xsl-list
[Top] [All Lists]

RE: [xsl] Grouping adjacent columns in a table

2010-01-15 09:33:40

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(_dot_)bird(_at_)matrixdigitaldata(_dot_)co(_dot_)uk] 
Sent: 15 January 2010 15:05
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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
  




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>