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

Re: Alternate sort order of subelements based on previ

Subject: Re: Alternate sort order of subelements based on previous parent element
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 01 Sep 2005 09:13:54 +0200
copy subelements
Hi,
Tempore 03:00:25, die 09/01/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Philipp Kursawe <LukeSky77@xxxxxxx>:

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.

I guess the easiest way is to group the 'item' elements by row and then alternate their sort order:


<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:key name="item" match="item" use="@row"/>

<xsl:template match="items">
<xsl:copy>
<xsl:for-each select="item[generate-id(key('item',@row))=generate-id()]">
	<xsl:sort select="@row" data-type="number"/>
	<xsl:variable name="order">
		<xsl:choose>
			<xsl:when test="position() mod 2=0">ascending</xsl:when>
			<xsl:otherwise>descending</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:comment><xsl:value-of select="$order"/></xsl:comment>
	<xsl:for-each select="key('item',@row)">
		<xsl:sort select="@col" order="{$order}" data-type="number"/>
		<xsl:copy-of select="."/>
	</xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+There are only 10 types of people in this world. Those who understand binary, and those who don'tB;

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.