I am using Umbraco and having some trouble with XSLT.
I have the following structure:
root
nodeA
nodeB
nodeB
nodeB
nodeC
nodeA
nodeB
nodeB
nodeB
I want to be able to get nodeB from nodeA under root or from nodeA under nodeC.
I currently use the following:
<xsl:param name="currentPage"/>
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*/nodeC" />
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:for-each select="$siteRoot/ancestor-or-self::*/nodeA/nodeB">
<xsl:if test="string(umbracoNaviHide) != '1'">
<li style="background-image: none;">
<xsl:if test="position() = last()">
<xsl:attribute name="class">no-border</xsl:attribute>
</xsl:if>
<a>
<xsl:attribute name="href">
<xsl:value-of select="umbraco.library:NiceUrl(current()/@id)"/>
</xsl:attribute>
<xsl:attribute name="style">
text-decoration: none;
</xsl:attribute>
<xsl:value-of select="./Name" /></a></li>
</xsl:if>
</xsl:for-each>
</xsl:template>
You must read something on XPAth and learn the meaning of the different axes.
You actually want quite the opposite of this code:
Or, better as a single XPath expression:
Note: Whenever possible, avoid using the XPath
descendant::or thedescendant-or-self::axes or the//pseudo-operator — they result in significant inefficiencies (slow execution) and//has anomalous and counter-intuitive behavior when used together with the[]operator.