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

Re: Arbitrarily breaking up a table

Subject: Re: Arbitrarily breaking up a table
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Sep 2000 18:28:42 +0200 (MET DST)
datarow position
> I have the following structure
> <TABLE>
>   <HEADERROW>
> 	<HEADER>a</HEADER> <HEADER>b</HEADER> <HEADER>c</HEADER>
>   </HEADERROW>
>   <DATAROWS>	
>      <DATAROW>
> 	<DATA>1</DATA> <DATA>1</DATA> <DATA>1</DATA>
>      </DATAROW>
>      <DATAROW>
> 	<DATA>2</DATA> <DATA>2</DATA> <DATA>2</DATA>
>      </DATAROW>
... [snip]
>   </DATAROWS>
> </TABLE>
> 
> Normally a bunch of applied templates could easily create one table with 9
> rows. 
> 
> What I need is to generate three tables from the same XML each with its own
> table header.
> 
> First table would (arbitrarily) have 5 consective rows (rows 1-5).
> Second table would have 2 consecutive rows (6-7).
> Third table would have 2 consective rows (8-9).

The trick is to select the rows you want to process with an XPath
expression using the context position of each row.
E.g. the first table should contain all the rows that have a position
greater or equal 1 and lower or equal 5:
      <xsl:apply-templates select="DATAROW[position() &gt;= 1 and
                                           position() &lt;= 5]" />

Now you have to take care to create the table headers at the appropriate
position in your stylesheet: first skip them, but afterwards process them
explicitly. 

I hope the following complete stylesheet shows what I shortly tried to
explain:

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="TABLE">
   <!-- skip HEADERROW -->
   <xsl:apply-templates select="DATAROWS" />
</xsl:template>

<xsl:template match="DATAROWS">
   Table 1:
   <table>
      <xsl:apply-templates select="preceding-sibling::HEADERROW" />
      <xsl:apply-templates select="DATAROW[position() &gt;= 1 and
                                           position() &lt;= 5]" />
   </table>
   Table 2:
   <table>
      <xsl:apply-templates select="preceding-sibling::HEADERROW" />
      <xsl:apply-templates select="DATAROW[position() &gt;= 6 and
                                           position() &lt;= 7]" />
   </table>
   Table 3:
   <table>
      <xsl:apply-templates select="preceding-sibling::HEADERROW" />
      <xsl:apply-templates select="DATAROW[position() &gt;= 8 and
                                           position() &lt;= 9]" />
   </table>
</xsl:template>

<xsl:template match="HEADERROW | DATAROW">
   <tr><xsl:apply-templates /></tr>
</xsl:template>

<xsl:template match="HEADER">
   <th><xsl:value-of select="."/></th>
</xsl:template>

<xsl:template match="DATA">
   <td><xsl:value-of select="."/></td>
</xsl:template>

</xsl:stylesheet>


Best regards,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.