Subject: [xsl] flattening html table with row/colspans From: Graham Seaman <graham@xxxxxxxxx> Date: Wed, 16 Oct 2002 17:51:34 +0100 (BST) |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Depth of an XML file using XS, Padmapriya Kandhadai | Thread | Re: [xsl] flattening html table wit, Joerg Heinicke |
[xsl] Depth of an XML file using XS, Padmapriya Kandhadai | Date | Re: [xsl] xsl:sort ... jeff comes b, Daniel Veillard |
Month |