This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: dynamic HTML table generation
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: dynamic HTML table generation
- From: Kay Michael <Michael dot Kay at icl dot com>
- Date: Fri, 6 Oct 2000 09:14:52 +0100
- Reply-To: xsl-list at mulberrytech dot com
The usual solution for grouping into tables relies on something like
<xsl:template match="item[position() mod 5 = 1]"/>
Variables aren't allowed in the match pattern of a template rule, so you
can't parameterise this. So you need a different approach. But the same
logic can easily be translated to xsl:for-each.
<xsl:param name="cols" select="5"/>
<xsl:template match="rs:data"/>
<table>
<xsl:for-each select="z:row[position() mod $cols = 1]">
<tr>
<xsl:for-each select=".|following-sibling::z:row[position() <
$cols]">
<td><xsl:value-of select="@product_id"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
Mike Kay
> -----Original Message-----
> From: Ireney Berezniak [mailto:iberezniak@usa.net]
> Sent: 05 October 2000 20:18
> To: xsl-list@mulberrytech.com
> Subject: dynamic HTML table generation
>
>
> Hi,
>
> I have a problem and so far I have been unsuccessful finding
> a solution. Any
> help you guys could provide would be greatly appreciated.
>
> I need to format and create an HTML result set table dynamically.
> For example, in one instance I have a resultset in XML that
> contains 10
> records. I need to have an XSL file which generates a table
> with 2 rows and 5
> columns. In another instance, I might have a resultset that
> contains 20
> records, and I need to present it in a 5 row by 4 column
> table using the same
> XSL file. I really want to do this dynamically. I can pass
> the desired row and
> column count into XSLT file so I know how many rows and
> columns I need to
> create, but how do I do the looping to achieve this?
>
> Thanks!
>
> ib.
>
> xml sample:
> <rs:data>
> <z:row Product_Id="98652"/>
> <z:row Product_Id="98682"/>
> <z:row Product_Id="98718"/>
> <z:row Product_Id="104512"/>
> <z:row Product_Id="106564"/>
> <z:row Product_Id="174272"/>
> <z:row Product_Id="175242"/>
> <z:row Product_Id="191765"/>
> <z:row Product_Id="194131"/>
> <z:row Product_Id="194132"/>
> </rs:data>
>
> desired HTML table to be generated dynamically:
> <TABLE>
> <TR>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> <TD></TD>
> </TR>
> </TABLE>
>
> or (depending on the rows/columns required)
>
> <TABLE>
> <TR>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD></TD>
> <TD></TD>
> </TR>
> </TABLE>
>
>
> ____________________________________________________________________
> Get free email and a permanent address at http://www.amexmail.com/?A=1
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list