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"
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.
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 :).
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:
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:
This doesn't return any nodes. If I try the value directly it does work:
What am I doing wrong?
Jeroen
Got it fixed :). Need to use this:
Instead of this:
Should have used copy. Now it works in combination with msxml:node-set($selectStatement).
Jeroen
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
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
is working on a reply...