[xsl] Transforming Tables

Subject: [xsl] Transforming Tables
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Thu, 04 May 2006 13:19:15 +0800
Good day!

I'm transforming a table xml into a InDesign tagged text table and i'm
having a problem when it comes to spanning. In InDesign tagged text a
cell is constructed this way: <clStart:x,y>data<clEnd:>, x is the number
of rows and y the number columns occupied by the cell. However, if the
table has 5 columns then each row must have 5 cell entries as well
regardless if there exist a cell the spans the rest of the column or a
previous cell that spans the row position.

So if you have a table xml like this:
<table row="4" col="5">
<row>
<cell col="1">Data</cell>
<cell col="2" colspan="3">Data</cell>
<cell col="5">Data</cell>
</row>
<row>
<cell col="1" rowspan="3">Data</cell>
<cell col="2">Data</cell>
<cell col="3">Data</cell>
<cell col="4">Data</cell>
<cell col="5">Data</cell>
</row>
<row>
<cell col="2" rowspan="2">Data</cell>
<cell col="3">Data</cell>
<cell col="4">Data</cell>
<cell col="5">Data</cell>
</row>
<row>
<cell col="3">Data</cell>
<cell col="4">Data</cell>
<cell col="5">Data</cell>
</row>
</table>

You should have a InDesign tagged text like this:
<tStart:4,12>
<rStart:>
<cStart:1,1>Data<cEnd:>
<cStart:1,3>Data<cEnd:>
<cStart:1,1><cEnd:>
<cStart:1,1><cEnd:>
<cStart:1,1>Data<cEnd:>
<rEnd:>
<rStart:>
<cStart:3,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<rEnd:>
<rStart:>
<cStart:1,1><cEnd:>
<cStart:2,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
</row>
<rEnd:>
<cStart:1,1><cEnd:>
<cStart:1,1><cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<cStart:1,1>Data<cEnd:>
<rEnd:>
<tEnd:>

I can get my xslt to handle column spanning, but i'm having trouble with
rowspanning. Here is my template for the cell element:
<xsl:template match="cell">
<xsl:variable name="col" select="if (exists(@colspan) then @colspan else
1)"/>
<xsl:variable name="row" select="if (exists(@rowspan) then @rowspan else
1)"/>
<xsl:value-of select="concat('<cStart:',$row,',',$col,'>')"/>
<xsl:apply-templates/>
<xsl:value-of select="'<cEnd:'"/>
<xsl:if test="exists(@colspan)">
<xsl:value-of select="for $x in (1 to @colspan-1) return
'<cStart:1,1><cEnd:>'"/>
</xsl:if>
</xsl:template>

Can someone help me with generating the empty cells for row spanning?

Thanks,
Jeff

Current Thread