PDA

View Full Version : XSL for each split data in groups



erilidon
08 Feb 2012, 09:31 PM
say I have an xml file like this:


<xml>
<data>
<img>
<url>1.jpg</url>
<name>1</name>
<desc>Picture 1</desc>
</img>
<img>
<url>2.jpg</url>
<name>2</name>
<desc>Picture 2</desc>
</img>
<img>
<url>3.jpg</url>
<name>3</name>
<desc>Picture 3</desc>
</img>
<img>...
</data>

And so on with several pictures upwards of 50 or so.

and I want to use an xsl stylesheet to pull the data into a table. The output should be something like this:


<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
</table>

I know how to


<table>
<xsl:for-each select="data/img">
<tr>
<td><xsl:value-of select="name"/></td>
</tr>
</table>

but how do I get it to split the data into the table row every 3 or so images?

Thanks.