Hello
I'd like to generate a three column HTML table using XSLT.
For example if I have this XML:-
Code:
--------
<product>
<name>Product 1</name>
</product>
<product>
<name>Product 2</name>
</product>
<product>
<name>Product 3</name>
</product>
<product>
<name>Product 4</name>
</product>
<pro.... etc, etc, etc, etc
-----------
And I want to produce a three column table using something like this:-
----
Code:
<table>
<tr>
<td>Product 1</td>
<td>Product 2</td>
<td>Product 3</td>
</tr>
<tr>
<td>Product 4</td>
<td>etc, etc, etc
----
How would I go about this?
I've looked through the W3C XSLT & XPath specs and I can't see a way, but I'm sure there is one.
Presumably I need to do something like go through the product nodes, but go through three at once, then write the <td>s.
Kind of like this in pseudo code
Code:
for (i = 0; i < total_number_of_products; i = (i + 3)) {
echo '<tr>';
for (j = 0; j < 3; j++) {
echo '<td>' + product_name + '</td>';
}
echo '</tr>';
}
--- or ---
Code:
<table>
<xsl:for-each select="product">
<tr>
<xsl:for-each (of the products just selected)
<td><xsl:value-of select="name" /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
----
Hope this makes sense?
Any help would be much appreciated.
Thanks
Gareth