Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Alternate sort order of subelements based on previous parent element

From: "Philipp Kursawe" <LukeSky77@------->
To:
Date: 9/1/2005 1:01:00 AM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent