[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to take a node set and convert it into a table

Subject: Re: 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
node set convert
On 12/12/06, David Carlisle <davidc@xxxxxxxxx> 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>&#10;</xsl:text>
        <tr>
          <xsl:for-each select=".|following-sibling::node[position() &lt; 5]">
            <td><xsl:value-of select="concat(@name,':',.)"/></td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
      <xsl:text>&#10;</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>&#10;</xsl:text>
      <tr>
        <xsl:for-each select=".|following-sibling::node[position() &lt; 5]">
          <td><xsl:value-of select="concat(@name,':',.)"/></td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>
  </table>
</xsl:template>

Output:
   <table>
     <tr>
       <td>a:1</td>
     </tr>
     <tr>
       <td>f:6</td>
     </tr>
   </table>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.