Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie help with table rows and columns with a variable data set

Status
Not open for further replies.

spiel2001

Programmer
Nov 1, 2001
39
US
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 &quot;max-columns&quot; 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 &quot;max-columns&quot; each?

<Data>
<ImgGroup>
<Name value=&quot;Group 1&quot;/>
<Image>
<URI value=&quot;img1.gif&quot;/>
...
</Image>
<Image>
<URI value=&quot;img2.gif&quot;/>
...
</Image>
...
</ImgGroup>
<ImgGroup>
<Name value=&quot;Group 2&quot;/>
<Image>
<URI value=&quot;imgA.gif&quot;/>
...
</Image>
...
</ImgGroup>
...
</Data>

<xsl:variable name=&quot;max-columns&quot; value=&quot;8&quot;/>

<xsl:template match=&quot;/&quot;>
...
<xsl:for-each select=&quot;/Data/ImgGroup&quot;>
<xsl:sort select=&quot;Name/@value&quot;/>
<xsl:call-template name=&quot;group-table&quot;/>
</xsl:for-each>
...
</xsl:template>

<xsl:template name=&quot;group-table&quot;>
<table yadda yadda yadda>
<tr>
<td><xsl:attribute name=&quot;colspan&quot;><xsl:value-of
select=&quot;$max-columns&quot;/></xsl:attribute><div
align=&quot;center&quot;><xsl:value-of select=&quot;Name/@value&quot;/>
</div></td>
</tr>
<xsl:for-each select=&quot;Image&quot;>
<xsl:sort select=&quot;Name/@value&quot;/>
<xsl:call-template name=&quot;table-cell&quot;/>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template name=&quot;table-cell&quot;>
<td width=&quot;100&quot; height=&quot;100&quot;>
<img width=&quot;65&quot; height=&quot;65&quot;><xsl:attribute
name=&quot;src&quot;><xsl:value-of
select=&quot;URI&quot;/></xsl:attribute></img>
</td>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top