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

Re: Sorting and Grouping revisited

Subject: Re: Sorting and Grouping revisited
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 19 Apr 2001 09:05:54 +0100
xslt sorting and grouping
> 'am I crazy for expecting XSLT to be able to handle sorting and
> grouping gracefully?'

You're not crazy to ask that (but that doesn't necessarily mean that
you are not crazy, and it certainly doesn't mean that XSLT handles
sorting and grouping gracefully).


> 'There is no simple way of doing grouping in XSLT. In some cases it can be
> done, painfully and generally rather slowly, by testing each item to see if
> it is the same as the previous item. 

That was probably written before Steve Meunch's insight into using keys
to make this more efficient (but in some ways even less graceful).
There's more on this sorting technique at Jeni's site.

> It seems to me the best bet for accomplishing what I need to do is to
> restructure my XML.  As another member of this group noted, this is changing
> the data subtly for a presentation reason.  This seems wrong.

It is wrong:-)



> In short, it seems as if the shortcoming is simply the lack of a way to
> access elements of a sorted node list (as opposed to in document-order).  I
> have read many archived messages from this group, but am I missing
> something?

Partly you are missing XSLT 2.0: the XSLT2 reequirements document
explicitly lists this as one of the main areas to be improved,
but there isn't even a draft spec for XSLT2, so you are not the only one
missing that.

However all is not lost. You can access the sorted list by doing

<xsl:variable name="x">
  <xsl:for-each....
    <xsl:sort/>
  ....
</xsl:variable>

then use it as in

<xsl:apply-templates select="exslt:node-set($x)"/>

where exslt: is the prefix for your processors extension namespace.
All the major XSLT systems (I think) offer a node-set() function for
this use.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 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.