<!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> <xsl:apply-templates select="."></xsl:apply-templates> </xsl:for-each> </ul>
</xsl:template>
<xsl:template match="*"> <xsl:for-each select="./child::* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </xsl:template>
XSLT is very efficient for stuff like this, but requires thinking a little bit outside of what you're used to. This is a classic example where "normal" programming would require some sort of forEach loop, which isn't really necessary for recursive stuff like this (in XSLT) - example:
<!-- Define scope by start- and endlevels -->
<xsl:variable name="startLevel" select="1" />
<xsl:variable name="endLevel" select="2" />
<xsl:template match="/">
<!-- Start processing pages at $startLevel, ignoring hidden pages -->
<xsl:apply-templates select="$currentPage/ancestor-or-self::*[@level = $startLevel][not(umbracoNaviHide = 1)]" />
</xsl:template>
<!-- Template for all links -->
<xsl:template match="*[@isDoc]">
<div class="nav_button_l">
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="ancestor-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName" />
</a>
</div>
<!-- Process any page(s) below this (within selected scope) -->
<xsl:apply-templates select="*[@isDoc][@level <= $endLevel][not(umbracoNaviHide = 1)]" />
</xsl:template>
List Level1 and Level2 nodes in same navigation
There must be a better way of doing what I am trying to achieve below.
Basically I want to list Level1 and Level2 nodes in the same navigation.
Is there a neater way to do this?
JG
Hi JG.
Do not know if you have found a better solution to your question.
But you asked if there was a better way to get level 1 nodes and level 2 nodes in the same navigation.
I have tried to make a small example where I lists level 1 nodes and below each level1 nodes retrieved level 2 nodes if there are any.
Hope you can use my suggestion for a solution.
/Dennis
Hi JG (+Dennis)
XSLT is very efficient for stuff like this, but requires thinking a little bit outside of what you're used to. This is a classic example where "normal" programming would require some sort of forEach loop, which isn't really necessary for recursive stuff like this (in XSLT) - example:
Hope this helps.
/Chriztian
Hi Chriztian,
Thanks for your example to solve this problem. Always nice to see more ways to solve the same problem.
Some solutions are of course more appropriate than others. And I am currently. in a learning process of writing XSLT code most advisable.
So thank you Chriztian :-)
/Dennis
Hi Chriztian
Thanks for taking the time to do this - very informative
regards
Julian Grahame
is working on a reply...