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

Alternate sort order of subelements based on previous

Subject: Alternate sort order of subelements based on previous parent element
From: "Philipp Kursawe" <LukeSky77@xxxxxxx>
Date: Thu, 1 Sep 2005 03:00:25 +0200
philipp kursawe
Hello fellow XSLT users,

I have run into a problem solving the following sophisticated (at least for
me) task:
There is a list of items each containing two nodes "row" and "col". First
the list has to be ordered ASCENDING by "rows". Next step is to sort the
list items of each "row" by its "col" node where the ordering direction
changes when the row is different to the previous.

Sample XML:
<items>
  <item row="300" col="2" />
  <item row="300" col="57" />
  <item row="304" col="110" />
  <item row="301" col="25" />
  <item row="301" col="120" />
  <item row="335" col="27" />
  <item row="327" col="50" />
  <item row="304" col="1" />
</items>

Expected result XML after transformation:
<items>
  <!-- Order by col DESCENDING -->
  <item row="300" col="57" />
  <item row="300" col="2" />
  <!-- Row change, now order by col ASCENDING -->
  <item row="301" col="25" />
  <item row="301" col="120" />
  <!-- Row change, revers order direction of col again -->
  <item row="304" col="110" />
  <item row="304" col="1" />
  <item row="327" col="50" />  
  <item row="335" col="27" />
</items>

Ordering and grouping by the row is the easy part. But how do I reverse the
ordering everytime the row changes? It should work with whatever order
direction of the "col" attribute I am starting. 

If doing this kind of operation based on attributes is too difficult it
would be also possible to convert the attributes to nodes.

I am stuck here since using "xsl:if" inside "xsl:sort" is not permitted.
Anybody got an Idea?

Thanks in advance,
Phil

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.