Re: [xsl] grouping, sorting, splitting

Subject: Re: [xsl] grouping, sorting, splitting
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 18 Apr 2005 11:26:02 +0100
If you need to sort and group it's much easier to program (and to think
about) if you do it in two steps, first sort and then group, eiether
doing it as two separate stylesheets or using a node-set extension
function which would allow you to do the two passes in one stylesheet.

Normally, after having done 

<xsl:for-each select="key('days', @date)[position() mod 3 = 1]">

You'd pick up the two following siblings by doing
select="following-sibling::*[position() &lt; 3]"

But axis navigation always refers to the source tree not to the sorted
node list constructed by xsl:sort so this doesn't work here.
If you do it in two passes, then on the second pass the sorted list is
reflected in the input so this would work.

If you do need to do it in one pass then as your sort criterion is
pretty simple I think you can do it in this case, you just can't easily
manke use of the key that has indexed your elements, you need to search
the doc again, something like

<xsl:for-each select="key('days', @date)[position() mod 3 = 1]">
<tr>
 <xsl:for-each
select=".|following-sibling::entry[@date=current()/@date][position()
&lt; 3]">
  <td>...

This relies on teh fact that sorting is stable: entries with the same
date will be reported in the same order as they appear in the original
document.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread