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

AW: sorting AND copying of XML via XSL

Subject: AW: sorting AND copying of XML via XSL
From: "Hendrik Beck \(Computation SIS GmbH\)" <hendrik.beck@xxxxxxxxxxxxxxxxxx>
Date: Tue, 9 Sep 2003 18:27:40 +0200
sorting xml via xsl
Hi Marcel,


> Now I want to sort the bar elements and then the item elements
according to their Id's, and finally output 
> the entire document sorted, e.g.


Think, there are better and shorter implementations do this, but this
might be one way to come by:


<xsl:output method="xml"/>

<xsl:template match="/foo">
	<xsl:element name="foo">
		<xsl:for-each select="bar">
		<xsl:sort select="@id" order="ascending"></xsl:sort>
         ^^^^^^^^^^^
			<xsl:element name="bar">
				<xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute>
				
				<xsl:for-each select="item">
				<xsl:sort select="@id"
order="ascending"></xsl:sort>
                     ^^^^^^^^^^^
					<xsl:element name="item">
						<xsl:attribute
name="id"><xsl:value-of select="@id"/></xsl:attribute>
						<xsl:value-of
select="item"/>
					</xsl:element>
				</xsl:for-each>
				
			</xsl:element>
		</xsl:for-each>
	</xsl:element>
</xsl:template>


Just put two sorted for-each-loops together and produce the output via
<xsl:element> and <xsl:attribute>. This produces the exactly the xml you
wanted. Or what else problem did you have with it?


Hendrik Beck


 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.