Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 343 karma points
    Nov 11, 2014 @ 15:13
    Tom Cowling
    0

    apply class child nodes

    Hi,

    I'm attempting to create a menu structure that I can manipulate using jquery. I'm ver nearly there, but just need (I guess) an if statement to test whether the current node has children, if it does, tag it with a class "has sub".

    My code so far:

    <?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:Examine="urn:Examine"
    exclude-result-prefixes="msxml umbraco.library Examine ">

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="maxLevelForMenu" select="3"/>

    <xsl:template match="/">

    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
    </xsl:call-template>
    </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(showInMenu) = '1' and @level &lt;= $maxLevelForMenu]">
    <li>
    <xsl:if test="$currentPage/@id = current()/@id">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    <xsl:if test="count(./* [@level &lt;= $maxLevelForMenu]) &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:stylesheet>

     

    Any help would be much appreciated!

     

    Thanks,

    Tom

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 11, 2014 @ 15:24
    Chriztian Steinmeier
    1

    Hi Tom,

    Have a look at my answer here for a better (in XSLT terms) way of approaching navigation. (The "drawNodes"-approach hasn't really got anything to do with XSLT - it's much more more akin to C# or PHP :-)

    To check whether the current node has any children, you can do this:

    <xsl:if test="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
        <!-- do stuff -->
    </xsl:if>
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft