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
    Dec 09, 2009 @ 11:44
    Nicky Christensen
    0

    Submenu, has children then add class?

    I have a submenu, the structure of if goes out to level 4, but when entering a subpage, i want those pages which has children to have a class called "hasChildren" - And when clicking the link that has children is gets 2 classes, "current and hasChildren" How do i do that?

    My XSLT:

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="2"/>
    <xsl:variable name="minLevel" select="1"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <div class="leftmenu">
    <xsl:if test="$currentPage/@level &gt;= 3 or count($currentPage/child::node [string(data [@alias='umbracoNaviHide'])  != '1' and @level = '3']) &gt; 0">
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                    <!-- we're under the item - you can do your own styling here -->
                    <xsl:attribute name="class">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </div>
    </xsl:template>

    </xsl:stylesheet>
     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 09, 2009 @ 22:33
    Chriztian Steinmeier
    0

    Hi Nicky,

    This should get you off to a good start:

    <?xml version="1.0" encoding="utf-8" ?>
    <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="xml" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" /> 
    
        <xsl:variable name="startLevel" select="2" />
    
        <xsl:template match="/">
            <ul id="navigation">
                <xsl:apply-templates select="$root//node[@level = $startLevel]" />
            </ul>
        </xsl:template>
    
        <xsl:template match="node">
            <!-- Determine CSS class -->
            <xsl:variable name="cssClass">
                <xsl:if test="node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
                    <xsl:text>hasChildren</xsl:text>
                </xsl:if>
                <xsl:if test="@id = $currentPage/@id">
                    <xsl:text> current</xsl:text><!-- Notice the leading SPACE... -->
                </xsl:if>
            </xsl:variable>
    
            <li>
                <!-- Set class attribute if necessary -->
                <xsl:if test="normalize-space($cssClass)">
                    <xsl:attribute name="class">
                        <xsl:value-of select="normalize-space($cssClass)" />
                    </xsl:attribute>
                </xsl:if>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName" />
                </a>
    
                <!-- Got any childnodes that aren't hidden? -->
                <xsl:if test="node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
                    <ul>
                        <xsl:apply-templates select="node" />
                    </ul>
                </xsl:if>
            </li>
        </xsl:template>
    
        <!-- Don't output these -->
        <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" />
    
    </xsl:stylesheet>

     

    /Chriztian

  • Nicky Christensen 19 posts 40 karma points
    Dec 10, 2009 @ 09:03
    Nicky Christensen
    0

    Hey Chriztian...

    Thx alot, just what i needed :)

Please Sign in or register to post replies

Write your reply to:

Draft