ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] grouping, sorting, splitting
by David Carlisle other posts by this author
Apr 18 2005 3:26AM messages near this date
[xsl] Upgrading Saxon XSLT 1.0 support addressing known limitations | [xsl] grouping, sorting, splitting
& XSLT 
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
________________________________________________________________________

--~------------------------------------------------------------------
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@[...].com> 
--~--

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved