I have been staring at this problem for two days now and cannot seem to resolve it. When I access my top-level pages, everything works fine. However, when I attempt to click on a page that is a child of another page, it duplicates itself in my navigation menu. My XSLT is not that sharp, so I may be overlooking something simple here, but I would appreciate any help that is given.
<xsl:template match="/"> <div> <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::node [@level=2]" /> <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level=2 and string(data[@alias='umbracoNaviHide']) != '1']"> <!-- Add the class selected if the currentpage or parent nodes (up the tree to the root) ID matches our current node ID in the for each loop --> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <p class="mainNavselected"> <img src="images/arrow_red.gif" /> <a href="{umbraco.library:NiceUrl(@id)}" atl="" class="main"><xsl:value-of select="data[@alias='umbracoMenuLinkTitle']" /></a> </p> </xsl:if> <xsl:if test="$currentPage/ancestor-or-self::node/@id != current()/@id"> <p class="mainNav"> <img src="images/arrow.gif" /> <a href="{umbraco.library:NiceUrl(@id)}" atl="" class="main"><xsl:value-of select="data[@alias='umbracoMenuLinkTitle']" /></a> </p> </xsl:if> </xsl:for-each> <xsl:variable name="rootNode2" select="$currentPage/ancestor-or-self::node [@level=3]" /> <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level=3 and string(data[@alias='umbracoNaviHide']) != '1']"> <!-- Add the class selected if the currentpage or parent nodes (up the tree to the root) ID matches our current node ID in the for each loop --> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <p class="secnav"> <a href="{umbraco.library:NiceUrl(@id)}" atl="" class="secnavlink" style="color:#bf1b11"><xsl:value-of select="data[@alias='umbracoMenuLinkTitle']" /></a> </p> </xsl:if> <xsl:if test="$currentPage/ancestor-or-self::node/@id != current()/@id"> <p class="secnav"> <a href="{umbraco.library:NiceUrl(@id)}" atl="" class="main"><xsl:value-of select="data[@alias='umbracoMenuLinkTitle']" /></a> </p> </xsl:if> </xsl:for-each> </div> </xsl:template> </xsl:stylesheet>
Not quite sure why you are written your navigation in the way you have done?
I.e. Why the hard coded CSS and class names for specific levels as this limits your XSLT to only be used for a 2 level navigation. I have just cleaned up my standard navigation XSLT that I use to build navigations in the majority of sites that I have developed. You will need to add your CSS to style the navigation based on the top level UL ( see below )
You might wish to add a check to see which level you are at and limit the amount of recursion if for example you have site content 3 layers deep but you only wish to show the first two in your main navigation.
And for the CSS
ul#nav li { Your top level CSS goes here } ul#nav li ul li { Your second level CSS goes here... I think you'll get the idea for the third level :) }
Thanks for your reply, Chris. I am still a little unfamiliar with XSLT, so how would I code in logic to only display third level child nodes to display only when their direct parent node is selected?
You could modify my above code and just add a of xsl:choose statement. I have not tested this and just written it directly into the forum so appologies for the formatting and if there is a bug! I think it is right though and should get you in the right direction :)
I've debugged your code and cannot figure out why on any level 1 node that the first level 2 node shows correcly, but every subsequent level 2 node show up nested beneth the first level 2 node. However, when I navigate to a level 2 node, every <li> nests itself in the <ul> as it should.
Sorry to bother you so much, but XSLT is still a bit hazy for me. Throw in a round of recursion, and my head starts spinning.
Repeating Child nodes in Nav menu
I have been staring at this problem for two days now and cannot seem to resolve it. When I access my top-level pages, everything works fine. However, when I attempt to click on a page that is a child of another page, it duplicates itself in my navigation menu. My XSLT is not that sharp, so I may be overlooking something simple here, but I would appreciate any help that is given.
Hi Jan,
Not quite sure why you are written your navigation in the way you have done?
I.e. Why the hard coded CSS and class names for specific levels as this limits your XSLT to only be used for a 2 level navigation. I have just cleaned up my standard navigation XSLT that I use to build navigations in the majority of sites that I have developed. You will need to add your CSS to style the navigation based on the top level UL ( see below )
You might wish to add a check to see which level you are at and limit the amount of recursion if for example you have site content 3 layers deep but you only wish to show the first two in your main navigation.
And for the CSS
I hope this helps :)
Thanks for your reply, Chris. I am still a little unfamiliar with XSLT, so how would I code in logic to only display third level child nodes to display only when their direct parent node is selected?
Hi,
You could modify my above code and just add a of xsl:choose statement. I have not tested this and just written it directly into the forum so appologies for the formatting and if there is a bug! I think it is right though and should get you in the right direction :)
Thanks, Chris!
I've debugged your code and cannot figure out why on any level 1 node that the first level 2 node shows correcly, but every subsequent level 2 node show up nested beneth the first level 2 node. However, when I navigate to a level 2 node, every <li> nests itself in the <ul> as it should.
Sorry to bother you so much, but XSLT is still a bit hazy for me. Throw in a round of recursion, and my head starts spinning.
Hows about showing and hiding the subnav with a tiny bit of css?
Dan
is working on a reply...