Copied to clipboard

Flag this post as spam?

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


  • Rik Hodiamont 56 posts 156 karma points
    Apr 29, 2011 @ 10:11
    Rik Hodiamont
    0

    Different classes in Main Navigation

    Hi,

    I'am new to Xslt and I have a problem. I have made an menu (with the sitemap template).

    You see the menu above. The five buttons are generated from the level 2 nodes and the position defines the class of the button. With a mouse over (jQuery) the submenu shows. The items in de submenu are also automaticly generated. Now the problem.

    I want that button 1 gives me an yellow submenu, button2 orange etc. How can i do that? I paste my xlst in this topic.

    Any help would be appreciated.

    Thanks in advance.

    Rik

    <?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"/>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="4"/>

    <xsl:template match="/">
    <div id="mainNav">
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/> 
    </xsl:call-template>
    </div>
    </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 id="jsddm">






    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">
    <li>

    <!--level 2 is het level waarin de algemene knoppen zitten-->
    <xsl:if test="position() = '1' and @level='2'">
    <a class="nav_menuitem_1" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:if>
    <xsl:if test="position() = '2' and @level='2'">
    <a class="nav_menuitem_2" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:if>
    <xsl:if test="position() = '3' and @level='2'">
    <a class="nav_menuitem_3" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:if>
    <xsl:if test="position() = '4' and @level='2'">
    <a class="nav_menuitem_4" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:if>
    <xsl:if test="position() = '5' and @level='2'">
    <a class="nav_menuitem_5" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:if>

    <!--submenu item-->
    <!--dit moet geen extra class bevatten-->
    <xsl:if test="@level = '3'">
    <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/>
    <xsl:value-of select="@parentID"/>

    </a>
    </xsl:if>


     <!--dit gedeelte zorgt voor submenu-->
    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">  
    <xsl:call-template name="drawNodes">   
    <xsl:with-param name="parent" select="."/>   
    </xsl:call-template> 
    </xsl:if>
    <!--einde gedeelte  dat zorgt voor submenu-->


     
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

  • Rik Hodiamont 56 posts 156 karma points
    Apr 30, 2011 @ 16:35
    Rik Hodiamont
    0

    I'am a little bit further to the solution.

    Mayby you could help me with the last bit. Can I use an If-statement to find out if the level 3 items belongs under the level 2 item at the first position?

    So if the current sub items belongs to the first item in level 2 then class = ...

    Thanks in advance.

  • Lennart Stoop 304 posts 842 karma points
    Apr 30, 2011 @ 16:59
    Lennart Stoop
    1

    Hi Rik,

    One way of doing this would be to test if the parent does not have any preceding siblings, for example:

    <xsl:if test="count($currentPage/parent::*/preceding-sibling::*) = 0">
      Parent does not have any preceding siblings
    </xsl:if>

    Hope this helps :-)

  • Rik Hodiamont 56 posts 156 karma points
    May 01, 2011 @ 14:01
    Rik Hodiamont
    0

    Thanks Lennart. That works!!

  • 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