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

Re: XSL to Sort XML Doc return XML

Subject: Re: XSL to Sort XML Doc return XML
From: "MacEwan, James (Information Services)" <James.MacEwan@xxxxxxxxxxxxxxxxxx>
Date: Fri, 1 Jun 2001 12:23:51 -0500
xsl return xml
Hi Xiaocun and xsl-list,

I am a novice and thought I would try your solution for myself.  I had to
wrap up your xsl a little bit and have produced the following two flavours
of code that work (one with for-each, the other with apply-templates).

for-each flavour:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="/">

<records>
	<xsl:for-each select="records/record">
		<xsl:sort select="."/>
		<record><xsl:value-of select="."/></record>
	</xsl:for-each>
</records>

</xsl:template>

</xsl:stylesheet>

apply-templates flavour:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="records">
	<records><xsl:apply-templates><xsl:sort
select="."/></xsl:apply-templates></records>
</xsl:template>

<xsl:template match="record">
	<record><xsl:value-of select="."/></record>
</xsl:template>

</xsl:stylesheet>

I am at a bit of loss as to which approach would be better (and I don't even
know how to name these two approaches).  Can you recommend a reference/web
tutorial/whatever that will help me better understand the design patterns
being used and when to use which?

Thanks,

J.


> From: Xiaocun Xu [mailto:xiaocunxu@xxxxxxxxx] 
> Sent: Thursday, May 31, 2001 2:49 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  XSL to Sort XML Doc return XML
> Doc ?
> 
> Hi, Matt:
> 
>   This can be done pretty easily with xsl:sort,
> like:
> <records>
> <xsl:for-each select="records/record">
> 	<xsl:sort select="."/>
> 	<record><xsl:value-of select="."/></record>
> </xsl:for-each>
> </records>


James MacEwan
Software Developer
Investors Group Inc.
mailto:James.MacEwan@xxxxxxxxxxxxxxxxxx
v: (204) 956-8515
f: (204) 943-3540


 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.