Subject: Re: [xsl] Interesting Table loop From: Spencer Tickner <spencertickner@xxxxxxxxx> Date: Thu, 9 Jun 2005 16:02:30 -0700 |
Hi Jay, Thanks for the post. The code's poetry. i can see I'm going to have to do a little work with the colspans and empty cells but other than that, worked like a charm. Great Post!, Spencer On 6/9/05, JBryant@xxxxxxxxx <JBryant@xxxxxxxxx> wrote: > Hi, Spencer, > > How about: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="html" omit-xml-declaration="no" indent="yes"/> > > <xsl:template match="/"> > <html> > <body> > <xsl:apply-templates/> > </body> > </html> > </xsl:template> > > <xsl:template match="Table"> > <table border="1"> > <!-- Make the header row --> > <tr> > <xsl:for-each select="Cell[qp_table_numeric_head]"> > <xsl:apply-templates select="."/> > </xsl:for-each> > </tr> > <!-- Make the body rows --> > <xsl:for-each-group > select="Cell[qp_table_numeric_body]|Cell[qp_table_numeric_data]" > group-starting-with="Cell[qp_table_numeric_body]"> > <tr> > <xsl:apply-templates select="current-group()/self::*"/> > </tr> > </xsl:for-each-group> > <!-- Make the footnote --> > <tr> > <xsl:for-each select="Cell[qp_table_numeric_footnote]"> > <xsl:apply-templates select="."/> > </xsl:for-each> > </tr> > </table> > </xsl:template> > > <xsl:template match="Cell[qp_table_numeric_head]"> > <th> > <xsl:apply-templates/> > </th> > </xsl:template> > > <xsl:template > match="Cell[qp_table_numeric_body]|Cell[qp_table_numeric_data]"> > <td> > <xsl:apply-templates/> > </td> > </xsl:template> > > <xsl:template match="Cell[qp_table_numeric_footnote]"> > <td colspan="{@ccols}"> > <xsl:apply-templates/> > </td> > </xsl:template> > > <xsl:template > match="qp_table_numeric_head|qp_table_numeric_body|qp_table_numeric_data|qp_t able_numeric_footnote"> > <xsl:value-of select="."/> > </xsl:template> > > </xsl:stylesheet> > > I assumed that the only thing that actually spanned columns would be > footnotes. I bet you can add spanning if you need to, though. Also, this > will break if the first data value in each row is not a > qp_table_numeric_body node. > > To test this, I extended your data set to have two body rows and ran it > through Saxon 8.4. I got what I expected. (Minor issue: You might want to > fiddle with normalize-space a bit, as this stylesheet inserts spaces and > linebreaks quite a bit - a consequence of trying to make a readable > stylesheet.) > > I love for-each-group. > > Jay Bryant > Bryant Communication Services > (presently consulting at Synergistic Solution Technologies) > > > > Spencer Tickner <spencertickner@xxxxxxxxx> > 06/09/2005 04:33 PM > Please respond to > xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > > To > xsl-list@xxxxxxxxxxxxxxxxxxxxxx > cc > > Subject > [xsl] Interesting Table loop > > > > > > > Hi everyone, > > Thanks in advance for the help. I have a table comming out of another > program, I have to turn it into a html table. Using xslt 2.0. > > So far I have tried recursively calling 2 templates representing the > rows and column counts of tables. Of course, because these have no > reference to the original table (there is more than 1 in each > document), I cannot acurately grab the content. Here is the xml: > > <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" > aid:table="table" aid:trows="3" aid:tcols="7"> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" > aid:ccolwidth="192"> > > <qp_table_numeric_head>Performance Measure</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_head>2001/02Actual</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_head>2002/03Actual</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_head>2003/04Actual</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_head>2004/05Target</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_head>2004/05Actual</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > <qp_table_numeric_head>2004/05 > Variance</qp_table_numeric_head> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" > aid:ccolwidth="192"> > > <qp_table_numeric_body>2.2Percentage of total > caseload.</qp_table_numeric_body> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" > aid:ccolwidth="50"> > > <qp_table_numeric_data>28.4%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > <qp_table_numeric_data>35.4%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > > <qp_table_numeric_data>43.3%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" > aid:ccolwidth="50"> > > <qp_table_numeric_data>46.0%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > <qp_table_numeric_data>49.8%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="50"> > > <qp_table_numeric_data>+3.8%</qp_table_numeric_data> > </Cell> > > <Cell aid:table="cell" aid:crows="1" aid:ccols="7"> > <qp_table_numeric_footnote>Source: Planning.</qp_table_numeric_footnote> > </Cell> > > </Table> > > > So I here's the pseudo xslt I figure should make the table. > > <xsl:template match="table"/> > <!-- Loop until you get to the end of @aid:trows --> > <tr> > <!-- Loop until you get to the end of @aid:tcols --> > <td><xsl:apply-templates select="Cell"/></td> > <!-- End col loop --> > </tr> > <!-- End row loop --> > </xsl:template> > > I'm kinda perplexed by how to do this, any suggestions, or if another > way jumps out at you, I'd be very gratefull for the advice. As a side > note, @aid:ccols in the Cell attribute seem to represent colspan. > > Spencer
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Interesting Table loop, JBryant | Thread | [xsl] DocBook <imagedata/> and scal, David Nedrow |
Re: [xsl] Interesting Table loop, JBryant | Date | [xsl] DocBook <imagedata/> and scal, David Nedrow |
Month |