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

Re: Transforming Tables - repost

Subject: Re: Transforming Tables - repost
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Tue, 16 May 2006 19:27:55 +0800
xsl text lt
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&gt;=1">
<xsl:value-of select="for $a in (1 to $coldiff) return '&lt;clStart:1,1&gt;&lt;clEnd:&gt;'" separator=""/>
</xsl:if>
<xsl:text disable-output-escaping="no">&lt;clStart:</xsl:text>
<xsl:value-of select="concat($row,',',$col)"/>
<xsl:text disable-output-escaping="no">&gt;</xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="no">&lt;clEnd:&gt;</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>
&lt;tStart:</xsl:text>
<xsl:value-of select="@row"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="@col"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates select="row"/>
<xsl:text>
&lt;tEnd:&gt;
</xsl:text>
</xsl:template>

<xsl:template match="row">
<xsl:text>
&lt;rStart:&gt;</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>
&lt;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>&gt;</xsl:text>
<xsl:apply-templates select="$cell/node()"/>
<xsl:text>&lt;cEnd:&gt;</xsl:text>
</xsl:for-each>
<xsl:text>
&lt;rEnd:&gt;</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

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-2011 All Rights Reserved.