Copied to clipboard

Flag this post as spam?

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


  • Christophe 23 posts 43 karma points
    Nov 01, 2010 @ 23:08
    Christophe
    0

    Add level to structured navigation menu from xslt

    Hello,

    Someone built my site for me so I am scared $#!^less about making changes. So far I have been successful thanks to you. To try out things I use a local copy of CWS. My site was based from CWS.

    I am trying to add a dropdown menu to my navigation bar but the way it was built there is no level below the first level (home is in the nav bar which I want). The "tab" at the page I am at is highlighted. The xslt code calling the structured list is :

    <?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"/>
    
        <xsl:template match="/">
    
            <ul>
    
                <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::node [@level=1]" />
    
                <li>
                    <!--
                        Add the class selected if the root node ID matches our 
                        current node ID in the for each loop
                        -->
                    <xsl:if test="$rootNode/@id = $currentPage/@id">
                        <xsl:attribute name="class">
                            <xsl:text>
                                selected
                            </xsl:text>
                        </xsl:attribute>
                    </xsl:if>
    
                    <a href="{umbraco.library:NiceUrl($rootNode/@id)}">
                        <xsl:value-of select="$rootNode/@nodeName" />
                    </a>
                </li>
    
                <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']">
                    <li>
                        <!--
                        Add the class selected if the currentpage or parent nodes (up the tree to the root) 
                        ID matches our current node ID in the for each loop
                        -->
                        <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                            <xsl:attribute name="class">
                                <xsl:text>
                                    selected
                                </xsl:text>
                            </xsl:attribute>
                        </xsl:if>
    
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName" />
                        </a>
                    </li>
                </xsl:for-each>
            </ul>
    
        </xsl:template>
    
    </xsl:stylesheet>

    Now I have tried hard to replicate that in CWS but in vain. The solution would be to use sitemap (I could manage) but when I test that in the local copy it does not include the home button.

    My questions are 1) can I use the xslt to drill down one level? 2) how can I get the home button in the sitemap (umbracoNavihide is unchecked).

    Thanks in advance for your help.

    Christophe

  • Jon Cuthbert 84 posts 173 karma points
    Nov 23, 2010 @ 23:19
    Jon Cuthbert
    0

    To drill down another level inside your 'li' add this code:

    <xsl:if test="count(node [string(data[@alias='umbracoNaviHide']) != '1']) &gt; 0">
    <ul>
    <xsl:for-each select="node [string(data[@alias='umbracoNaviHide']) != '1']">
    <a href="{umbraco.library:NiceUrl(@id)}">
     
    <xsl:value-of select="@nodeName" />
     
    </a>
    </xsl:for-each>
    </ul>
    </xsl:if>

    To include a link to your home button it looks like you already had the code:

                <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::node [@level=1]" />
               
             
    <li>
                   
    <!--
                        Add the class selected if the root node ID matches our
                        current node ID in the for each loop
                        -->

                   
    <xsl:if test="$rootNode/@id = $currentPage/@id">
                       
    <xsl:attribute name="class">
                           
    <xsl:text>
                                selected
                           
    </xsl:text>
                       
    </xsl:attribute>
                   
    </xsl:if>
                   
                   
    <a href="{umbraco.library:NiceUrl($rootNode/@id)}">
                       
    <xsl:value-of select="$rootNode/@nodeName" />
                   
    </a>
               
    </li>


     

Please Sign in or register to post replies

Write your reply to:

Draft