Been searching the forums the last hour looking for an answer to how i get my level 0 (root) nodes liste with xslt for a toplevel navigation menu in the old schema.
Structure looks like this example:
- Domain 1 - Home - About - Vision - Domain 2 - Home - About - Vision - Domain 3
- Home
- About
- Vision
I started using the Prototype Navigation xslt, but when i set level=1 i get the nodes below Domain 1. If i set it to 0 i get nothing.
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <xsl:variable name="level" select="2"/>
<xsl:template match="/">
<!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="style">font-weight: bold;</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </ul>
When i change the level variabel to 2 in the original xslt in order to run through the child nodes of the "Homepage" node i dont get the level 1 node (Homepage) with the above example.
If i leave the level at 1 i don't get the child nodes at all.
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <xsl:variable name="level" select="1"/>
<xsl:template match="/">
<!-- The fun starts here --> <ul id="menu"> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </ul>
Try the following XPath to select all document nodes under root (with umbracoNaviHide is false):
$currentPage/ancestor::root/*[@isDoc and string(umbracoNaviHide) != '1']
This will:
Go to the ancestor called root (which is aptly called 'root' and happens to be the root of the Umbraco XML file)
Select all direct child nodes of any type (hence the *) that have the property 'isDoc' and do not have a child node called 'umbracoNaviHide' that contains the string value '1'.
You cannot access the root node using [@level = $level] because it has no property called 'level'. That is why your first XPath $currentPage/ancestor-or-self::*[@level = 1]/../*[@isDoc] did work.
Go to the ancestor (or self) on level 1
Go to the parent (.. means parent) which happens to be the 'root'
Level 0 Navigation (Top level nodes)
Hi there
Been searching the forums the last hour looking for an answer to how i get my level 0 (root) nodes liste with xslt for a toplevel navigation menu in the old schema.
Structure looks like this example:
- Domain 1
- Home
- About
- Vision
- Domain 2
- Home
- About
- Vision
- Domain 3
- Home
- About
- Vision
I started using the Prototype Navigation xslt, but when i set level=1 i get the nodes below Domain 1. If i set it to 0 i get nothing.
XSLT:
Gah, sry for the double post :(
Got it!
Hi Martin,
Glad you got it sorted!
In future you might like to structure your site so your pages are all under 'Home' of each site, like this:
Domain 1
- Home
- About
- Vision
- Domain 2
- Home
- About
- Vision
- Domain 3
- Home
- About
- Vision
Your structure (I imagine) was the reason that the navigation xslt wasn't pulling out all the nodes.
Rich
Hi Rich
With the structure you suggest, how do you go about not hardcoding the Home link since it's on a different level than the other subnodes?
Hi Martin,
This code should work (place it outside of the navigation loop)
Rich
Oh, never seen that before.
I'll bookmark this one and try it out for my next project.
Thanks for commenting!
That really didn't work out for me all that well.
When i change the level variabel to 2 in the original xslt in order to run through the child nodes of the "Homepage" node i dont get the level 1 node (Homepage) with the above example.
If i leave the level at 1 i don't get the child nodes at all.
Any advice here?
Hi Martin,
For your version, set the level to 2 and try this code
Rich
Hi Rich
Oh, can do!
I'll get back to you on that one, thanks :-)
Hi Rich
No go, unfortunately. If the level i set to "2", i get the children of the frontpage node, but not the Frontapage node itself.
Hmm it seems that i'm not using the same XSLT anymore, can't remember when i made the switch :/
Try the following XPath to select all document nodes under root (with umbracoNaviHide is false):
$currentPage/ancestor::root/*[@isDoc and string(umbracoNaviHide) != '1']
This will:
You cannot access the root node using [@level = $level] because it has no property called 'level'. That is why your first XPath $currentPage/ancestor-or-self::*[@level = 1]/../*[@isDoc] did work.
Hi Thjis
Cool, i'll give it a go tomorrow!
Thanks alot for your effort, much appreciated.
is working on a reply...