Looks like you are using the $level2 variable in both of your for-each loops. If you use variable $level3 in the 'inner' for-each loop i think it should work.
Try changing 'inner' for-each loop to this:
<xsl:for-each select="$currentPage/child::* [@isDoc and @level=$level3]/* [@isDoc and string(umbracoNaviHide) != '1']">
Perhaps you can benefit from using the "sitemap" snippet, as it does what you're trying to achieve recursively. There's no need for the $level variables.
In the sample you can specify the max level...think that is the way to go for you.
I thought maybe I could use count to see if page has child nodes, if it does, then show the 'Browse sections', but that wouldn't work either because the 'Browse sections' would disappear when clicking on 'About 1' or 'About 2' as they have no sub pages.
Then I thought I could test that (a) has sub pages (so 'Browse sections' would display when on top level page) or (b) has a parent page (ie the node must be a sub level if it has a parent?!)
However, all my top navigations have a parent (home) so once again 'Browse sections' displays on all pages regardless of whether the page has child nodes. Bit confused here.
Well my first problem I managed to solve :)... but I really wanted the levels to expand when clicked rather than all levels being displayed all the time, here's what I have so far:
<!-- This automatically hides items with umbracoNaviHide checked -->
<xsl:template match="*[umbracoNaviHide = 1]" />
</xsl:stylesheet>
Ideally, when on a top level page, all the level 2 nodes will be displayed. Then, if a user clicks on the level 2 node, then the level 3 ones are displayed. I can get a good result with cog navigation but I am sure this way is better for me because I wont learn a thing just chucking a package in there to do the job.
Navigation help
I need to do this navigation, and i'm messing around with the XSLT, can someone help me out? :)
Tried to delete the doublepost but wasn't able to..
Here's the XSLT I have untill now, almost does the trick.. except it doesnt show the last level of navigation :(
<?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="level" select="1"/>
<xsl:variable name="level2" select="2"/>
<xsl:variable name="level3" select="3"/>
<xsl:template match="/">
<ul class="undermenu">
<xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level2]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<!-- This is the active item -->
<xsl:attribute name="class">aktiv</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
<xsl:for-each select="$currentPage/child::node [@isDoc and @level=$level2]/* [@isDoc and string(umbracoNaviHide) != '1']">
<ul>
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<!-- This is the active item -->
<xsl:attribute name="class">aktiv</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
</li>
</ul>
</xsl:for-each>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Looks like you are using the $level2 variable in both of your for-each loops.
If you use variable $level3 in the 'inner' for-each loop i think it should work.
Try changing 'inner' for-each loop to this:
<xsl:for-each select="$currentPage/child::* [@isDoc and @level=$level3]/* [@isDoc and string(umbracoNaviHide) != '1']">
/Thor
Hi Daniel
Perhaps you can benefit from using the "sitemap" snippet, as it does what you're trying to achieve recursively. There's no need for the $level variables.
In the sample you can specify the max level...think that is the way to go for you.
/Jan
Hi Daniel (+others)
Since you all know my position on these matters, I would recommend trying this approach instead - I'm seeing way too much duplication already :-)
/Chriztian
Thanks Chriztian, will try it out ! :)
I really have to spend some time with apply templates etc, it really does make a lot of sense :)
Hi Daniel,
check this code. I`ve the same problems when I start with the new schema.
/PRK
Thanks for all the help guys, I ended up using Chriztians example :), works like a knife through melted butter...
Chriztian I owe you a beer @ Codegarden :)
@Chriztian in your above code, how would you put the class="aktiv" on the <li> which is active instead of on the <a> ?
Hi Daniel
If you want to put the class on the <li> instead of the a you can just do like this:
/Kim A
- Just move the three lines (<xsl:if> <xsl:attribute>... </xsl:if>) up right after the <li>:
/Chriztian
Thanks Chriztian :)
Hi everyone,
I am trying to adapt the above (thanks Chriztian!), so that the menu has a title in the form of
However, when I put this into the code, the 'Browse sections' either shows:
a) On ALL pages even with no sub pages so a menu title with no menu OR
b) In between all <li> elements so 'Browse sections' repeats down the menu.
I can't figure out a test which would mean this title only shows once, above the menu, but only if the menu is present.
Any help is always appreciated :) thanks.
Sam.
I can expand, I get either:
...the above is how I want it, however, when clicking on a top level page with no sub pages I get this:
which is no good :(
I thought maybe I could use count to see if page has child nodes, if it does, then show the 'Browse sections', but that wouldn't work either because the 'Browse sections' would disappear when clicking on 'About 1' or 'About 2' as they have no sub pages.
Then I thought I could test that (a) has sub pages (so 'Browse sections' would display when on top level page) or (b) has a parent page (ie the node must be a sub level if it has a parent?!)
However, all my top navigations have a parent (home) so once again 'Browse sections' displays on all pages regardless of whether the page has child nodes. Bit confused here.
Sam.
Well my first problem I managed to solve :)... but I really wanted the levels to expand when clicked rather than all levels being displayed all the time, here's what I have so far:
Ideally, when on a top level page, all the level 2 nodes will be displayed. Then, if a user clicks on the level 2 node, then the level 3 ones are displayed. I can get a good result with cog navigation but I am sure this way is better for me because I wont learn a thing just chucking a package in there to do the job.
Thanks if anyone can help :)
Sam.
is working on a reply...