[xsl] flattening html table with row/colspans

Subject: [xsl] flattening html table with row/colspans
From: Graham Seaman <graham@xxxxxxxxx>
Date: Wed, 16 Oct 2002 17:51:34 +0100 (BST)

I've been off the list (and xsl) for a while - I can't see this question
in the archives or the faq, but I would guess it may have come up before;
if so, sorry, and please point me to the right place...

I need to convert html tables used for layout to a linear structure,
listing the contents of each cell in sequence but removing the table
itself. For a simple table with no rowspans or colspans, I would like the

... etc

And without rowspans or colspans, this is one short recursive template

Once rowspans and colspans come into it, recursion gets more than I can
handle, but I assume it's possible to do this (preferably using XSL1.0
without extensions).

For a table with rowspan and colspan I would like to mimic the above
output but in terms of the visual appearance of the rendered html, rather
than the actual numbering of the table cells.

So when I meet a <td colspan="x"> all subsequent tds at position [y] in
this tr should be treated as if their position was [y+x-1]. Similarly,
if I meet a <td rowspan="x"> in tr[m], the following tds at position
[y] in tr[m+1], tr[m+2] .. tr[m+x-1] should be treated as if they were in
position [y+1]. Hope that makes sense... 

I assume I need several recursive templates to implement this, but have
given myself a headache trying to visualize how they need to interact.
I'm not even sure if it's possible at all without using the node-set()

Thanks for any advice, code outlines, etc...

This is the working version with no row/col spans...

    <xsl:template name="linearize-table">
      <xsl:param name="the-trs"/>
      <xsl:param name="td-pos"/>
        <xsl:when test="count($the-trs/td[$td-pos]) &gt; 0">
          <xsl:for-each select="$the-trs">
              <xsl:when test="td[$td-pos]">
                   <xsl:apply-templates select="td[$td-pos]"/>
          <xsl:call-template name="linearize-table">
            <xsl:with-param name="the-trs" select="$the-trs"/>
            <xsl:with-param name="td-pos" select="$td-pos + 1"/>

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

Current Thread