Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 19 posts 40 karma points
    Jan 27, 2010 @ 10:44
    Nicky Christensen
    0

    Third level in menu disappears

    Hey everyone...

    If you take a look at http://www.markings.dk/produkter/macsa-laser.aspx
    And click at "Gummi" in the left menu, the left menu collapses, it shouldnt, the left menu should remain open, and "Gummi" should get the "Selected" class

    The XSLT that handles the menu is this:

    <?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:param name="level" select="2"/>
        <xsl:template match="/">
        <div class="leftmenu">
            <xsl:call-template name="menu">
                <xsl:with-param name="level" select="$level"/>
            </xsl:call-template>
        </div>
        </xsl:template>
        <xsl:template name="menu">
            <xsl:param name="level"/>
            <ul class="level_{@level}">
                <xsl:if test="count($currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; '0'">
                    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
                        <li>
                            <xsl:if test="$currentPage/@id = current()/@id">
                                    <xsl:attribute name="class">selected</xsl:attribute>
                            </xsl:if>
                                <a href="{umbraco.library:NiceUrl(@id)}">
                                    <xsl:if test="$currentPage/@id = current()/@id">
                                        <xsl:attribute name="class">selected</xsl:attribute>
                                    </xsl:if>
                                    <xsl:value-of select="@nodeName"/>
                                </a>
                            <xsl:if test="count(current()/node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; '0'">
                                <xsl:call-template name="submenu">
                                    <xsl:with-param name="level" select="$level+1"/>
                                </xsl:call-template>
                            </xsl:if>
                        </li>
                    </xsl:for-each>
                </xsl:if>
            </ul>
        </xsl:template>
        <xsl:template name="submenu">
            <xsl:param name="level"/>
            <ul class="level_{@level}">
                <xsl:for-each select="current()/node [string(data [@alias='umbracoNaviHide']) != '1']">
                    <li>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                <xsl:if test="$currentPage/@id = current()/@id">
                                    <xsl:attribute name="class">Selected</xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="@nodeName"/>
                            </a>
                    </li>
                </xsl:for-each>
            </ul>
        </xsl:template>
    </xsl:stylesheet>

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    Jan 27, 2010 @ 10:57
    Lee Kelleher
    1

    Hi Nicky,

    The reason the third level menu is hidden is because of the way your CSS is handling it.  The parent menu item needs to keep the "selected" class.

    Here's an updated XSLT for you:

    <?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:param name="level" select="2"/>
    
        <xsl:template match="/">
            <div class="leftmenu">
                <xsl:call-template name="menu">
                    <xsl:with-param name="level" select="$level"/>
                </xsl:call-template>
            </div>
        </xsl:template>
    
        <xsl:template name="menu">
            <xsl:param name="level"/>
            <ul class="level_{@level}">
                <xsl:if test="count($currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; '0'">
                    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
                        <li>
                            <xsl:if test="$currentPage/@id = @id or $currentPage/ancestor-or-self::node/@id = @id">
                                <xsl:attribute name="class">selected</xsl:attribute>
                            </xsl:if>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                <xsl:if test="$currentPage/@id = @id or $currentPage/ancestor-or-self::node/@id = @id">
                                    <xsl:attribute name="class">selected</xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="@nodeName"/>
                            </a>
                            <xsl:if test="count(current()/node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; '0'">
                                <xsl:call-template name="submenu">
                                    <xsl:with-param name="level" select="$level+1"/>
                                </xsl:call-template>
                            </xsl:if>
                        </li>
                    </xsl:for-each>
                </xsl:if>
            </ul>
        </xsl:template>
    
        <xsl:template name="submenu">
            <xsl:param name="level"/>
            <ul class="level_{@level}">
                <xsl:for-each select="current()/node [string(data [@alias='umbracoNaviHide']) != '1']">
                    <li>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:if test="$currentPage/@id = current()/@id">
                                <xsl:attribute name="class">Selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="@nodeName"/>
                        </a>
                    </li>
                </xsl:for-each>
            </ul>
        </xsl:template>
    
    </xsl:stylesheet>

    Cheers, Lee.

  • Nicky Christensen 19 posts 40 karma points
    Jan 27, 2010 @ 11:01
    Nicky Christensen
    0

    Great, thx alot :)

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    Jan 27, 2010 @ 11:02
    Lee Kelleher
    1

    Ooops, forgot to explain the change, doh!

    For the "class=selected" attribute, we include an extra condition:

    <xsl:if test="$currentPage/@id = @id or $currentPage/ancestor-or-self::node/@id = @id">
        <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>

    Whilst iterating through the nodeset, we check for the "$currentPage/ancestor-or-self::node/@id = @id" XPath. If a parent node matches the ID, then it will add the "class=selected".

    That should keep your menu structure expanded - based on your existing CSS.

    Cheers, Lee.

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    Jan 27, 2010 @ 11:02
    Lee Kelleher
    0

    Glad it worked Nicky, don't forget to mark the solution.

    Cheers, Lee.

  • Nicky Christensen 19 posts 40 karma points
    Jan 27, 2010 @ 11:12
    Nicky Christensen
    1

    Yeah, works like a charm :) Thx again mate :)

Please Sign in or register to post replies

Write your reply to:

Draft