This works perfectly with my
css and the Hover effect as well but since am using umbraco i wanted to
create it as an XSLT file but i cant get the second level navigation
that is the Drop Down Menu:
The Drop Down Menu works fine and when i click on one of the Links on top it returns a class to indicate this is the active Link but now am trying to get the same result but when clicking on the child node.
The parent node should be the active one.
Here is my code
<ulid="top-navigation">
<li> <xsl:attributename="class"> <xsl:iftest="$currentPage/@level=$level"> <xsl:text>current</xsl:text> </xsl:if> </xsl:attribute> <ahref="/"> <xsl:value-ofselect="$currentPage/ancestor-or-self::*/@nodeName"/> </a> </li> <xsl:for-eachselect="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:attributename="class"> <xsl:iftest="$currentPage/@id=@id"> <xsl:text>current</xsl:text> </xsl:if> </xsl:attribute> <ahref="{umbraco.library:NiceUrl(@id)}"><xsl:value-ofselect="@nodeName"/></a> <!-- Drop Down Menu --> <xsl:iftest="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0"> <ul> <xsl:for-eachselect="./* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:attributename="class"> <xsl:iftest="$currentPage/descendant::* [@level=1]"> <xsl:text>current</xsl:text> </xsl:if> </xsl:attribute> <ahref="{umbraco.library:NiceUrl(@id)}"><xsl:value-ofselect="@nodeName"/></a></li> </xsl:for-each> </ul> </xsl:if> <!-- End of Drop Down Menu --> </li> </xsl:for-each> </ul>
Nope still not working....the parent still not being highlighted....when i view the source code its still the child node which contains the class="current".
In my case my top navigation is
Accueil
Informations
- Information 1
- Information 2
Produits
Formation
Contact
So when i click on Informations main page the Link on top of my menu is Highlighted when if i click on Information 1 my parent Informations is not Hightlighted.
<a href="/"> <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/> </a> </li> <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:attribute name="class"> <xsl:if test="$currentPage/@id=@id"> <xsl:text>current</xsl:text> </xsl:if> </xsl:attribute> <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a> <!-- Drop Down Menu --> <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0"> <ul> <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <xsl:attribute name="class">current</xsl:attribute> </xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li> </xsl:for-each> </ul> </xsl:if> <!-- End of Drop Down Menu --> </li> </xsl:for-each> </ul>
</xsl:template>
</xsl:stylesheet>
And error I'm receiving from Umbraco XSTLT editor
"System.Xml.Xsl.XslLoadException: The variable or parameter 'level' is either not defined or it is out of scope."
One last question: What XSLT editor is perferred? I would like to work with XSLT but I'm not sure what editor to use.
You get the error because you have not defined a variable named "level".
In this part
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
you make sure that nodes are only selected from the level that is specified in the $level variable...only problem is though that it does not exist :-)
So in order to make it work you need to specify the variable of course.
You can specify it right after the <xsl:template match="/"> or right before it.
Do it like this
<xsl:variable name="level" select="1" />
You could also skip using this variable and instead write the level directly in the for-each section like this
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level='1']/* [@isDoc and string(umbracoNaviHide) != '1']">
For editing XSLT files I'm using visual studio when working on Windows. If you're using a Mac I think Textmate is what you would want to use. Also for Windows there is an editor that works like Textmate...I think it's called E-TextEditor.
The benefit from using the editor in Umbraco is that you get the error messages when something is wrong when you're trying to save. When you edit the files outside of Umbraco you don't get the error messages and can save code that contains errors. But there is inbuilt error checking, which will notify you about possible syntax errors.
I have implemented the 2nd level macro and now all of the links are being shown in the menu system, both top and 2nd level. I assume there are settings that must be placed in the CSS file, but I am not sure as to what or where.
You'll have to take a look at the rendered code an see which ID's or Classes you have for ie. the UL and LI's in the source, and make css according to these.
.firstlevel {background-color:grey} .firstlevel li {color:red;} .firstlevel li a {text-decoration:none} .firstlevel li a:hover {text-decoration:underline} .firstlevel ul.secondlevel li {color:blue;}
Still having issues. Now when the page appears, both the top and 2nd level menus appear (no drop down) and when I click on a page, it goes to the correct page, but the menu disappears and an error message appears - Error parsing XSLT file: \xslt\umbTopNavigation.xslt.
<!-- Drop Down Menu --> <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0"> <ul> <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:attribute name="class"> <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id"> <xsl:attribute name="class">current</xsl:attribute> </xsl:if> </xsl:attribute> <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a> </li> </xsl:for-each> </ul> </xsl:if> <!-- End of Drop Down Menu --> </li> </xsl:for-each>
Top Navigation with Drop Down Menu
Can someone help me out with Drop Down Menu on Hover effect.
I have a top Navigation which i previously created in dreamweaver with the followin structure:
<ul id="top-navigation">
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT US</a>
<ul>
<li><a href="#">ASSOCIATION BACKGROUND</a></li>
<li><a href="#">MISSION & OBJECTIVE</a></li>
<li><a href="#">MANAGEMENT COMMITTEE</a></li>
<li><a href="#">CSR MANAGEMENT</a></li>
<li><a href="#">ABOUT MAURITIUS</a></li>
<li><a href="#">LINKS</a></li>
</ul>
</li>
<li><a href="#">SCHOOL</a>
<ul>
<li><a href="#">THE PRIMARY SCHOOL (CHALLENGES)</a></li>
<li><a href="#">THE PROGRAMME</a></li>
<li><a href="#">TEACHING STAFF</a></li>
<li><a href="#l">LEARNING DISABILITIES</a></li>
<li><a href="#">PARA-MEDICAL SUPPORT</a></li>
<li><a href="#">EXTRA-CURRICULUM ACTIVITIES</a></li>
</ul>
</li>
<li><a href="#">YOUNG ADULT CLASS</a></li>
<li><a href="#">AUTISM</a></li>
<li><a href="#">PARENT'S CORNER</a></li>
<li><a href="#">KID'S CORNER</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
This works perfectly with my css and the Hover effect as well but since am using umbraco i wanted to create it as an XSLT file but i cant get the second level navigation that is the Drop Down Menu:
Here is how i structured it in XSLT:
<xsl:variable name="level" select="1"/>
<xsl:variable name="dropDown" select="2"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul id="anougrandi-menu-top">
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$dropDown]/* [@isDoc and string(umbracoNaviHide) != '2']">
<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
</xsl:for-each>
</ul>
</li>
</xsl:for-each>
</ul>
Can someone help me out??
Fuji
Hi Fuji.
Could you try changing this:
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$dropDown]/* [@isDoc and string(umbracoNaviHide) != '2']">
<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
</xsl:for-each>
</ul>
to this:
Does this render the second level nodes under the right parent nodes?
/Kim A
Hi Kim,
I got it working.....
/fuji
Great to hear Fuji :)
/Kim A
Kim can you help me sort this out please
The Drop Down Menu works fine and when i click on one of the Links on top it returns a class to indicate this is the active Link but now am trying to get the same result but when clicking on the child node.
The parent node should be the active one.
Here is my code
<ul id="top-navigation">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/@level=$level">
<xsl:text>current</xsl:text>
</xsl:if>
</xsl:attribute>
<a href="/">
<xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
</a>
</li>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/@id=@id">
<xsl:text>current</xsl:text>
</xsl:if>
</xsl:attribute>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
<!-- Drop Down Menu -->
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/descendant::* [@level=1]">
<xsl:text>current</xsl:text>
</xsl:if>
</xsl:attribute>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
</xsl:for-each>
</ul>
</xsl:if>
<!-- End of Drop Down Menu -->
</li>
</xsl:for-each>
</ul>
Hi Fuji
Try changing this:
<xsl:attribute name="class">
<xsl:if test="$currentPage/descendant::* [@level=1]">
<xsl:text>current</xsl:text>
</xsl:if>
</xsl:attribute>
To this:
/Kim A
And you might want to change this for the parent node as well. You can do by changing this:
inside the for-each loop, to this:
/Kim A
Doh!
The above code I wrote to you was to the legacy schema. Try this instead:
The difference is the node that has been changed to *[@isDoc]
/Kim A
Nope still not working....the parent still not being highlighted....when i view the source code its still the child node which contains the class="current".
In my case my top navigation is
Accueil
Informations
Produits
Formation
Contact
So when i click on Informations main page the Link on top of my menu is Highlighted when if i click on Information 1 my parent Informations is not Hightlighted.
/Fuji
Kim i got it working!!!....Great ...... one of my classes was missing!!
Thanks a bunch....
/fuji
Thats good to hear Fuji. Could you show us the code that solved the problem?
/Kim A
Yours actually.....i needed to removed the for-each loop on my parent node to get the child node working and at same forgot to add a class in my css.
Thanks
/fuji
Okay cool to hear that. I couldn't understand what was wrong with the code I posted as I have used it myself earlier, so I got a bit confused there :)
/Kim A
Hi guys
Have taken the opportunity to follow this, and it works just fine. Thanks!
However I would like to keep certain document types away from the dropdown.
I've been struggeling with how to do that in Umb ver. 4.5.2....
Can you help me out here..?
Thanks
Best,
Morten
Hi Morten,
What do you mean by document types?? If am not mistaken you dont need any document type for the drop down Navigation...all you need is an XSLT file.
With the new release of umbraco v4.7 its more fun using Razor
/Fuji
Hi Fuji
In my nodetree I have pages created with document type "SiteStandard" ande some withe documenttype "ItemElement"
It's only the nodes with "SiteStandard" I want to show in my dropdown.
Nodes with "ItemElement" should be filtered away, as they are used for other purpose.
Thanks
Morten
What you can do is create another XSLT but choose "List Pages from Changeable Source' and create a source tab and just apply it to you template.
Then you copy > paste the list style you used in the previous navigation.
/Fuji
An acceptable workaround...,
Thanks for pointing the direction, Fuji!
Best,
Morten
Hello everyone,
This post has been very helpful. I am also pretty new in XSLT and had some issue incorporing it in my own nav.
Here is the code
And error I'm receiving from Umbraco XSTLT editor
"System.Xml.Xsl.XslLoadException: The variable or parameter 'level' is either not defined or it is out of scope."
One last question: What XSLT editor is perferred? I would like to work with XSLT but I'm not sure what editor to use.
Thank you for everyones help and time
Hi Carl
You get the error because you have not defined a variable named "level".
In this part
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
you make sure that nodes are only selected from the level that is specified in the $level variable...only problem is though that it does not exist :-)
So in order to make it work you need to specify the variable of course.
You can specify it right after the <xsl:template match="/"> or right before it.
Do it like this
<xsl:variable name="level" select="1" />
You could also skip using this variable and instead write the level directly in the for-each section like this
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level='1']/* [@isDoc and string(umbracoNaviHide) != '1']">
For editing XSLT files I'm using visual studio when working on Windows. If you're using a Mac I think Textmate is what you would want to use. Also for Windows there is an editor that works like Textmate...I think it's called E-TextEditor.
The benefit from using the editor in Umbraco is that you get the error messages when something is wrong when you're trying to save. When you edit the files outside of Umbraco you don't get the error messages and can save code that contains errors. But there is inbuilt error checking, which will notify you about possible syntax errors.
I hope this makes sense to you.
/Jan
Hey Jan,
Thank you so much for your help! That solved an issue I was having for a long time. Please let me know where I can send the case of beer.
Hi Carl
You're very welcome - I'm glad to hear you got it solved.
If you're planning til attend Codegarden we can grab a beer - otherwise I think wee need to keep track in here: http://foamee.com/ :D
Have a great day :-)
/Jan
have you created an XSLT by Level or clean one?
//fuji
have you created an XSLT by Level or clean one?
//fuji
I have implemented the 2nd level macro and now all of the links are being shown in the menu system, both top and 2nd level. I assume there are settings that must be placed in the CSS file, but I am not sure as to what or where.
Any help would be greatly appreciated.
Thank you,
Tim - Umbraco Rookie
You're on track.
You'll have to take a look at the rendered code an see which ID's or Classes you have for ie. the UL and LI's in the source, and make css according to these.
<ul class="firstlevel">
<li><a href="#">Item1<a/></li>
<li><a href="#">Item2<a/></li>
<ul class="secondlevel">
<li><a href="#">Item1<a/></li>
<li><a href="#">Item2<a/></li>
</ul>
<li><a href="#">Item3<a/></li>
</ul>
and css:
.firstlevel {background-color:grey}
.firstlevel li {color:red;}
.firstlevel li a {text-decoration:none}
.firstlevel li a:hover {text-decoration:underline}
.firstlevel ul.secondlevel li {color:blue;}
Still having issues. Now when the page appears, both the top and 2nd level menus appear (no drop down) and when I click on a page, it goes to the correct page, but the menu disappears and an error message appears - Error parsing XSLT file: \xslt\umbTopNavigation.xslt.
Here is the code:
<?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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>
<xsl:template match="/">
<ul id="top-navigation">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/@level=$level">
<xsl:text>current</xsl:text>
</xsl:if>
</xsl:attribute>
<a href="/">
<xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
</a>
</li>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
</xsl:attribute>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
<!-- Drop Down Menu -->
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
</xsl:attribute>
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
<!-- End of Drop Down Menu -->
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Thanks for the help.
Tim
is working on a reply...