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

RE: Tranforming a table with colspan and rowspan attri

Subject: RE: Tranforming a table with colspan and rowspan attributes to another more complex table
From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Jan 2002 13:47:22 -0000
stylesheet colspan
Hi,

Providing your input data is just like your sample, you can use this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <table>
  <xsl:apply-templates select="fvtable/fvtr"/>
  </table>
</xsl:template>

<xsl:template match="fvtr">
<tr>
  <xsl:apply-templates select="fvtd"/>
</tr>
</xsl:template>

<xsl:template match="fvtd">
<td>
  <xsl:copy-of select="@colspan|@rowspan"/>
  <xsl:value-of select="."/>
</td>
</xsl:template>

</xsl:stylesheet>


You can add your html markup as you want, but I would recommend using class
attributes and then including a css style section within cdata at the top of
your stylesheet.

I hope this is a start

cheers

andrew

===




-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Rogier
Hofboer
Sent: Tuesday, January 29, 2002 1:09 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Tranforming a table with colspan and rowspan attributes
to another more complex table


Hi,

Can anybody help me out with the following?

xml:

<fvtable>
  <fvtr>
    <fvtd>1</fvtd>
    <fvtd>2</fvtd>
    <fvtd>3</fvtd>
    <fvtd>4</fvtd>
  </fvtr>
  <fvtr>
    <fvtd>5</fvtd>
    <fvtd>6</fvtd>
    <fvtd>7</fvtd>
    <fvtd>8</fvtd>
  </fvtr>
</fvtable>

xslt:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="fvtable">
  <table width="100%" border="0" cellpadding="0" cellspacing="1">
  <xsl:variable name="maxcells">
  <xsl:for-each select="fvtr"><xsl:sort select="count(fvtd)"
order="descending"/>
    <xsl:if test="position()=1"><xsl:value-of
select="count(fvtd)"/></xsl:if>
  </xsl:for-each>
  </xsl:variable>
  <tr>
    <td colspan="{$maxcells*2+1}" bgcolor="#D9DCEF" height="2"></td>
  </tr>
  <xsl:for-each select="fvtr">
    <tr>
      <td bgcolor="#D9DCEF" width="2"></td>
      <xsl:for-each select="fvtd">
       <td bgcolor="#FFFFDD" valign="top">
        <font face="arial" size="2">
        <xsl:apply-templates />
        </font>
        </td>
        <xsl:if test="position() != last()">
          <td bgcolor="#D9DCEF" width="1"></td>
        </xsl:if>
      </xsl:for-each>
      <td bgcolor="#D9DCEF" width="2"></td>
    </tr>
    <xsl:if test="position() != last()">
      <tr>
        <td colspan="{$maxcells*2+1}" bgcolor="#D9DCEF" height="1"></td>
      </tr>
    </xsl:if>
  </xsl:for-each>
  <tr>
    <td colspan="{$maxcells*2+1}" bgcolor="#D9DCEF" height="2"></td>
  </tr>
  </table>
</xsl:template>
</xsl:stylesheet>

This works ok.

But now I want to change the input XML to be something like this:

<fvtable>
  <fvtr>
    <fvtd colspan="2">1</fvtd>
    <fvtd>2</fvtd>
    <fvtd>3</fvtd>
    <fvtd>4</fvtd>
    <fvtd>5</fvtd>
  </fvtr>
  <fvtr>
    <fvtd>6</fvtd>
    <fvtd>7</fvtd>
    <fvtd colspan="2">8</fvtd>
    <fvtd rowspan="3">9</fvtd>
    <fvtd>10</fvtd>
  </fvtr>
  <fvtr>
    <fvtd>11</fvtd>
    <fvtd colspan="2" rowspan="2">12</fvtd>
    <fvtd>13</fvtd>
    <fvtd>14</fvtd>
  </fvtr>
  <fvtr>
    <fvtd>15</fvtd>
    <fvtd>16</fvtd>
    <fvtd>17</fvtd>
  </fvtr>
</fvtable>

And this HTML as output:

<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
  <td colspan="13" bgcolor="#D9DCEF" height="2"></td>
</tr>
<tr>
  <td bgcolor="#D9DCEF" width="2"></td>
  <td colspan="3" bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">1</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">2</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">3</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">4</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">5</font>
  </td>
  <td bgcolor="#D9DCEF" width="2"></td>
</tr>
<tr>
  <td colspan="13" bgcolor="#D9DCEF" height="1"></td>
</tr>
<tr>
  <td bgcolor="#D9DCEF" width="2"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">6</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">7</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td colspan="3" bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">8</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td rowspan="5" bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">9</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">10</font>
  </td>
  <td bgcolor="#D9DCEF" width="2"></td>
</tr>
<tr>
  <td colspan="9" bgcolor="#D9DCEF" height="1"></td>
  <td colspan="3" bgcolor="#D9DCEF" height="1"></td>
</tr>
<tr>
  <td bgcolor="#D9DCEF" width="2"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">11</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td colspan="3" rowspan="3" bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">12</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">13</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">14</font>
  </td>
  <td bgcolor="#D9DCEF" width="2"></td>
</tr>
<tr>
  <td colspan="3" bgcolor="#D9DCEF" height="1"></td>
  <td colspan="3" bgcolor="#D9DCEF" height="1"></td>
  <td colspan="3" bgcolor="#D9DCEF" height="1"></td>
</tr>
<tr>
  <td bgcolor="#D9DCEF" width="2"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">15</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">16</font>
  </td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#D9DCEF" width="1"></td>
  <td bgcolor="#FFFFDD" valign="top">
    <font face="arial" size="2">17</font>
  </td>
  <td bgcolor="#D9DCEF" width="2"></td>
</tr>
<tr>
  <td colspan="13" bgcolor="#D9DCEF" height="2"></td>
</tr>
</table>

I tried a lot of things... But I can't find a single
solution that's able to handle all the cases.
(just simple colspans work, but not things like the definition above)
The stylesheet I am looking for should be able to handle
all kinds combinations with colspan an rowspan
it should include a complete table handler.

Is this possible to build with XSLT? Anyone?

Thanks in advance,

Rogier Hofboer







 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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