RE: [xsl] Grouping adjacent columns in a table

Subject: RE: [xsl] Grouping adjacent columns in a table
From: Emmanuel Begue <eb@xxxxxxxxxx>
Date: Fri, 15 Jan 2010 17:48:04 +0100
> -----Original Message-----
> From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
> Sent: Friday, January 15, 2010 4:33 PM
> Subject: RE: [xsl] Grouping adjacent columns in a table
> Rather than using for-each-group, I would use recursion: tail
> recursion over the sequence of columns, testing each one to see
> if it has the same content as the next column. You can do this
> test using deep-equals(): given $i as the column number
> deep-equal(tbody/tr/td[$i], tbody/tr/td[$i+1)
> The output of this recursion can be a list of the columns to be
> included in the result (in your example (1,2,3,5)) and then you
> can use this list to drive the process that builds the output.

Using deep-equal (and a key to avoid using //), it's possible to
proceed in one pass:

<xsl:key name="cols" match="td" use="count(preceding-sibling::*)"/>

<xsl:template match="th|td">
  <xsl:variable name="pos" select="count(preceding-sibling::*)"/>
  <xsl:if test="not(deep-equal(key('cols',$pos),key('cols',$pos - 1)))">
    <xsl:copy-of select="."/>

Is it undesirable because it (probably) makes the comparison
again for each row (ie, for each column of each row), so if
there are many rows it may be slow...?

But if there are not many rows, why not? (I feel I'm missing
something but I don't know what ;-)

(Also, this only works if identical columns are adjacent).


Current Thread