I'm trying to create a vertical multilevel nav for Umbraco using XSLT, that will add nested lists automatically. Currently I have had to keep adding each nested list manually into the XSLT (which is not good practice).
I've created the following menu but I need help as it's not creating the nest lists properly:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="level1" select="$currentPage/ancestor-or-self::* [@level = 2 and string(umbracoNaviHide) != '1' and string(hideFromSideNavigation) != '1']" />
<xsl:variable name="level" select="2"/>
<div class="subnav">
<!-- LEVEL 1 -->
<p><xsl:value-of select="$level1/@nodeName"/></p>
<ul>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc][@level=2]"/>
</xsl:call-template>
</ul>
</div>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:for-each select="$parent/ancestor-or-self::* [@level=2]/* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']) = 0">
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</xsl:if>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']) > 0">
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<ul>
<xsl:choose>
<xsl:when test="./umbracoNaviHide != '1'">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:when>
</xsl:choose>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here's manual added nested lists XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="level1" select="$currentPage/ancestor-or-self::* [@level = 2 and string(umbracoNaviHide) != '1' and string(hideFromSideNavigation) != '1']" />
<xsl:variable name="level" select="2"/>
<div class="subnav">
<!-- LEVEL 1 -->
<p><xsl:value-of select="$level1/@nodeName"/></p>
<!-- LEVEL 2 -->
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<!-- LEVEL 3 if any more nodes are Visible -->
<xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<!-- LEVEL 4 if any more nodes are Visible -->
<xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<!-- LEVEL 5 if any more nodes are Visible -->
<xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1' and string(@template) != '0']">
<li>
<xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
Can anyone suggest a solution?