This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Customised sorting
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] Customised sorting
- From: Mille Eriksson <mille dot eriksson at observergroup dot com>
- Date: Thu, 05 Apr 2001 09:30:57 +0200
- Organization: Observer AB
- Reply-To: xsl-list at lists dot mulberrytech dot com
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