Copied to clipboard

Flag this post as spam?

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


  • RobbyO 2 posts 22 karma points
    Feb 20, 2013 @ 06:59
    RobbyO
    0

    XSLT Dropdown Menu: how to add a "Home" link?

    I am very close to having a Macro/XSLT create a drop down navigation menu. (I am new to XSLT)

    Using the following XSLT, I am unable to get the "Home" node added to the navigation menu.  How is it that I can add the Home link like the default 

    My desired HTML is as follows:

    <nav>
        <ul>
            <li ><a href="/">HOME</a></li>
            <li><a href="#">Link 2</a>
                <ul>
                    <li><a href="#">Link 2.1</a></li>
                    <li><a href="#">Link 2.2</a></li>
                    <li><a href="#">Link 2.3</a></li>
                </ul>
            </li>
            <li><a href="#">Link 3</a></li>
        </ul>
    </nav>

    My current XSLT is as follows:

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
    
    <xsl:template match="/">
        <nav> 
            <xsl:call-template name="drawNodes">  
                <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
            </xsl:call-template>
        </nav>
    </xsl:template>
    
    <xsl:template name="drawNodes">
        <xsl:param name="parent"/> 
        <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
            <ul>
                <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]"> 
                <li>
                    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>  
                        <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
                            <xsl:call-template name="drawNodes">    
                                <xsl:with-param name="parent" select="."/>                </xsl:call-template>  
                        </xsl:if> 
                </li>
                </xsl:for-each>
            </ul>
        </xsl:if>
    </xsl:template>
    <xsl:template name="drawLevel1">
    </xsl:template>

    The default umbTopNavigation uses the following to add the Home link, but i get an error when trying to add it after the opening <nav>:

           <li class="home">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home current</xsl:attribute>
             </xsl:if>
             <a href="/">Home</a>
           </li>

    Any thoughts?

Please Sign in or register to post replies

Write your reply to:

Draft