Subject: Re: [xsl] Customised sorting From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 05 Apr 2001 09:51:55 +0100 |
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?
<pop:capitals> <city name="Paris" pop="4000"/> <city name="Roma" pop="3000"/> <city name="Madrid" pop="1000"/> <city name="Napoli" pop="2000"/> </pop:capitals>
T:\ftemp>saxon mille.xml mille.xsl <?xml version="1.0" encoding="utf-8"?> <countries> <country name="Espana"> <city>Madrid</city> <city>Barcelona</city> </country> <country name="Italia"> <city>Milano</city> <city>Firenze</city> <city>Napoli</city> </country> <country name="Italy"> <city>Roma</city> </country> <country name="France"> <city>Paris</city> <city>Nice</city> <city>Lyon</city> </country> </countries> T:\ftemp>
<xsl:sort select="document('')/*/pop:capitals /city[@name=current()/ancestor::cities/ city[@country=current()]/@name] /@pop"/>
<?xml version="1.0"?><!--mille.xsl--> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pop="population" exclude-result-prefixes="pop" version="1.0">
<pop:capitals> <city name="Paris" pop="4000"/> <city name="Roma" pop="3000"/> <city name="Madrid" pop="1000"/> <city name="Napoli" pop="2000"/> </pop:capitals>
<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"> <xsl:sort select="document('')/*/pop:capitals /city[@name=current()/ancestor::cities/ city[@country=current()]/@name] /@pop"/> <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>
-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML/OmniMark services, training, products. Book: Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3 Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html Next public instructor-led training: 2001-04-06,05-01,05-14,05-15, - 05-16,05-17,05-21,05-22,06-18,06-21,07-20,07-21,09-19
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Customised sorting, Jeni Tennison | Thread | Re: [xsl] Customised sorting, Mille Eriksson |
Re: [xsl] Re: retrieve data from #1, Jeni Tennison | Date | Re: [xsl] !!!counters in XSL!!!, Alexey Gokhberg |
Month |