On 12/12/06, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:
> how do I make a table that looks like this:
>
> a:1 b:2 c:3 d:4 e:5
> f:6 g:7 h:8 i:9 j:10
>
> In other words, a 5x2 table.
The following will handle any number of rows:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="nodes">
<table>
<xsl:for-each select="node[position() mod 5 =1]">
<xsl:text> </xsl:text>
<tr>
<xsl:for-each select=".|following-sibling::node[position() < 5]">
<td><xsl:value-of select="concat(@name,':',.)"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
<xsl:text> </xsl:text>
</table>
</xsl:template>
</xsl:stylesheet>
$ saxon node.xml node.xsl
<?xml version="1.0" encoding="utf-8"?><table>
<tr><td>a:1</td><td>b:2</td><td>c:3</td><td>d:4</td><td>e:5</td></tr>
<tr><td>f:6</td><td>g:7</td><td>h:8</td><td>i:9</td><td>j:10</td></tr>
</table>
David,
I took your code and modified it just a little to what I am really
doing and it is only giving me one column tables:
XML:
<detailNVPSet>
<detailNVP name="a">1</detailNVP>
<detailNVP name="b">2</detailNVP>
<detailNVP name="c">3</detailNVP>
<detailNVP name="d">4</detailNVP>
<detailNVP name="e">5</detailNVP>
<detailNVP name="f">6</detailNVP>
<detailNVP name="g">7</detailNVP>
<detailNVP name="h">8</detailNVP>
<detailNVP name="i">9</detailNVP>
<detailNVP name="j">10</detailNVP>
</detailNVPSet>
XSLT:
<xsl:template match="detailNVPSet">
<table>
<xsl:for-each select="detailNVP[position() mod 5 =1]">
<xsl:text> </xsl:text>
<tr>
<xsl:for-each select=".|following-sibling::node[position() < 5]">
<td><xsl:value-of select="concat(@name,':',.)"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
<xsl:text> </xsl:text>
</table>
</xsl:template>
Output:
<table>
<tr>
<td>a:1</td>
</tr>
<tr>
<td>f:6</td>
</tr>
</table>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--