Thursday, October 18, 2012

Mod operator to control Table Rows in XSL


The Mod operator returns the remainder left after division is performed. If you have a table and you need to have a certain amounts of columns before another row is created, use the mod operator.

The following example will create a new row after 3 columns are created.

<xsl:if test="position() mod 3 = 1">
<xsl:text disable-output-escaping="yes"><![CDATA[ <tr> ]]></xsl:text>
</xsl:if>
   <td valign="top">
    <img alt="" src="{@ImgURL}"/>
    <xsl:call-template name="dvt_2" />
   </td>
<xsl:if test="position() mod 3 = 3">
<xsl:text disable-output-escaping="yes"><![CDATA[ </tr> ]]></xsl:text>
</xsl:if>

No comments:

Post a Comment