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

Grouping and sorting data

Subject: Grouping and sorting data
From: Verakso <verakso@xxxxxxxxx>
Date: Wed, 24 Nov 2004 13:36:23 +0100
sorting data
Is there some great FAQ about grouping and sorting flat XML data?

Everytime I seem to get at grip of it, I still mess it up

I have a huge XML file with records that looks like this:
<csv_data_records>
<record num="1">
          <Country>Denmark</Country>
          <City>Copenhagen</City>
          <CompanyFull>Company Name</CompanyFull>
          <adr1>Street Address</adr1>
          <adr2></adr2>
          <adr3></adr3>
          <adr4></adr4>
          <PostalCode>1070</PostalCode>
          <ZipCode>1070</ZipCode>
          <MainPhone>+45 5555 55555</MainPhone>
          <MainFax>+45 6666 66666</MainFax>
          <CompanyType>Branch</CompanyType>
          <DepartmentTitle>Management/Client Manager</DepartmentTitle>
          <LastName>Nielsen</LastName>
          <FirstName>Thomas</FirstName>
          <Direct>+45 77777 7777</Direct>
          <Home></Home>
          <MobileHoliday></MobileHoliday>
          <Fax>+45 8888 8888</Fax>
     </record>
.
.
<csv_data_records>

I would like to group and sort, first on Country, second on City and
third on CompanyFullName.

I have tries keys and various approaches, but I haven't had any succes
with the secon and third grouping.

The stylesheet looks like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
	<xsl:key name="kCountry" match="record" use="Country"/>
	<xsl:template match="*"/>
	<xsl:template match="csv_data_records">
		<test>
			<xsl:apply-templates
select="record[generate-id(.)=generate-id(key('kCountry', Country))]">
				<xsl:sort select="Country"/>
			</xsl:apply-templates>
		</test>
	</xsl:template>
	<xsl:template match="record">
		<country>
			<xsl:value-of select="Country"/>
		</country>
	</xsl:template>
</xsl:stylesheet>

I just have a problem getting back and selecting the City's to the
corresponding Country, and then next the grouping of the Companies.

What have I missed.

/Thomas

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.