Copied to clipboard

Flag this post as spam?

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


  • TaoistTotty 246 posts 314 karma points
    Nov 06, 2010 @ 13:03
    TaoistTotty
    0

    ancestor not selecting home item on menu

    I am trying to use the following code to make the root of sub-menu items appear highlighted when the sub items are selected.

    This works on all pages, even those without sub-pages except the home page.

    What am I missing?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;">
                                <!ENTITY hidden "umbracoNaviHide = 1">
                                <!ENTITY node "*[@isDoc]">
    ]>
    <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="homeMenu" select="/macro/homeItem"/>
        <xsl:variable name="homePage" select="umbraco.library:GetXmlNodeById($homeMenu)"/>

    <xsl:template match="/">

      
      <xsl:if test="$homeMenu !=''">
        <xsl:variable name="homePage" select="umbraco.library:GetXmlNodeById($homeMenu)"/>
        <ul>
          <xsl:apply-templates select="$homePage | $homePage/&node;"/>
        </ul>
      </xsl:if>

    </xsl:template>
    <xsl:template match="&node;">
      <li>
        <xsl:if test="@id = $currentPage/ancestor-or-self::&node;/@id and @id != $homeMenu">
            <xsl:attribute name="class">
              current
            </xsl:attribute>
          </xsl:if>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="navigationName"/>
        </a>
        <xsl:variable name="nextLevel" select="current()"/>
        <xsl:if test="count($nextLevel/&node;) &gt; 0 and position() != 1 and $nextLevel/&node; [umbracoNaviHide != 1] and @id != 1283">
          <ul>
            <xsl:for-each select="$nextLevel/&node;">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="navigationName"/>
                </a>
              </li>
            </xsl:for-each>
          </ul>
        </xsl:if>
      </li>
    </xsl:template>
        <xsl:template match="&node;[&hidden;]"/>    
    </xsl:stylesheet>

    Many thanks.

    TT

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 06, 2010 @ 21:19
    Chriztian Steinmeier
    0

    Hi TT,

    As far as I can see, you're actively excluding the homeMenu from getting the "current" class:

    <xsl:if test="@id = $currentPage/ancestor-or-self::&node;/@id and @id != $homeMenu">

    ?

    /Chriztian

  • TaoistTotty 246 posts 314 karma points
    Nov 06, 2010 @ 22:06
    TaoistTotty
    0

    Thank you for your reply Chriztian, I should have been clearer.

    I am trying to exclude the homeMenu except when it is the page that has focus.

    Regards

    Michael

  • 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