Re: [xsl] table header respecting xml structure

Subject: Re: [xsl] table header respecting xml structure
From: Manolis Mavrikis <M.Mavrikis@xxxxxxxx>
Date: Wed, 04 Feb 2004 20:16:36 +0000
Rui,

I had something siilar long ago. I can't find it right now, I 'll look in a while instead of re-writing it now. Some clarifications though will help:

I guess you want to build an HTML table. So: something like:

<table border="1" id="table1">
<tr>
<td rowspan="3">Col 1</td>
<td rowspan="3">Col2 </td>
<td align="center" colspan="4">More cols</td> <td rowspan="3">Col 3</td>
<td rowspan="3">Col 4</td>
</tr>
<tr>
<td rowspan="2">Col 1</td>
<td rowspan="2">Col2</td>
<td align="center" colspan="2">depth cols</td>
</tr>
<tr>
<td>Col1 </td>
<td>Col 2</td>
</tr>
</table>



right ?


The other thing I don't get from this structure is are you going to have data in the columns ? Like

<column desc="Col 2">Hello</column> ?

Basically the idea is that when you find this root structure (btw is this the root of the document, or the root of this structure that represents tables?) you create the <table> html element and then you call a template with select="*"

   <xsl:choose>
   <xsl:when test="name()='column'">
   <td>
	<xsl:attribute name="rowspan"><xsl:value-of select="count(group)+1"></xsl:attribute>
	<xsl:value-of select="@desc"/>
    </td>
    </xsl:when><xsl:when test="name()='group'>
    <td>
	<xsl:attribute name="colspan"><xsl:value-of select="count(descendant::*)-1"></xsl:attribute>
	<xsl:value-of select="@desc"/>
    </td>
   </xsl:when></xsl:choose>
</xsl:template>


or something like that (that would basically count the elements inside the group and the descandant group(s) in order to know your colspan.


Then ypu call another tempalte selecting all groups that would write you the TRs which would again call the previous tempalte fro columns.

I am sorry I can't be more detailed or if this sounds confusing its out of my mind I haven't tried you. I 'll have a look if I find the stylesheet where I was doing something similar. Meanwhile if this turns out to be helpful please post saying you found it (it will save me time).

Cheers,

Manolis

Rui Alberto L. Gonçalves wrote:

Hi all,

I have the following document:
<root>
 <column desc="Col 1"/>
 <column desc="Col 2"/>
 <group desc="More Cols">
   <column desc="Col 1"/>
   <column desc="Col 2"/>
   <group desc="Depth Col">
     <column desc="Col 1"/>
     <column desc="Col 2"/>
   </group>
 </group>
 <column desc="Col 3"/>
 <column desc="Col 4"/>
</root>

and I want to build a table with the header respecting
the document structure, that should look like:

TABLE:
================================================================
       |       |         More Cols            |       |       |
Col 1  | Col 2 | Col 1  | Col 2 | Depth Col   | Col 3 | Col 4 |
       |       |        |       |Col 1 | Col 2|       |       |
===============================================================|

I'm stucked with this problem ... does anyone have
any sugestion or has done something similar??
Thaks for any help!!

Rui







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


Current Thread