Elad Lachmi
Elad Lachmi

Reputation: 10561

Add class to every third element

Im using XSLT to build a list of select products. They are shown in rows of three. I want to add a class to the right most (third) box in each row to remove the right margin. Any ideas how I can do this? Im really new to XSLT.

Upvotes: 1

Views: 379

Answers (1)

Elad Lachmi
Elad Lachmi

Reputation: 10561

Here is a solution I got from the Umbraco forum. Can't take credit for it, but I'm posting it for future reference.

<xsl:for-each select="$currentPage/child::* [@isDoc]">
 <div class="something">
  <xsl:if test="position() mod 3 = 0">
    <xsl:attribute name="class">something someotherclass</xsl:attribute>
  </xsl:if>
  Content of div
 </div>
</xsl:for-each>

Upvotes: 1

Related Questions