Subject: RE: creating html tables from cells
From: Americo Albuquerque <melinor@xxxxxxxx>
Date: Wed, 15 Oct 2003 22:22:22 +0100
|
Hi
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> Whitney, Dan (CanWest Interactive)
> Sent: Wednesday, October 15, 2003 4:06 PM
> To: 'mulberry - xsl'
> Subject: creating html tables from cells
>
>
> 2 questions.
>
(...)
>
> I'm wondering if there's an effecient way with xsl to
> transform it to: <table>
> <tr>
> <td>Row 1 - Column 1</td>
> <td>Row 1 - Column 2</td>
> <td>Row 1 - Column 3</td>
> <td>Row 1 - Column 4</td>
> </tr>
> <tr>
> <td>Row 2 - Column 1</td>
> <td>Row 2 - Column 2</td>
> <td>Row 2 - Column 3</td>
> <td>Row 2 - Column 4</td>
> </tr>
> </table>
>
> I know I have to somehow create the tr's on the RS element
> but I'm not at all sure how.
>
You can use keys to do this, though it might not be the best solution
for big files.
Check the comments in the code
Stylesheet:
<!-- set the key to look for the closest previous RI with @col=1 -->
<xsl:key match="RI" name="RI" use="generate-id((preceding-sibling::RI
| self::RI)[@col=1][last()])"/>
<xsl:template match="RS">
<table>
<!-- start only with RI the belong to the first column -->
<xsl:apply-templates mode="start" select="RI[@col=1]"/>
</table>
</xsl:template>
<xsl:template match="RI" mode="start">
<!-- for each one create a row -->
<tr>
<!-- then select the nodes until the next RI[@col=1] -->
<xsl:apply-templates select="key('RI',generate-id())"/>
</tr>
</xsl:template>
<xsl:template match="RI">
<!-- here you do whatever you want with the columns -->
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
Regards,
Americo Albuquerque
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|