DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

XSLT Alternating Colors For HTML Table Rows

04.11.2005
| 15948 views |
  • submit to reddit
        This attaches a style attribute to the tr tag, but only on every other tag.

<xsl:template match="my_repeating_item">
<tr>
  <xsl:if test="position() mod 2 != 1">
    <xsl:attribute  name="style">background-color:#dddddd</xsl:attribute>
  </xsl:if>
  <xsl:apply-templates/>
</tr>
<xsl:template>