Copied to clipboard

Flag this post as spam?

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


  • Joe 21 posts 41 karma points
    Feb 18, 2011 @ 21:50
    Joe
    0

    Second Level Navigation - Quick Fix?

    I am trying to get my second level nav links to show up only when their parent is clicked. Right now, all second level nav links are layed out statically beneath their parent.

    <?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"
           
    exclude-result-prefixes="msxml umbraco.library">


    <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:template match="/">

    <!-- The fun starts here -->


    <xsl:for-each select="umbraco.library:GetXmlNodeById(1045)/node [string(data [@alias='umbracoNaviHide']) != '1']">
                   
    <a href="{umbraco.library:NiceUrl(@id)}" class="navOff">
                           
    <xsl:choose>
                                   
    <xsl:when test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                           
    <xsl:attribute name="class">navOn</xsl:attribute>
                                           
                                   
    </xsl:when>
                                   
    <xsl:otherwise>
                                           
    <xsl:attribute name="class">navOff</xsl:attribute>
                                   
    </xsl:otherwise>
                           
    </xsl:choose>
                           
    <xsl:value-of select="@nodeName"/>
                   
    </a>
    <!-- Secondary Nav -->
     
    <xsl:if test="count(./child::node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; 0">
               
    <ul>
                   
    <xsl:for-each select="./child::node [string(data [@alias='umbracoNaviHide']) != '1']">
                       
    <li>
                           
    <a href="{umbraco.library:NiceUrl(@id)}">
                                   
    <xsl:value-of select="@nodeName"/>
                           
    </a>                      

                       
    </li>
                   
    </xsl:for-each>
               
    </ul>    
           
    </xsl:if>

    <!-- Secondary Nav -->
    </xsl:for-each>


    </xsl:template>

    </xsl:stylesheet>
  • kows 81 posts 151 karma points c-trib
    Feb 19, 2011 @ 18:56
    kows
    0

    add a check to your xsl:if for second nav if $currentPage equals the selected node (same test for your class)...?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 19, 2011 @ 19:35
    Kim Andersen
    0

    Hi Joe

    Try changing your xsl:if to this:

    <xsl:if test="count(./child::node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; 0 and count(descendant-or-self::node [@id = $currentPage/@id]) &gt; 0">

    Does that help?

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft