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

RE: Using xsl:sort to sort child elements

Subject: RE: Using xsl:sort to sort child elements
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 4 Nov 2003 19:27:46 -0000
xsl sort children
By the time you are processing an Address, it's too late to sort the
addresses. When you write

<xsl:template match="EntryData/Applicant/Address">
  <xsl:copy>
    <xsl:apply-templates> 
     <xsl:sort select="ZipCode"/>
   </xsl:apply-templates> 
  </xsl:copy>
</xsl:template>

the apply-templates is selecting the children of the Address, and
evaluating child::ZipCode for each one: but the nodes being sorted are
Type, City, and ZipCode nodes, and none of these has a ZipCode child.
You need to sort the addresses at the point where you are processing the
Applicant.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Jim McDowall
> Sent: 04 November 2003 17:30
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Using xsl:sort to sort child elements
> 
> 
> I have examined the numerous examples of the xsl:sort instruction but 
> haven't seen one that describes the technique to use for what 
> I need to 
> do.  
> 
> I need to sort child elements of the document that I am 
> transforming. Here is a very very simple example of what I'm 
> trying to accomplish.  
> Given this document: 
> 
> <EntryData>
> 	<Applicant>
> 		<FirstName>Ralph</FirstName>
> 		<LastName>Smith</LastName>
> 		<Address>
> 			<Type>Business</Type>
> 			<City>Chicago</City>
> 			<ZipCode>60011</ZipCode>
> 		</Address>
> 		<Address>
> 			<Type>Regional</Type>
> 			<City>Springfield</City>
> 			<ZipCode>62103</ZipCode>
> 		</Address>
> 		<Address>
> 			<Type>Corporate</Type>
> 			<City>New York</City>
> 			<ZipCode>10011</ZipCode>
> 		</Address>
> 	</Applicant>
> </EntryData>
> 
> I would like to transform this document sorting the "Address" 
> elements 
> within the document by zip code.
> 
> Here's an example of a style sheet that I've tried but the 
> result tree 
> remains in it's original state... 
> 
> <?xml version="1.0"?>
> <!--XML Declaration -->
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
> <xsl:output method="xml" indent="yes" standalone="yes" 
> omit-xml-declaration="no" encoding="UTF-8"/> 
> 
> <xsl:template match="EntryData/Applicant/Address">
>   <xsl:copy>
>     <xsl:apply-templates> 
>      <xsl:sort select="ZipCode"/>
>    </xsl:apply-templates> 
>   </xsl:copy>
> </xsl:template>
> 
> <xsl:template match="*|@*|text()">
>  <xsl:copy>
>    <xsl:apply-templates select="*|@*|text()">
>    </xsl:apply-templates>
>   </xsl:copy>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> Please advise.  
> 
> Thanks,
> Jim McDowall
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.