This question may seem a bit naive, but it's is really troubling me. I have a data set made up of N groups of some number of images where each group will contain an unknown number of images. I need to arrange those images into tables, using a separate table for each group and then break the images up into rows based on the number of columns in the table.
OK... so I can use a template for the group and have the group template call another template for each cell in the table (snippet below).
What I am uncertain of is: If I need "max-columns" maximum per table, how can I control when and where to insert the <TR> and </TR> HTML tags needed to break the individual cells up into table rows of "max-columns" each?
<Data>
<ImgGroup>
<Name value="Group 1"/>
<Image>
<URI value="img1.gif"/>
...
</Image>
<Image>
<URI value="img2.gif"/>
...
</Image>
...
</ImgGroup>
<ImgGroup>
<Name value="Group 2"/>
<Image>
<URI value="imgA.gif"/>
...
</Image>
...
</ImgGroup>
...
</Data>
<xsl:variable name="max-columns" value="8"/>
<xsl:template match="/">
...
<xsl:for-each select="/Data/ImgGroup">
<xsl:sort select="Name/@value"/>
<xsl:call-template name="group-table"/>
</xsl:for-each>
...
</xsl:template>
<xsl:template name="group-table">
<table yadda yadda yadda>
<tr>
<td><xsl:attribute name="colspan"><xsl:value-of
select="$max-columns"/></xsl:attribute><div
align="center"><xsl:value-of select="Name/@value"/>
</div></td>
</tr>
<xsl:for-each select="Image">
<xsl:sort select="Name/@value"/>
<xsl:call-template name="table-cell"/>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="table-cell">
<td width="100" height="100">
<img width="65" height="65"><xsl:attribute
name="src"><xsl:value-of
select="URI"/></xsl:attribute></img>
</td>
</xsl:template>
OK... so I can use a template for the group and have the group template call another template for each cell in the table (snippet below).
What I am uncertain of is: If I need "max-columns" maximum per table, how can I control when and where to insert the <TR> and </TR> HTML tags needed to break the individual cells up into table rows of "max-columns" each?
<Data>
<ImgGroup>
<Name value="Group 1"/>
<Image>
<URI value="img1.gif"/>
...
</Image>
<Image>
<URI value="img2.gif"/>
...
</Image>
...
</ImgGroup>
<ImgGroup>
<Name value="Group 2"/>
<Image>
<URI value="imgA.gif"/>
...
</Image>
...
</ImgGroup>
...
</Data>
<xsl:variable name="max-columns" value="8"/>
<xsl:template match="/">
...
<xsl:for-each select="/Data/ImgGroup">
<xsl:sort select="Name/@value"/>
<xsl:call-template name="group-table"/>
</xsl:for-each>
...
</xsl:template>
<xsl:template name="group-table">
<table yadda yadda yadda>
<tr>
<td><xsl:attribute name="colspan"><xsl:value-of
select="$max-columns"/></xsl:attribute><div
align="center"><xsl:value-of select="Name/@value"/>
</div></td>
</tr>
<xsl:for-each select="Image">
<xsl:sort select="Name/@value"/>
<xsl:call-template name="table-cell"/>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="table-cell">
<td width="100" height="100">
<img width="65" height="65"><xsl:attribute
name="src"><xsl:value-of
select="URI"/></xsl:attribute></img>
</td>
</xsl:template>