Does this mean, from a table like the following
<table>
<tr>
<td>1</td>
<td colspan="2">2</td>
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
you want to get the following output:
1
2
3
4
5
6
or should the values from the <td>s with col- or rowspan be repeated:
1
2
2
3
4
5
6
3
In the second case: What should happen in conflict situations (e.g.
colspan at <td> with value 6)?
I couldn't imagine that you want to have the first case, because it's
simply <td> for <td> in document order.
Regards,
Joerg
Graham Seaman wrote:
Hi,
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
order:
tr[1]td[1]
tr[1]td[2]
tr[1]td[3]
.....
tr[2]td[1]
tr[2]td[2]
tr[2]td[3]
... etc
And without rowspans or colspans, this is one short recursive template
(appended).
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()
function...
Thanks for any advice, code outlines, etc...
Graham
--------------------------------------------------------
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:choose>
<xsl:when test="count($the-trs/td[$td-pos]) > 0">
<xsl:for-each select="$the-trs">
<xsl:choose>
<xsl:when test="td[$td-pos]">
<xsl:apply-templates select="td[$td-pos]"/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<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:call-template>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list