[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Thanks, this would work. I did try your suggestion of using the no of total columns and testing it with respect to the current position of the cell, and arrived at this templates:
<xsl:template match="cell">
<xsl:variable name="colname" select="@col"/>
<xsl:variable name="col" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(@colspan)">
<xsl:value-of select="number(@colspan)+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="row" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(@rowspan)">
<xsl:value-of select="number(@rowspan)+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="coldiff" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(preceding-sibling::cell[1]/@col)">
<xsl:value-of select="number(@col)-number(preceding-sibling::cell[1]/@col)-1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(@col)-1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$coldiff>=1">
<xsl:value-of select="for $a in (1 to $coldiff) return '<clStart:1,1><clEnd:>'" separator=""/>
</xsl:if>
<xsl:text disable-output-escaping="no"><clStart:</xsl:text>
<xsl:value-of select="concat($row,',',$col)"/>
<xsl:text disable-output-escaping="no">></xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="no"><clEnd:></xsl:text>
</xsl:template>
which is pretty long compared to your templates, so i think i'm gonna use your version (mine aint that efficient with so many variables and looping).
the 12 came from, my original source, i did not notice it. i shortened the table sample.
however, what if there are information in the spanning cell, like for example the rules, like <cell col='1' rowspan='2' rulebottom='1'> so that your empty cell marker would also reflect this information, like <clStart:1,1;rulebottom:1><clEnd:>. I think this would be more complicate, i'll be satisfied with what i have right now and just think about this when the situation arrives.
Again thanks!
-- Jeff Sese
David Carlisle wrote:
Re: [xsl] Transforming Tables - repost
Subject: Re: [xsl] Transforming Tables - repost From: Jeff Sese <jsese@xxxxxxxxxxxx> Date: Tue, 16 May 2006 19:27:55 +0800 |
Thanks, this would work. I did try your suggestion of using the no of total columns and testing it with respect to the current position of the cell, and arrived at this templates:
<xsl:template match="cell">
<xsl:variable name="colname" select="@col"/>
<xsl:variable name="col" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(@colspan)">
<xsl:value-of select="number(@colspan)+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="row" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(@rowspan)">
<xsl:value-of select="number(@rowspan)+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="coldiff" as="xs:integer">
<xsl:choose>
<xsl:when test="exists(preceding-sibling::cell[1]/@col)">
<xsl:value-of select="number(@col)-number(preceding-sibling::cell[1]/@col)-1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(@col)-1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$coldiff>=1">
<xsl:value-of select="for $a in (1 to $coldiff) return '<clStart:1,1><clEnd:>'" separator=""/>
</xsl:if>
<xsl:text disable-output-escaping="no"><clStart:</xsl:text>
<xsl:value-of select="concat($row,',',$col)"/>
<xsl:text disable-output-escaping="no">></xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="no"><clEnd:></xsl:text>
</xsl:template>
which is pretty long compared to your templates, so i think i'm gonna use your version (mine aint that efficient with so many variables and looping).
the 12 came from, my original source, i did not notice it. i shortened the table sample.
however, what if there are information in the spanning cell, like for example the rules, like <cell col='1' rowspan='2' rulebottom='1'> so that your empty cell marker would also reflect this information, like <clStart:1,1;rulebottom:1><clEnd:>. I think this would be more complicate, i'll be satisfied with what i have right now and just think about this when the situation arrives.
Again thanks!
-- Jeff Sese
David Carlisle wrote:
something like this perhaps
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="table"> <xsl:text> <tStart:</xsl:text> <xsl:value-of select="@row"/> <xsl:text>:</xsl:text> <xsl:value-of select="@col"/> <xsl:text>></xsl:text> <xsl:apply-templates select="row"/> <xsl:text> <tEnd:> </xsl:text> </xsl:template>
<xsl:template match="row"> <xsl:text> <rStart:></xsl:text> <xsl:variable name="here" select="."/> <xsl:for-each select="1 to ../@col"> <xsl:variable name="cell" select="$here/cell[@col=current()]"/> <xsl:text> <cStart:</xsl:text> <xsl:value-of select="max(($cell/@rowspan,1))"/> <xsl:text>,</xsl:text> <xsl:value-of select="max(($cell/@colspan,1))"/> <xsl:text>></xsl:text> <xsl:apply-templates select="$cell/node()"/> <xsl:text><cEnd:></xsl:text> </xsl:for-each> <xsl:text> <rEnd:></xsl:text> </xsl:template>
</xsl:stylesheet>
which on
<tables>
<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>
<table row="3" col="5"> <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> </tables>
produces
<tStart:4:5> <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:> <rEnd:> <rStart:> <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:>
<tStart:3:5> <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:> <rEnd:> <rStart:> <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:>
which is more or less what you asked for except in the first table you said you needed <tStart:4,12> but I'm not sure where the 12 came from.
David
________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Transforming Tables - rep, David Carlisle | Thread | Re: [xsl] Transforming Tables - rep, David Carlisle |
RE: [xsl] Wrapping a Condition arou, Kevin Bird \(Matrix\ | Date | [xsl] two transformations consecuti, jimmy |
Month |