xsl-list
[Top] [All Lists]

Alternate sort order of subelements based on previous parent element

2005-08-31 18:00:25
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


--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>
  • Alternate sort order of subelements based on previous parent element, Philipp Kursawe <=