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

Customised sorting

Subject: Customised sorting
From: Mille Eriksson <mille.eriksson@xxxxxxxxxxxxxxxxx>
Date: Thu, 05 Apr 2001 09:30:57 +0200
lyon city name
In Michael Kay's book XSLT - Programmer's reference, the following
example is given on getting data into groups (pages 560-561):

<cities>
	<city name="Paris" country="France"/>
	<city name="Roma" country="Italy"/>
	<city name="Nice" country="France"/>
	<city name="Madrid" country="Espana"/>
	<city name="Milano" country="Italia"/>
	<city name="Firenze" country="Italia"/>
	<city name="Napoli" country="Italia"/>
	<city name="Lyon" country="France"/>
	<city name="Barcelona" country="Espana"/>
</cities>

The grouping of the data is done with the following stylesheet:

<xsl:template match="/">
	<xsl:variable name="unique-countries"
		select="/cities
			/city[not(@country=preceding-sibling::city/@country)]
			/@country"
	/>
	<countries>
		<xsl:for-each select="$unique-countries">
			<country name="{.}">
				<xsl:for-each select="//city[@country=current()]">
					<city>
						<xsl:value-of select="@name"/>
					</city>
				</xsl:for-each>
			</country>
		</xsl:for-each>
	</countries>
</xsl:template>

Resulting in:

<countries>
	<country name="France">
		<city>Paris</city>
		<city>Nice</city>
		<city>Lyon</city>
	</country>
	...
	and so on
</countries>

Now, my problem is very similar to this example but with the addition
that I need to sort the groups in a specific order. In the example this
would correspond to order the groups for example by the size of captial
of each country. This ordering information needs to bes supplied with
the style-sheet and not with the XML-document.

Are there any ideas of how this can be accomplished?

Thanks in advance
Mille Eriksson

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.