I'm developing a skin for DotNetNuke 5 using the DNN Done Right menu component which uses an custom XSL-T to convert the XML sitemap into an HTML navigation.
Using XSL-T is a life saver in comparison to the other ways of building a navigation menu. However I've run into problems doing something a little more complex, as I'm a newcomer to XML-T and XPath.
What I'm trying to achieve is this:
- Ignore level 0 nodes
- Loop through all level 1 nodes in the selected hierarchy
- Once the selected level 1 node is found, start looping through the hierarchy/breadcrumb structure up to the active level.
- Once at the active node level, loop through and show all the siblings of that level
- Then finish off looping through the level 1 nodes
Below is a example XML block of a sitemap the menu component uses.
<Root>
<root>
<node id="37" text="Home" url="http://www.dnndoneright.com/Home.T37.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="0" >
<description >Upgrade your standard DNN menu - automatically and for free - to an SEO-optimised, accessible, mobile-friendly, cross-browser menu.</description>
</node>
<node id="56" text="DNN Menu" url="http://www.dnndoneright.com/DNN-Menu.T56.aspx" enabled="1" selected="0" breadcrumb="1" first="0" last="0" only="0" depth="0" >
<node id="97" text="Menu features" url="http://www.dnndoneright.com/Menu-features.T97.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
<node id="111" text="Pre-built templates" url="http://www.dnndoneright.com/Pre-built-templates.T111.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
<node id="94" text="Standard DNN menu, upgraded" url="http://www.dnndoneright.com/Standard-DNN-menu-upgraded.T94.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="124" text="Superfish template" url="http://www.dnndoneright.com/Superfish-template.T124.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="106" text="Treeview template" url="http://www.dnndoneright.com/Treeview-template.T106.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="107" text="Accordion template" url="http://www.dnndoneright.com/Accordion-template.T107.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="112" text="Dropdown template" url="http://www.dnndoneright.com/Dropdown-template.T112.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="96" text="Mega-menu" url="http://www.dnndoneright.com/Mega-menu.T96.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
<node id="113" text="Getting started" url="http://www.dnndoneright.com/Getting-started.T113.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="1" >
<node id="114" text="Installing the menu" url="http://www.dnndoneright.com/Installing-the-menu.T114.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="115" text="Upgrading a SolPart menu" url="http://www.dnndoneright.com/Upgrading-a-SolPart-menu.T115.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="116" text="Upgrading a DNNMenu" url="http://www.dnndoneright.com/Upgrading-a-DNNMenu.T116.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="117" text="Installing a template" url="http://www.dnndoneright.com/Installing-a-template.T117.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="118" text="Adding to a skin" url="http://www.dnndoneright.com/Adding-to-a-skin.T118.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
<node id="119" text="Customising templates" url="http://www.dnndoneright.com/Customising-templates.T119.aspx" enabled="0" selected="0" breadcrumb="1" first="0" last="1" only="0" depth="1" >
<node id="120" text="Standard options" url="http://www.dnndoneright.com/Standard-options.T120.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="2" />
<node id="121" text="Specifying filenames" url="http://www.dnndoneright.com/Specifying-filenames.T121.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="2" />
<node id="122" text="XML format" url="http://www.dnndoneright.com/XML-format.T122.aspx" enabled="1" selected="1" breadcrumb="1" first="0" last="0" only="0" depth="2" />
<node id="123" text="Creating custom templates" url="http://www.dnndoneright.com/Creating-custom-templates.T123.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="2" />
</node>
</node>
<node id="87" text="Download" url="http://www.dnndoneright.com/Download.T87.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="0" only="0" depth="0" />
<node id="85" text="Contact" url="http://www.dnndoneright.com/Contact.T85.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="0" >
<node id="129" text="Blog" url="http://www.dnndoneright.com/Blog.T129.aspx" enabled="1" selected="0" breadcrumb="0" first="1" last="0" only="0" depth="1" />
<node id="130" text="Forum" url="http://www.dnndoneright.com/Forum.T130.aspx" enabled="1" selected="0" breadcrumb="0" first="0" last="1" only="0" depth="1" />
</node>
</root>
</Root>
Also here is my (incorrect) starting point, just to expose my lack of XSL/XPath knowledge. (My code is wrong, because it lists all L1 nodes, rather than just the L1 nodes in the selected hierarchy)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<div class="SideMenu">
<!-- Loop through all L1 nodes -->
<xsl:for-each select="Root/root/node/node">
<xsl:if test="@enabled='1'" >
<!-- Only use L1 in the current hierarchy -->
<div>
[ <xsl:value-of select="@text"/>: <xsl:value-of select="@depth"/> ]
</div>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>