Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phil Crowe 192 posts 256 karma points
    Jan 04, 2011 @ 10:11
    Phil Crowe
    0

    check if node does exist

    something funny seems to be going on with my xslt. i have a for-each loop that occasionally breaks and i have found the bug to be some nodes are referencing the incorrect parentid. if i write out the value-of the parentid it says 'no node is located at id ..blah blah' and when i check in umbraco the actual parent of the node showing the error has a different parent id!

    so I overcome this is want to check the node does exist before i reference it, i read that checking if the @path has -1 tells you if it exsists, but this seems to be incorrect because all more nodes have a path containing -1. 'contains($granparent/@path, '-1')'

    So how else can i check this?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 04, 2011 @ 10:12
    Kim Andersen
    0

    Hi Phil

    Can you show us your XSLT where this happens?

    /Kim A

  • Phil Crowe 192 posts 256 karma points
    Jan 04, 2011 @ 10:30
    Phil Crowe
    0

    hi kim, kind of a big file but here it is:

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE xsl:stylesheet [

      <!ENTITY nbsp "&#x00A0;">

    ]>

    <xsl:stylesheet

    version="1.0"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:msxml="urn:schemas-microsoft-com:xslt"

    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"

    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets myfunctionlib"

     

      xmlns:myfunctionlib="urn:myfunctionlib"

      xmlns:PS.Helpers="urn:PS.Helpers"

      >

     

     

    <msxml:script implements-prefix="myfunctionlib" language="C#" >

     

    <![CDATA[

    Random r = new Random();

    public int RandomPos(int max) {

        return r.Next(max) + 1;

    }

    ]]>

    </msxml:script>

     

    <xsl:output method="xml" omit-xml-declaration="yes"/>

     

    <xsl:param name="currentPage"/>

    <xsl:variable name="source" select="/macro/source"/>

    <xsl:variable name="maxresults" select="/macro/MaxResults" />

     

    <xsl:template match="/">

     

     

     

      <img src="/images/my-collection/black-up.jpg" id="mycollup" />

      <ul>

        <xsl:choose>

          <xsl:when test="string-length(umbraco.library:RequestQueryString('hasSearchTerm')) &gt; 0">

     

                <xsl:call-template name="displaySearchedRows">

     

                  <xsl:with-param name="searchedTerm" select="umbraco.library:RequestQueryString('hasSearchTerm')" />

                  <xsl:with-param name="counter" select="1" />

                  <!--max rows is all the comment nodes under the product node-->

                <xsl:with-param name="maxrows" select="4" />

                </xsl:call-template>

     

         </xsl:when>

         <xsl:otherwise>

        <xsl:call-template name="displayrow">

     

        <xsl:with-param name="counter" select="1" />

        <xsl:with-param name="maxrows" select="$maxresults" />

        </xsl:call-template>

          </xsl:otherwise>

     

        </xsl:choose>

      </ul>

      <img src="/images/my-collection/black-down.jpg" id="mycolldown" />

     

    </xsl:template>

     

        <xsl:template name="displayrow">

          <xsl:param name="counter" />

          <xsl:param name="maxrows" />

          <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />

          <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

            <xsl:variable name="randomnode" select="umbraco.library:GetXmlNodeById($source)//TextImageData[position()=myfunctionlib:RandomPos($maxrows)]"/>

             <xsl:value-of select="randomnode"/>

     

     

                                 <xsl:choose>

              <xsl:when test="$randomnode/member != ''">

                <li class="licomment">

     

                <xsl:variable name="mxml" select="umbraco.library:GetMember($randomnode/member)" />

                <div class="myCollectionLatest" id="mycollectioncomment{$counter}">

                  <div style="float:left;">

                    <div class="colltoppic">

                      <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

                <img src="{$mxml/node/profilePicture}" width="74" height="74" onerror="ImgError(this);" />

     

                      </a>

                    </div>

     

                    <div style="float:left; position:absolute; margin-left:83px; margin-top:-84px; width:160px;" class="mycolllatestlinks">

     

                        <b>

                          <xsl:variable name="parent" select="$randomnode/@parentID">

     

                            </xsl:variable>

                            <xsl:variable name="granparent" select="umbraco.library:GetXmlNodeById(umbraco.library:GetXmlNodeById($parent)/@parentID)" />

    <xsl:value-of select="$granparent">

    <xsl:choose>

    <!--this is the check to see if a gran-parent exsists, currently some nodes reference an incorrect parent id-->

    <xsl:when test="contains($granparent/@path, '-1')">

    <a href="/my-collection.aspx?memberId={$mxml/*/@id}" class="usernamelinkdiv">

    <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/>

    </a> SAID 

    </xsl:when>

    <xsl:otherwise>

    <xsl:choose>

    <xsl:when test="string-length($granparent/@nodeName) &gt; 0">

    <a href="/my-collection.aspx?memberId={$mxml/*/@id}" class="usernamelinkdiv">

    <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/>

    </a> SAID ABOUT

     

    <span class="pinkTxt">

     

    <br />

     

    <xsl:choose>

    <xsl:when test="name($granparent) = 'ProductCategory'">

    <a href="{umbraco.library:NiceUrl($granparent/@id)}?categoryId=1">

    <xsl:value-of select="translate($granparent/@nodeName, $smallcase, $uppercase)"/>

    </a>

    </xsl:when>

    <xsl:when test="name($granparent) = 'ProductSubCategory'">

    <a href="{umbraco.library:NiceUrl($granparent/@id)}?searchingForProduct=1">

    <xsl:value-of select="translate($granparent/@nodeName, $smallcase, $uppercase)"/>

    </a>

    </xsl:when>

    <xsl:otherwise>

    <a href="{umbraco.library:NiceUrl($granparent/@id)}">

    <xsl:value-of select="translate(umbraco.library:GetXmlNodeById($granparent)/@nodeName, $smallcase, $uppercase)"/>

    </a>

    </xsl:otherwise>

     

    </xsl:choose>

     

    </span>

    </xsl:when>

     

    <xsl:otherwise>

    <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

    <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/>

    </a> SAID

    </xsl:otherwise>

    </xsl:choose>

    <!--add this because some comments didnt seem to have a product against them-->

    </xsl:otherwise>

    </xsl:choose>

                        </b>

     

                      <p>

                      <xsl:value-of select="substring(umbraco.library:StripHtml($randomnode/text),1,60)" />...

                    </p>

     

                    </div>

                    <div class="randomCommentsSeeMore">

                      <span class="pinkTxt">

                        <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

                          See more <img src="/images/navControls/more-arrow.jpg" alt="see more" />

                        </a>

                    </span>

                    </div>

                  </div>

     

                </div>

     

     

              </li>

                <xsl:if test="$counter &lt; $maxrows">

     

                  <xsl:call-template name="displayrow">

                    <xsl:with-param name="counter" select="$counter + 1" />

                    <xsl:with-param name="maxrows" select="$maxrows" />

                  </xsl:call-template>

     

                </xsl:if>

           </xsl:when>

          <xsl:when test="$randomnode/member = ''">

            <xsl:if test="$counter &lt; $maxrows">

     

              <xsl:call-template name="displayrow">

                <xsl:with-param name="counter" select="$counter" />

                <xsl:with-param name="maxrows" select="$maxrows" />

              </xsl:call-template>

     

            </xsl:if>

          </xsl:when>

          <xsl:otherwise>

            <xsl:if test="$counter &lt; $maxrows">

     

              <xsl:call-template name="displayrow">

                <xsl:with-param name="counter" select="$counter" />

                <xsl:with-param name="maxrows" select="$maxrows" />

              </xsl:call-template>

     

            </xsl:if>        

          </xsl:otherwise>

          </xsl:choose>

        </xsl:template>

      <xsl:template name="displaySearchedRows">

        <xsl:param name="counter" />

        <xsl:param name="maxrows" />

        <xsl:param name="searchedTerm" />

     

        <xsl:variable name="returnedSearchedString" select="PS.Helpers:MemberListString($searchedTerm)"/>

     

      <!--  umbraco.library:Split($products, ',') -->

        <xsl:variable name="splitMemberNodes" select="umbraco.library:Split($returnedSearchedString, ',')" />

      <xsl:for-each select="$splitMemberNodes/value">

     

     

          <li class="licomment">

     

            <xsl:if test="string-length(.) &gt; 0">

              <xsl:variable name="mxml" select="umbraco.library:GetMember(.)" />

     

     

     

     

              <div class="myCollectionLatest" id="mycollectioncomment{position()}">

                <div style="float:left;">

                  <div class="colltoppic">

                    <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

                      <img src="{$mxml/node/profilePicture}" width="74" height="74" onerror="ImgError(this);" />

     

                    </a>

                  </div>

                  <div class="collbottompic">

                  </div>

                  <div style="float:left; position:absolute; margin-left:83px; margin-top:-84px;" class="mycolllatestlinks">

     

                    <b>

                      <xsl:variable name="parent" select="@parentID">

     

                      </xsl:variable>

                      <xsl:variable name="granparent" select="umbraco.library:GetXmlNodeById(umbraco.library:GetXmlNodeById($parent)/@parentID)" />

                      <xsl:choose>

                        <xsl:when test="string-length($granparent/@nodeName) &gt; 0">

                          <a href="/my-collection.aspx?memberId={$mxml/*/@id}" class="usernamelinkdiv">

                            <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />

                            <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

                            <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/>

                          </a> 

     

                          <span class="pinkTxt">

     

                            <br />

                            <a href="{umbraco.library:NiceUrl($granparent/@id)}">

                              <xsl:value-of select="$granparent/@nodeName"/>

                            </a>

     

                          </span>

                        </xsl:when>

     

                        <xsl:otherwise>

                          <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

                            <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />

                            <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

                            <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/>

                          </a> 

                        </xsl:otherwise>

                      </xsl:choose>

     

                    </b>

     

                    <p>

                      <xsl:if test="string-length($mxml/node/makeUpIdol) &lt; 1" >

                        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />

                        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

                        <xsl:value-of select="translate($mxml/node/screenName, $smallcase, $uppercase)"/> HAS NOT GOT A MAKEUP IDOL

                      </xsl:if>

                      <xsl:value-of select="$mxml/node/makeUpIdol"/>

                    </p>

     

                  </div>

                  <div class="randomCommentsSeeMore">

                    <span class="pinkTxt">

                      <a href="/my-collection.aspx?memberId={$mxml/*/@id}">

                        See more <img src="/images/navControls/more-arrow.jpg" alt="see more" />

                      </a>

                    </span>

                  </div>

                </div>

     

              </div>

     

     

            </xsl:if>

            </li>

     

            <!-- <xsl:variable name="randomnode" select="umbraco.library:GetXmlNodeById($source)//TextImageData[position()=myfunctionlib:RandomPos($maxrows)]"/>-->

     

        </xsl:for-each>

     

     

      </xsl:template>

    </xsl:stylesheet>

     

    I have highlighted in bold where the error occurs.

  • Thijs Kuipers 43 posts 66 karma points
    Jan 04, 2011 @ 12:03
    Thijs Kuipers
    0

    Hi Phil, first off: what's the deal with all the "translate(), smallcase, uppercase" stuff? Doesn't "upper-case()" work? (I seriously don't know, you might have tested this and found it doesn't).

    Second, I don't know where your error stems from, but I often use an XSLT-only construct to find a node by id:

    <!-- Get the absolute root -->
    <xsl:variable name="rootNode" select="$currentPage/ancestor::root"/>
    
    <!-- Get a node by id -->
    <xsl:variable name="selectNode" select="$rootNode//*[@id = $requestedId]"/>
Please Sign in or register to post replies

Write your reply to:

Draft