[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Sorting and grouping

Subject: RE: Sorting and grouping
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 2 Oct 2002 11:24:28 +0100
access grouping
> I have a non-sorted list I want to sort, but I also want to 
> know when a group is new.

Try not to think so procedurally: you're not interested in when things
happen, only in how the output is functionally related to the input.

Generally with sorting-then-grouping problems I advise a two-phase
transformation, using a temporary tree (result tree fragment) as the
intermediate result. This needs the xx:node-set() extension to access
this tree in the second phase.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 



  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.
> 
> Example:
> 
> XSL:
> <xsl:output method="html" />
> 
> <xsl:template match="check">
> <html>
> <table border="1">
> <tr><th>new</th><th>i</th><th>g</th></tr>
> <xsl:for-each select="news"><xsl:sort select="@i" 
> order="descending"/> <tr> <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>
> </tr>
> </xsl:for-each>
> 
> </table>
> </html>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> XML:
> <check>
> <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>
> </check>
> 
> 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!
> 
> Regards
> Martin Gundersen
> martin@xxxxxxxxxxxxx
> Oslo, Norway
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.