Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 20:05
    Jeroen Breuer
    0

    Use a variable in a select statement

    Hello,

    I'm trying to use a variable in the select statement of a foreach loop, but I can't get it work. Any XSLT guru knows what I'm doing wrong? Here is the XSLT:

      <xsl:variable name="selectStatement">
        <xsl:choose>
          <xsl:when test="$currentPage/@level=3">
            <xsl:value-of select="$currentPage/*[@isDoc and @level=4 and hideInMenu=0]"/>
          </xsl:when>
          <xsl:when test="$currentPage/@level=4">
            <xsl:value-of select="$currentPage/parent/*[@isDoc and @level=4 and hideInMenu=0]"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentPage/*"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
      <!-- The subnodes which will be displayed. Sorted in the correct order. -->
      <xsl:variable name="sub_temp_nodes">
        <xsl:for-each select="$selectStatement">
          <xsl:sort order="ascending" select="@sortOrder" data-type="number"/>
          <xsl:copy-of select="." />
        </xsl:for-each>
      </xsl:variable>

    The select statement always throws this error: "To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function"

    So I tried this:

    <xsl:for-each select="msxml:node-set($selectStatement)">

    This doesn't return any nodes. If I try the value directly it does work: 

    <xsl:for-each select="$currentPage/*[@isDoc and @level=4 and hideInMenu=0]">

    What am I doing wrong?

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 20:22
    Jeroen Breuer
    0

    Got it fixed :). Need to use this:

    <xsl:copy-of select="$currentPage/*[@isDoc and @level=4 and hideInMenu=0]"/>

    Instead of this:

    <xsl:value-of select="$currentPage/*[@isDoc and @level=4 and hideInMenu=0]"/>

    Should have used copy. Now it works in combination with msxml:node-set($selectStatement).

    Jeroen

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Sep 30, 2010 @ 20:36
    Nik Wahlberg
    1

    From a best practices standpoint (and to be able to leverage existing templates) you should consider using 'umbracoNaviHide' for the property name on your "Hide From Navigation" document type prop. 

    Cheers,
    Nik

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 21:11
    Jeroen Breuer
    0

    I also use umbracoNaviHide, but not for the menu because that gave me conflicts in the past with some packages. For example if umbracoNaviHide is checked XSLT search can't find it. So by using hideInMenu I can hide it in the menu but it can still be found by XSLT search. Same goes for sitemaps etc. That's why I do it this way :).

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft