Copied to clipboard

Flag this post as spam?

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


  • Henrik Bøgelund Lavstsen 8 posts 39 karma points
    Apr 14, 2010 @ 09:04
    Henrik Bøgelund Lavstsen
    0

    table with alternate rows

    Hi there

    i have made a foreach loop in xslt that works, the thing is that i want every second <tr> to have a class name.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Apr 14, 2010 @ 09:09
    Thomas Höhler
    0

    Try something like this:

    <xsl:if test="position() mod 2 = 1">
    <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>

    hth, Thomas

  • Kim Andersen 1447 posts 2197 karma points MVP
    Apr 14, 2010 @ 09:09
    Kim Andersen
    0

    Hi Henrik you can do it with something like this:

    <xsl:for-each select="something...">
    <tr>
    <xsl:attribute name="class">
    <xsl:choose>
    <xsl:when test="position() mod 2 = 1">altRow</xsl:when>
    <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    <td>
    tralala...
    </td>
    </tr>
    </xsl:for-each>

    This is from the top of my head, so please take a minute to see if anything is wrong. But something like that should work.

    /Kim A

  • Kim Andersen 1447 posts 2197 karma points MVP
    Apr 14, 2010 @ 09:21
    Kim Andersen
    1

    By the way, you could also do this with jQuery if you prefer that.

    $("tr:has(td):even").addClass("evenRow");
    $("tr:has(td):odd").addClass("oddRow");

    This would get all of your <tr>'s that contains one or more <td>'s (which mean that a <tr> that includes your <th>'s wouldn't be selected), and give the even rows a class of evenRow, and the odd rows would get a class of oddRow.

    Just another approach.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft