|
Subject: Re: [xsl] How to take a node set and convert it into a table view From: "Sam Carleton" <scarleton@xxxxxxxxxxxxxxxx> Date: Fri, 15 Dec 2006 12:45:49 -0500 |
> 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>
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>| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How to take a node set an, David Carlisle | Thread | Re: [xsl] How to take a node set an, David Carlisle |
| Re: [xsl] XSLT WYSIWYG WEB Editor, Wendell Piez | Date | Re: [xsl] How to take a node set an, David Carlisle |
| Month |