Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Knowles 141 posts 222 karma points
    Dec 08, 2010 @ 12:03
    Chris Knowles
    0

    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 "&#x00A0;">
    ]>
    <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>            
            <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>          
              <href="{umbraco.library:NiceUrl(@id)}">
              <span class="menuTxt">
                <xsl:value-of select="@nodeName"/>
              </span>
              </a>
            </li>
            <xsl:if test="count(./*[@isDoc])&gt;0 and count(descendant-or-self::*[@id = $currentPage/@id]) &gt; 0">
              
           <ul>
                <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level>$level and @level&lt;$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>
                    <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>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 08, 2010 @ 12:10
    Chriztian Steinmeier
    0

    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

  • Lachlann 344 posts 626 karma points
    Dec 08, 2010 @ 12:10
    Lachlann
    0

    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

  • Rich Green 2246 posts 4008 karma points
    Dec 08, 2010 @ 12:11
    Rich Green
    0

    Hi,

    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

  • Lachlann 344 posts 626 karma points
    Dec 08, 2010 @ 12:12
    Lachlann
    0

    Wait Chriztian is totally right.

    :)

  • Chris Knowles 141 posts 222 karma points
    Dec 08, 2010 @ 12:14
    Chris Knowles
    0

    Thank you all for your help. 

    Chriztian, works perfectly.

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies