Copied to clipboard

Flag this post as spam?

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


  • Sam 63 posts 126 karma points
    Apr 16, 2012 @ 11:24
    Sam
    0

    Show sub menu when on corresponding level (2 or 3)

    Hi all,

    I have witten an xslt to shoe a sub menu for level 3 of a menu...

    <xsl:variable name="level" select="3"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <div id="navSubMnu">  
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
                              <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
                                    <xsl:attribute name="class">current</xsl:attribute>
                                  </xsl:if>
                               <xsl:attribute name="href">
                                 <xsl:choose>
                                  <xsl:when test="count(./*[@isDoc]) &gt; 1  and string(linkToSubpage) = '1'">
                                       <xsl:value-of select="umbraco.library:NiceUrl(./*[@isDoc]/@id)" />
                                     </xsl:when>           
                                      <xsl:otherwise>
                                         <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
                                      </xsl:otherwise>           
                                 </xsl:choose>
                              </xsl:attribute>
                             <xsl:value-of select="@nodeName"/>
        </a>
        
        
      </li>
    </xsl:for-each>
    </ul>
        </div>
    </xsl:template>

     

    I want to modify this to show the sub menu on level 2 also..that is depending on whiche level we are..show the sub menu.

     

    My structure:

    default 
     Home
      About 
        Menu 1 (level 2)
        Menu 2  (level 2)
        Menu 3
            Sub-menu 1 (level 3)
            Sub-menu 2 (level 3)

    Any help please.

    //Sam


  • sun 403 posts 395 karma points
    Apr 16, 2012 @ 11:41
    sun
    0

    give you some code of my site. It will show you how to do it. notice that variable level can set which level you want to show.

     

    <xsl:stylesheet

      version="1.0"

      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

      xmlns:umbraco.library="urn:umbraco.library"

      exclude-result-prefixes="umbraco.library">

     

        <xsl:output method="html" omit-xml-declaration="yes" />

     

        <xsl:param name="currentPage"/>

     

        <xsl:variable name="level" select="0"/>

     

        <xsl:template match="/">

            <ul>

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

                <xsl:for-each select="$root/*[@isDoc and navigator=1]">

                  <xsl:sort select="@sortOrder"/>

                    <li>

                        <a href="{umbraco.library:NiceUrl(@id)}">

                            <xsl:if test="$currentPage/ancestor-or-self::*[@level=2]/@id=@id">

                                <xsl:attribute name="class"> active</xsl:attribute>

                            </xsl:if>

                                <xsl:value-of select="@nodeName"/>

                        </a>

                        <xsl:call-template name="subMenu">

                            <xsl:with-param name="node" select="."/>

                            <xsl:with-param name="level" select="$level"/>

                        </xsl:call-template>

                    </li>

                </xsl:for-each>

            </ul>

     

        </xsl:template>

     

        <xsl:template name="subMenu">

            <xsl:param name="node"/>

            <xsl:param name="level"/>

            <xsl:if test="$level=0 or $node/@level &lt; $level">

                <xsl:variable name="subItems" select="$node/*[@isDoc and navigator = 1]"/>

                <xsl:if test="count($subItems)>0">

                    <ul>

                        <xsl:for-each select="$subItems">

                            <li>

                                <a href="{umbraco.library:NiceUrl(@id)}">

                                    <xsl:value-of select="@nodeName"/>

                                </a>

                                <xsl:call-template name="subMenu">

                                    <xsl:with-param name="node" select="."/>

                                    <xsl:with-param name="level" select="$level"/>

                                </xsl:call-template>

                            </li>

                        </xsl:for-each>

                    </ul>

                </xsl:if>

            </xsl:if>

     

        </xsl:template>

     

    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft