Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
My XSLT shows the navigation of my site as i need it to, but when i am on the homepage it does not change the style of the LI to be highlighted. Please could someone have a look and tell me what i am doing wrong for the homepage section.
Thanks
Chris
<?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"/> <!-- 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:variable name="maxlevel" select="3"/> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:template match="/"> <!-- The fun starts here --> <ul> <li> <a href="{umbraco.library:NiceUrl($siteRoot/@id)}"> <xsl:if test="$currentPage/self::*/@id = current()/@id"> <xsl:attribute name="class">highlight</xsl:attribute> </xsl:if> <span class="menuTxt"> <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/> </span> </a> </li> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <xsl:attribute name="class">highlight</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <span class="menuTxt"> <xsl:value-of select="@nodeName"/> </span> </a> </li> <xsl:if test="count(./*[@isDoc])>0 and count(descendant-or-self::*[@id = $currentPage/@id]) > 0"> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level>$level and @level<$maxlevel]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <xsl:choose> <xsl:when test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <xsl:attribute name="class">subhighlight</xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="class">sub</xsl:attribute> </xsl:otherwise> </xsl:choose> <a href="{umbraco.library:NiceUrl(@id)}"> <span class="subMenuTxt"> <xsl:value-of select="@nodeName"/> </span> </a> </li> </xsl:for-each> </ul> </xsl:if> </xsl:for-each> </ul> </xsl:template></xsl:stylesheet>
Hi Chris,
In this line:
<xsl:if test="$currentPage/self::*/@id = current()/@id">
current() is referring to the "/" that's matched on the template (which is actually the <macro> element)
try changing that line to this:
<xsl:if test="$currentPage/@id = $siteRoot/@id">
and you should get your highlight class...
/Chriztian
Hey
Im not sure if this is it but I would write this:
Like this
<xsl:if test="$currentPage/@id = current()/@id">
Dont think there is any need for the self::*
could be wrong though.
L
Not sure what might be wrong with yours, but I use this
<li> <a href="/"> <xsl:if test="$currentPage/@level=1"> <xsl:attribute name="class">highlight</xsl:attribute> </xsl:if> <xsl:value-of select="$currentPage/ancestor-or-self::node/@nodeName"/> </a> </li>
Also it seems that you are applying the class to the href for home but on the <li> for the rest of the nav, is that what you wanted?
Rich
Wait Chriztian is totally right.
:)
Thank you all for your help.
Chriztian, works perfectly.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Highlighting home page
Hi,
My XSLT shows the navigation of my site as i need it to, but when i am on the homepage it does not change the style of the LI to be highlighted. Please could someone have a look and tell me what i am doing wrong for the homepage section.
Thanks
Chris
<?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"/>
<!-- 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:variable name="maxlevel" select="3"/>
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<li>
<a href="{umbraco.library:NiceUrl($siteRoot/@id)}">
<xsl:if test="$currentPage/self::*/@id = current()/@id">
<xsl:attribute name="class">highlight</xsl:attribute>
</xsl:if>
<span class="menuTxt">
<xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>
</span>
</a>
</li>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<xsl:attribute name="class">highlight</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<span class="menuTxt">
<xsl:value-of select="@nodeName"/>
</span>
</a>
</li>
<xsl:if test="count(./*[@isDoc])>0 and count(descendant-or-self::*[@id = $currentPage/@id]) > 0">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level>$level and @level<$maxlevel]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:choose>
<xsl:when test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<xsl:attribute name="class">subhighlight</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class">sub</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<a href="{umbraco.library:NiceUrl(@id)}">
<span class="subMenuTxt">
<xsl:value-of select="@nodeName"/>
</span>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Hi Chris,
In this line:
current() is referring to the "/" that's matched on the template (which is actually the <macro> element)
try changing that line to this:
and you should get your highlight class...
/Chriztian
Hey
Im not sure if this is it but I would write this:
<xsl:if test="$currentPage/self::*/@id = current()/@id">
Like this
<xsl:if test="$currentPage/@id = current()/@id">
Dont think there is any need for the self::*
could be wrong though.
L
Hi,
Not sure what might be wrong with yours, but I use this
Also it seems that you are applying the class to the href for home but on the <li> for the rest of the nav, is that what you wanted?
Rich
Wait Chriztian is totally right.
:)
Thank you all for your help.
Chriztian, works perfectly.
Thanks
is working on a reply...