Subject: Re: Arbitrarily breaking up a table From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 11 Sep 2000 18:28:42 +0200 (MET DST) |
> 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() >= 1 and position() <= 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() >= 1 and position() <= 5]" /> </table> Table 2: <table> <xsl:apply-templates select="preceding-sibling::HEADERROW" /> <xsl:apply-templates select="DATAROW[position() >= 6 and position() <= 7]" /> </table> Table 3: <table> <xsl:apply-templates select="preceding-sibling::HEADERROW" /> <xsl:apply-templates select="DATAROW[position() >= 8 and position() <= 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Arbitrarily breaking up a table, Linus-Lin | Thread | More problems and questions, anilia bruho |
document production options, Francis Norton | Date | RE: XSLT 2.0 Idea: third argument f, Jeni Tennison |
Month |