Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    Sep 08, 2010 @ 09:47
    MartinB
    0

    TopNavigation class disappears on sublevel items

    Hi there

    I'm building a multilevel menu, nothing new there, but i've run into a small challenge.

    I test if the selected item is the active item, and if yes, apply .selected css class.

    BUT, when i start to click sublevel items (level 2), then the .selected class disappears from my top navigation. I've not had this problem before, and whatever i do i can't seem to figure it out.

    Xslt for topnavigation:

    <?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 -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->

    <ul id="topnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:choose>
    <xsl:when test="expandedUrl != '' ">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" /><xsl:value-of select="expandedUrl" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>

    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

    Xslt for subnavigation:

    <?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 -->
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">

    <ul id="subnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:attribute>

    <xsl:if test="$currentPage/ancestor-or-self/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>
  • Rich Green 2246 posts 4006 karma points
    Sep 08, 2010 @ 10:02
    Rich Green
    0

    In your Top Nav change the following

    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
                                                                   
    <xsl:attribute name="class">selected</xsl:attribute>
                                                   
    </xsl:if>

    to

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

    Rich

  • MartinB 411 posts 512 karma points
    Sep 08, 2010 @ 10:07
    MartinB
    0

    Hi Rich

    Thanks for your contribution. Unfortunately your example removes the .selected class of my topnavigation item completely

  • MartinB 411 posts 512 karma points
    Sep 08, 2010 @ 10:17
    MartinB
    0

    Ok, found it:

    <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">

    Did the trick

  • Rich Green 2246 posts 4006 karma points
    Sep 08, 2010 @ 10:31
    Rich Green
    0

    Glad you worked it out :)

    I assumed you were using an pre 4.5 version of Umbraco.

    Rich

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies