Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Jun 20, 2014 @ 18:20
    Paul Griffiths
    0

    How to apply a class to the last nav item using xslt

    Hi all,

    My main navigation uses a divider on the right and i would like to remove this on the last item and im wondering how to apply a class the the last nav item please.

    Here is my code

    <nav>
            <!--<h2 class="hidden">Main Navigation</h2>-->
    <ul>
         <li>
             <a title="home" href="/">
              <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">selected</xsl:attribute>
             </xsl:if>
             <span>home</span></a>
           </li>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
    
                    <xsl:attribute name="class">selected</xsl:attribute>
                </xsl:if>
                <span><xsl:value-of select="@nodeName"/></span>
            </a>
        </li>
    </xsl:for-each>
    </ul>
        </nav>
    

    Where do i neeed to apply the test and the attribute?

    Thanks

    Paul

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 20, 2014 @ 23:50
    Chriztian Steinmeier
    100

    Hi Paul,

    I'd put it on the last <li> - you can easily target the <a> inside it, with CSS, if the styles are to be applied to the link, and you don't have to react to more than one thing...

    Like this (I'm throwing the class last-one on here):

    <nav>
        <!--<h2 class="hidden">Main Navigation</h2>-->
        <ul>
            <li>
                <a title="home" href="/">
                    <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                        <xsl:attribute name="class">selected</xsl:attribute>
                    </xsl:if>
                    <span>home</span>
                </a>
            </li>
            <xsl:variable name="topNode" select="$currentPage/ancestor-or-self::*[@level = $level]" />
            <xsl:for-each select="$topNode/*[@isDoc][not(umbracoNaviHide = 1)]">
                <li>
                    <xsl:if test="position() = last()">
                        <xsl:attribute name="class">last-one</xsl:attribute>
                    </xsl:if>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:if test="@id = $currentPage/ancestor-or-self::*/@id">
                            <xsl:attribute name="class">selected</xsl:attribute>
                        </xsl:if>
                        <span><xsl:value-of select="@nodeName"/></span>
                    </a>
                </li>
            </xsl:for-each>
        </ul>
    </nav>
    

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Jun 21, 2014 @ 11:06
    Paul Griffiths
    0

    Hi Chriztian,

    As always mate spot on! PROBLEM SOLVED :)

    Thanks for your help mate.

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft