Row-Of-4

Last change 25/04/2014

Take a xml with loads items, and you want to display it - 4 in a row - in a table. This neat snippet does exactly that.
This template takes the problem of having 4 cells in a row even one step further. Beause it makes sure that each cell can contain loads of logic if needed and still keep it simple:...
<table>
    <xsl:apply-templates select="/root/folder" mode="RowOf4"/>
</table>
...

<xsl:template match="*" mode="RowOf4">
    <xsl:if test="count(preceding-sibling::*[name() = 'folder']) mod 4 = 0">
        <tr>
            <td width="25%">
                <xsl:apply-templates select="."/><span/>
            </td>
            <td width="25%">
                <xsl:apply-templates select="following-sibling::*[(position()=1) and (name() = 'folder') ]"/><span/>
            </td>
            <td width="25%">
                <xsl:apply-templates select="following-sibling::*[(position()=2) and (name() = 'folder')]"/><span/>
            </td>
            <td width="25%">
                <xsl:apply-templates select="following-sibling::*[(position()=3) and (name() = 'folder')]"/><span/>
            </td>
        </tr>
    </xsl:if>
</xsl:template>



Site created with Corinis CCM