I have a tree level navigation, and its all working fine.
One macro for the main navigation and one macro for the subnavigation. When i am on the second level everything works fine. The active element gets its class. But when i move on to the third level i still want the second level element to be active. Se the page here: http://spotpaint.no/om-oss/for-bedrift.aspx
I want the element "om oss" to have the selected class.
I changed a few things, like moving the HREF to be inline and setting a CSS class for each of the links - so you don't need to double-check for the "selected" page in the "last" section. Lastly, I removed a few of the "./" (dot-slash) as you don't really need them in this context.
I think it's because of this these lines of code you're having problems:
t<xsl:if test="$currentPage/ancestor-or-self::node/@id= current()/@id"> - this should read t<xsl:if test="$currentPage/ancestor-or-self::*/@id= current()/@id">
and
<xsl:when test="$currentPage/@id = current()/@id"> - This should read <xsl:when test="$currentPage/ancestor-or-self::*/@id = current()/@id">
Trouble with navigation and selected class
I have a tree level navigation, and its all working fine.
One macro for the main navigation and one macro for the subnavigation. When i am on the second level everything works fine. The active element gets its class. But when i move on to the third level i still want the second level element to be active. Se the page here: http://spotpaint.no/om-oss/for-bedrift.aspx
I want the element "om oss" to have the selected class.
Here is the xslt for the main 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"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:param name="navigationRoot" select="$currentPage/ancestor-or-self::*[@level=1]" />
<xsl:param name="shouldShowHome" select="1" />
<xsl:param name="cnt" select="count($navigationRoot/* [@isDoc])" />
<!-- The fun starts here -->
<ul>
<xsl:if test="$shouldShowHome=1">
<li>
<a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[@level=1]/@id)}">
<xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::*[@level=1]/@id">
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="$currentPage/ancestor-or-self::*[@level=1]/@nodeName"/>
</a>
</li>
</xsl:if>
<xsl:for-each select="$navigationRoot/* [@isDoc]">
<xsl:if test="./@id > 0 and ./umbracoNaviHide!=1">
<li><a>
<xsl:choose>
<xsl:when test="$cnt=position()">
<xsl:attribute name="class">
last<xsl:if test="$currentPage/ancestor-or-self::node/@id= current()/@id"> selected</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:when test="$currentPage/@id = current()/@id">
<xsl:attribute name="class"> selected</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:attribute name="href">
<xsl:value-of select="umbraco.library:NiceUrl(./@id)" />
</xsl:attribute>
<xsl:value-of select="./@nodeName"/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
I really hope someone can help me width this :)
Hi Cecilie,
The problem is that you were referencing the node name as "node" (old XML schema) instead of "*[@isDoc]" (new XML schema).
No worries... I've tried to help by re-writing a little snippet of your XSLT - which you might find easier to use?
I changed a few things, like moving the HREF to be inline and setting a CSS class for each of the links - so you don't need to double-check for the "selected" page in the "last" section. Lastly, I removed a few of the "./" (dot-slash) as you don't really need them in this context.
Cheers, Lee.
Hi Cecillie and welcome to the forum :)
I think it's because of this these lines of code you're having problems:
t<xsl:if test="$currentPage/ancestor-or-self::node/@id= current()/@id"> - this should read t<xsl:if test="$currentPage/ancestor-or-self::*/@id= current()/@id">
and
<xsl:when test="$currentPage/@id = current()/@id"> - This should read <xsl:when test="$currentPage/ancestor-or-self::*/@id = current()/@id">
I hope this helps.
/Jan
Too slow, Lee is da man :)
Magic, thank you so much, works like a dream :)
is working on a reply...