This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Breaking up is hard to do.
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: Breaking up is hard to do.
- From: "Steve Muench" <smuench at us dot oracle dot com>
- Date: Sat, 19 Feb 2000 22:18:00 -0800
- References: <91023B9A71E1D311B3910050049D57D50E62@rksrv1.redknee.com>
- Reply-To: xsl-list at mulberrytech dot com
|
| I am unable to generate a </tr><tr> in my output.
|
Here's a simple way to do it that works like
your brain might be thinking. It depends
on using the:
<xsl:text disable-output-escaping="yes">
to *force* text into the result without being
quoted by the processor. In this case the text
you want to force into the result is:
</tr><tr>
at the strategic point when you hit your threshold
of maximum number of columns.
Given the input document of:
<data>
<field>1</field>
<field>2</field>
<field>3</field>
<field>4</field>
<field>5</field>
<field>6</field>
<field>7</field>
<field>8</field>
<field>9</field>
<field>10</field>
</data>
The stylesheet below (which is parameterized
to allow specifying the max number of columns
for the current "run") gives output like:
<html>
<body>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>10</td>
</tr>
</table>
</body>
</html>
===============[ cut ]===================
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="max" select="number(3)"/>
<xsl:template match="/">
<html><body><xsl:apply-templates/></body></html>
</xsl:template>
<xsl:template match="data">
<table>
<tr>
<xsl:for-each select="field">
<td><xsl:apply-templates/></td>
<xsl:if test="position() mod $max = 0 and position()!=last()">
<xsl:text disable-output-escaping="yes"><![CDATA[</tr><tr>]]></xsl:text>
</xsl:if>
</xsl:for-each>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
_________________________________________________________
Steve Muench, Consulting Product Manager & XML Evangelist
Business Components for Java Development Team
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list