Copied to clipboard

Flag this post as spam?

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


  • Sam 184 posts 209 karma points
    Jan 29, 2011 @ 21:18
    Sam
    0

    Creating navigation with incremental class name

    Hi everyone,

    Could anyone give a run through of how to do this vis xslt?

    For example, if I wanted to output:

    <ul>

    <li class="menuItem1"><a href="#">link</a></li>

    <li class="menuItem2"><a href="#">link</a></li>

    <li class="menuItem3"><a href="#">link</a></li>

    <li class="menuItem4"><a href="#">link</a></li>

    </ul>

    Just so I can do something a bit different with the css on my menu I need different classes on each :)

    This is my menu here, my site only has two levels (so far...) so this works fine for me, apart from not having different classes:

    <ul>

     
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=1]/* [@isDoc and string(umbracoNaviHide) != '1']">

      <li>

    <xsl:if test="$currentPage/@id = current()/@id">
                <xsl:attribute name="class">
                    <xsl:value-of select="'current'"/>
                </xsl:attribute>              
    </xsl:if>

    <xsl:if test="@id = $currentPage/parent::* /@id">
                <xsl:attribute name="class">
                    <xsl:value-of select="'parent'"/>
                </xsl:attribute>              
    </xsl:if>

        <a href="{umbraco.library:NiceUrl(@id)}"><span><xsl:value-of select="@nodeName"/></span></a>
      </li>
    </xsl:for-each>

    </ul>

    Thanks.

    Sam.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 29, 2011 @ 22:16
    Kim Andersen
    2

    Hi Sam

    If you want to insert a number that increases on each li-element, you can use the position() like this:

    <xsl:attribute name="class">
    <xsl:text>menuItem </xsl:text><xsl:value-of select="position()" />
    </xsl:attribute>

    /Kim A

  • Sam 184 posts 209 karma points
    Jan 30, 2011 @ 14:48
    Sam
    0

    Thanks Kim. that's perfect :).

    Sam.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 30, 2011 @ 15:17
    Kim Andersen
    0

    Great to hear Sam. And you are very welcome :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft