Table generation with XSL?

Subject: Table generation with XSL?
From: "Chris Burn" <chrislists@xxxxxxxxxxx>
Date: Tue, 27 Jun 2000 12:24:17 +0100
Hello..

I'm sure this problem must have come up before, but i can't find any
reference to it.

I have a dtd that specifies a table structure :

<!ELEMENT Table (HeadRow, Row*, Caption?)>
<!ELEMENT HeadRow (Cell+)>
<!ELEMENT Row (Cell+)>
<!ELEMENT Cell (#PCDATA)>
<!ELEMENT Caption (#PCDATA)>

As you can see authors of an xml document that conforms to this dtd can have
as many Cell elements in any Rows as they require. So some Rows will have
more Cells than others. So my problem is outputting a html table that has
the same number of cells in each row to keep proper formating.

For example if the XML document is :

<Table>
  <HeadRow>
    <Cell>Heading one</Cell>
    <Cell>Heading two</Cell>
  </HeadRow>
  <Row>
    <Cell>Cell one</Cell>
    <Cell>Cell two</Cell>
    <Cell>Cell three</Cell>
  </Row>
  <Row>
    <Cell>Cell Four</Cell>
  </Row>
  <Caption>this is the caption</Caption>
</Table>

I would like the HTML out put to be :

<table>
  <thead>
    <tr>
      <td>Heading one</td>
      <td>Heading two</td>
      <td>&nbsp</td>
    </tr>
  </thead>
  <tr>
    <td>Cell one</td>
    <td>Cell two</td>
    <td>Cell three</td>
  </tr>
  <tr>
    <td>Cell Four</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">this is the caption</td>
  </tr>
</table>

The way I was thinking of tackling this was :

maxCells = 0
For Each Row (including HeadRow)
  count = Count number of cells in current row
  if count > maxCells then maxCells = count
End For

<table>
For each Row
  <tr>
    For i = 1 to maxCells
      <td>
      if current row current cell[i] content <> null then ouput content else
output &nbsp;
      </td>
    end for
  </tr>
end for
<tr><td colspan="maxCells">output caption</td></tr>
</table>

But I can't think how to write this in XSL. Does anyone have any ideas? or
has this been solved before?

Many thanks,

Chris Burn
---
chris burn              p.   +44 (0)20 7961 0305
webmaster               f.   +44 (0)20 7961 0307
                        e.   cburn@xxxxxxxxxxxxxxxxxx
businesseurope.com      icq. 18567886



__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com


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


Current Thread