Copied to clipboard

Flag this post as spam?

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


  • Jonas Eriksson 930 posts 1825 karma points
    Oct 18, 2010 @ 12:21
    Jonas Eriksson
    0

    How can one use use xml for variables? (currentPage and GetXmlNodeById)

    I wonder how one can make variables use xml. Some experiments:

    <xsl:variable name="currentPageCopy">
      <xsl:copy-of select="$currentPage"/>
    </xsl:variable>

    That won't give me a copy of the magic $currentPage. If I try to use

    <xsl:value-of select="count($currentPageCopy/node)"/>

    I'll get an error - "need to use node-set." But with this:

    <xsl:value-of select="count(msxsl:node-set($currentPageCopy)/node))"/>

    I always get the result 0.

    Why am I trying to achieve?

    Yes, I need a variable that can contain either currentPage or another node xml:

    <xsl:variable name="requestRewriteFromId" select="umbraco.library:RequestQueryString('RewriteFromId')"/>
    <xsl:value-of select="$requestRewriteFromId"/>

    <xsl:variable name ="navigationPageXml">
    <xsl:choose>
    <xsl:when test="$requestRewriteFromId!=''">
    <xsl:copy-of select="umbraco.library:GetXmlNodeById($requestRewriteFromId)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:copy-of select="$currentPage"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="navigationPage" select="msxsl:node-set(navigationPageXml)"/>

    ...so that I can use it with standard xslt instead of $currentPage.

    Thanks alot!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 18, 2010 @ 12:57
    Jeroen Breuer
    0

    Here is a sample I'm using:

    <!-- The nodes which will be displayed. Sorted in the correct order. -->
      <xsl:variable name="temp_nodes">
        <xsl:for-each select="$currentPage/NewsItem [@isDoc]">
          <xsl:sort order="descending" select="currentDate" data-type="text"/>
          <xsl:copy-of select="." />
        </xsl:for-each>
      </xsl:variable>
    
      <!-- Convert the nodes to a value which is easier to work with. -->
      <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/*[self::NewsItem [@isDoc]]" />
    
      <!-- The total amount of items -->
      <xsl:variable name="totalItems" select="count($nodes)" />

    If you're using Umbraco 4.5 this won't work:

     msxsl:node-set($currentPageCopy)/node)

    If you try /* or /* [@isDoc] what does the count return?

    Jeroen

  • Jonas Eriksson 930 posts 1825 karma points
    Oct 18, 2010 @ 13:02
    Jonas Eriksson
    0

    Thanks

    I'm using 4.03 here forgot to say.

    I missed a $:

    <xsl:variable name="navigationPage" select="msxsl:node-set($navigationPageXml)"/>

    ... ang adding /node to it seems to do the trick this time. But ... I'm trying to understand what happens...

    <xsl:variable name="navigationPage" select="msxsl:node-set($navigationPageXml)/node"/>

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 18, 2010 @ 13:10
    Jeroen Breuer
    0

    The /node is the name of the element. In Umbraco 4.0.x all the nodes are of the element of "node". You can see this if you look at the umbraco.config file. 

    Jeroen

  • Jonas Eriksson 930 posts 1825 karma points
    Oct 18, 2010 @ 13:33
    Jonas Eriksson
    0

    Yes, indeed, but I thought I was at the right node to begin with.

    I guess I'm just one level up because of the variable, and that's why omitting the "/node" won't work as expected.

    Since this works:

    <xsl:value-of select="umbraco.library:GetXmlNodeById($requestRewriteFromId)/@id"/>

    But this don't:

    <xsl:value-of select="msxsl:node-set($navigationPageXml)/@id"/>

    I'll have to use:

    <xsl:value-of select="msxsl:node-set($navigationPageXml)/node/@id"/>
Please Sign in or register to post replies

Write your reply to:

Draft