Copied to clipboard

Flag this post as spam?

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


  • Daniel 19 posts 51 karma points
    Mar 08, 2011 @ 08:42
    Daniel
    0

    Highlight 'home' link in navigation

    I've seen some examples in the forum but haven't gotten any of them to work with my xslt navigation.

        <xsl:output method="xml" omit-xml-declaration="yes" />
        <xsl:param name="currentPage"/>
        <xsl:variable name="level" select="1"/>
        <xsl:template match="/">
      
        <li>
          <a href="/">Home</a>
        </li>

        <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(showInNavigation) = '1']">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
                <xsl:attribute name="class">active</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="@nodeName"/>
            </a>
          </li>
        </xsl:for-each>
      </xsl:template>

    This is what I have so far. As you can see the 'home' button is outside the loop and therefore not highlighted when clicked like the other pages. How can I incorporate the 'home' button into the navigation of the sub nodes?

    I appreciate your help!

  • Daniel 19 posts 51 karma points
    Mar 08, 2011 @ 08:52
    Daniel
    2

    I'm sorry for beeing too hasty, I solved it myself. I added this line above template:

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    And added this before the for each loop:

          <!-- Home node added here -->
          <li>            
            <a href="{umbraco.library:NiceUrl($siteRoot/@id)}">
              <xsl:if test="$currentPage/@id = $siteRoot/@id">
                <xsl:attribute name="class">active</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>            
            </a>        
          </li>

    This is the final code of my top navigation menu which highlights the home link:

    <?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"/>
        <xsl:variable name="level" select="1"/>
        
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

        <xsl:template match="/">
          <!-- Home node added here -->
          <li>            
            <a href="{umbraco.library:NiceUrl($siteRoot/@id)}">
              <xsl:if test="$currentPage/@id = $siteRoot/@id">
                <xsl:attribute name="class">active</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/>            
            </a>        
          </li>
        
        <!-- Sub nodes added here -->
        <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(showInNavigation) = '1']">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
                <xsl:attribute name="class">active</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="@nodeName"/>
            </a>
          </li>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

    I hope someone will find this useful.

  • Daniel 19 posts 51 karma points
    Mar 15, 2011 @ 09:15
    Daniel
    0

    Maybe an admin want to check this thread as solved? :)

Please Sign in or register to post replies

Write your reply to:

Draft