Subject: RE: Grouping adjacent columns in a table
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 15 Jan 2010 15:33:14 -0000
|
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.
[The reason for avoiding for-each-group is that it's not easy in this
situation to compute a grouping key. But it's not impossible, and if
recursion fills you with horrors, it might be easier.)
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
> -----Original Message-----
> From: Kevin Bird [mailto:kevin.bird@xxxxxxxxxxxxxxxxxxxxxxx]
> Sent: 15 January 2010 15:05
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Grouping adjacent columns in a table
>
> Hello
>
> I have an XHTML table which can have an arbitrary number of
> columns and rows.
>
> For display purposes, I need to reduce the number of columns
> by grouping adjacent duplicate columns.
>
> Therefore.
>
> <table border="1" rules="all">
> <thead>
> <tr>
> <th>A</th>
> <th>B</th>
> <th>C</th>
> <th>D</th>
> <th>E</th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td>100</td>
> <td>100</td>
> <td>200</td>
> <td>200</td>
> <td>300</td>
> </tr>
> <tr>
> <td>400</td>
> <td>500</td>
> <td>500</td>
> <td>500</td>
> <td>500</td>
> </tr>
> <tr>
> <td>600</td>
> <td>600</td>
> <td>700</td>
> <td>700</td>
> <td>800</td>
> </tr>
> <tr>
> <td>900</td>
> <td>900</td>
> <td>900</td>
> <td>900</td>
> <td>900</td>
> </tr>
> </tbody>
> </table>
>
> becomes
>
> <table border="1" rules="all">
> <thead>
> <tr>
> <th>A</th>
> <th>B</th>
> <th>C,D</th>
> <th>E</th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td>100</td>
> <td>100</td>
> <td>200</td>
> <td>300</td>
> </tr>
> <tr>
> <td>400</td>
> <td>500</td>
> <td>500</td>
> <td>500</td>
> </tr>
> <tr>
> <td>600</td>
> <td>600</td>
> <td>700</td>
> <td>800</td>
> </tr>
> <tr>
> <td>900</td>
> <td>900</td>
> <td>900</td>
> <td>900</td>
> </tr>
> </tbody>
> </table>
>
> as columns 'C' and 'D' contain duplicate values. The real
> data could contain up to 50 columns and grouping could span
> several columns.
>
> I can utilise a XSLT 2.0 solution.
>
> Any help you be appreciated.
>
> --
> Kevin
|