[xsl] Sorting and grouping

Subject: [xsl] Sorting and grouping
From: Martin Gundersen <mgu@xxxxxxxxxxxxxx>
Date: Wed, 2 Oct 2002 11:31:08 +0200
Thanks to all who helped me with the PHP question.  Now for something
completely different:

I have a non-sorted list I want to sort, but I also want to know when a
group is new.  I've managed to do this
using for-each, sort and an if with a "not preceding".  (Thanks to the faq
and posts in this list)

But the "not preceding" is not looking at the sorted order - it's looking at
the orginal order in the XML-file.  I want it to "search" the sorted list.


<xsl:output method="html" />

<xsl:template match="check">
<table border="1">
<xsl:for-each select="news"><xsl:sort select="@i" order="descending"/>
<td><xsl:if test="not(preceding::g=g)">*</xsl:if></td>
<td><xsl:value-of select="@i"/></td>
<td><xsl:value-of select="g"/></td>



<news i="6"><g>3</g></news>
<news i="1"><g>2</g></news>
<news i="5"><g>2</g></news>
<news i="4"><g>1</g></news>
<news i="3"><g>1</g></news>
<news i="2"><g>3</g></news>

This outputs : (n = new, i=item, g=group)
n i g 
* 6 3 
  5 2 
* 4 1 
  3 1 
  2 3 
* 1 2        <- i=1 is the first use of group 2 in the XML

But I want it to output :

n i g 
* 6 3 
* 5 2        <- i=5 is the first use of group 2 in the sorted list
* 4 1 
  3 1 
  2 3 
  1 2 

Thanks in advance for any help!

Martin Gundersen
Oslo, Norway

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread