I have an issue with my menu which is pieced together inside XSLT using apply templates. The menu is a simple list of horizontal tabs, the submenus (if there are any) slide out on hover using Jquery.
If the current page is any First (Home) or 2nd level content page (About Us, Products, Newsletters, Contact Us), the menu works correctly. If I am on the 3rd level, the sliding menu (3rd level) are non-existent. Any advice on why it isn't working as expected would be much appreciated!
I am also fairly sure there are more succinct ways of achieving what I want, so any advice on how to re-work it optimally would also be mcuh appreciated.
<xsl:param name="currentPage"/> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::root/*[@isDoc and @level=1]" /> <xsl:template match="/"> <ul id="nav"> <!-- Run for rootnode and 2nd level nodes (will deal with 3rd level inside the template match)--> <xsl:apply-templates select="$siteRoot [@isDoc]" /> <xsl:apply-templates select="$siteRoot/* [@isDoc and string(umbracoNaviHide) != '1']" /> </ul>
</xsl:template> <!-- HOMEPAGE (matches as its the only one at level 1)--> <xsl:template match="*[@isDoc]"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /> </a> </li> </xsl:template>
<!-- SECOND LEVEL PAGES (matches all at level 2)--> <xsl:template match="*[@isDoc and @level = 2]"> <li> <!-- if this node has a child then --> <xsl:if test="*[@isDoc and string(umbracoNaviHide) != '1']"> <xsl:attribute name="class">trigger</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /> </a> <!-- if this node has a child then (selects 3rd level nodes) --> <xsl:if test="*[@isDoc]"> <ul class="submenu"> <xsl:apply-templates select="*[@isDoc]" /> </ul> </xsl:if> </li> </xsl:template>
<!-- THIRD LEVEL PAGES (matches all at level 3)--> <xsl:template match="*[@isDoc and @level = 3 and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /> </a> </li> </xsl:template>
I am an idiot. The output from the XSLT is correct. It was an incorrect path to my jscript file in my master template causing the problem! How can I delete this topic?!
I would however like to know if there is a more succinct method of achieiving the same output - my XSLT feels a little messy...? This is the first time I've used umbraco and XSLT so any advice appreciated.
No worries - that's exactly why we're all here. I can't tell you how many times I've solved an issue by explaining what I *thought* was going on to someone else, only to realize where the culprit was :-)
There's no reason to delete it either - just make sure to mark your own answer as the solution, so that people with a similar problem can quickly see that the topic has a "solution", so they don't have to dig through the comments...
I'll post a somewhat cleaned up version of the code, but it's actually pretty good already, compared to some of the othr stuff you'll see here :-)
Thanks for your reply. Much cleaner. Sometimes you don't see things even though they are staring you in the face! (I obviously didn't need the template to specifically match the 3rd level)
Nested Apply_Template Menu Problem
I have an issue with my menu which is pieced together inside XSLT using apply templates. The menu is a simple list of horizontal tabs, the submenus (if there are any) slide out on hover using Jquery.
If the current page is any First (Home) or 2nd level content page (About Us, Products, Newsletters, Contact Us), the menu works correctly. If I am on the 3rd level, the sliding menu (3rd level) are non-existent. Any advice on why it isn't working as expected would be much appreciated!
I am also fairly sure there are more succinct ways of achieving what I want, so any advice on how to re-work it optimally would also be mcuh appreciated.
My basic content structure is (as advised by this post http://www.blogfodder.co.uk/2010/5/13/building-your-first-umbraco-site-from-scratch)
My XSLT is
Thanks!
Hi Jamie,
Seems a little weird to me at first look - the XSLT should do the same on every level...
Anything in the jQuery that depends on a class or something that's not set on 3rd level pages (on a master pages)?
/Chriztian
Hi Chriztian
I am an idiot. The output from the XSLT is correct. It was an incorrect path to my jscript file in my master template causing the problem! How can I delete this topic?!
I would however like to know if there is a more succinct method of achieiving the same output - my XSLT feels a little messy...? This is the first time I've used umbraco and XSLT so any advice appreciated.
Thanks
Hi Jamie,
No worries - that's exactly why we're all here. I can't tell you how many times I've solved an issue by explaining what I *thought* was going on to someone else, only to realize where the culprit was :-)
There's no reason to delete it either - just make sure to mark your own answer as the solution, so that people with a similar problem can quickly see that the topic has a "solution", so they don't have to dig through the comments...
I'll post a somewhat cleaned up version of the code, but it's actually pretty good already, compared to some of the othr stuff you'll see here :-)
/Chriztian
Hi again,
This is how I'd write it - should be faily easy to compare yourself - just ask if anything is cryptic :-)
/Chriztian
Thanks for your reply. Much cleaner. Sometimes you don't see things even though they are staring you in the face! (I obviously didn't need the template to specifically match the 3rd level)
is working on a reply...