Copied to clipboard

Flag this post as spam?

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


  • Ron Brouwer 273 posts 768 karma points
    Jul 28, 2009 @ 12:34
    Ron Brouwer
    1

    Classes for first and last item

    Seems nice,

    Have not tried it yet but it would be nice to have additional classes for the first and last item.

    Ron

  • Kyle Skrinak 272 posts 327 karma points
    Jul 28, 2009 @ 13:30
    Kyle Skrinak
    0

    If umbraco doesn't have that; it should: +1

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jul 28, 2009 @ 13:57
    Darren Ferguson
    0

    How do you mean? If listing items with xslt you just use the position() and count() functions to determine your position in an iteration.....

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jul 28, 2009 @ 14:18
    Douglas Robar
    4

    As Darren says, it's a simple thing to do in xslt using the position() and last() functions.  I prefer last() but you could certainly use count() if you prefer.

    The basic idea would be something like this...

    <ul>
    <xsl:for-each select="_something_here_">
        <li>
            <xsl:choose>
                <xsl:when test="position() = 1">
                    <xsl:attribute name="class">first</xsl:attribute>
                </xsl:when>
                <xsl:when test="position() = last()">
                    <xsl:attribute name="class">last</xsl:attribute>
                </xsl:when>
            </xsl:choose>
            <xsl:value-of select="@nodeName" />
        </li>
    </xsl:for-each>
    </ul>

     

    The output for a loop of four items would be something like this...

    <ul>
        <li class="first">item 1</li>
        <li>item 2</li>
        <li>item 3</li>
        <li class="last">item 4</li>
    </ul>

    cheers,
    doug.

  • Kyle Skrinak 272 posts 327 karma points
    Jul 28, 2009 @ 15:16
    Kyle Skrinak
    0

    Cool -- thanks for the tip -- just another square-peg php-approach to this elegant solution. I retract my +1.

Please Sign in or register to post replies

Write your reply to:

Draft