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

RE: changing the order of xml elements when doing XSLT

Subject: RE: changing the order of xml elements when doing XSLT
From: "Xuegen Jin" <xjin_imi@xxxxxxxxx>
Date: Wed, 18 Apr 2001 23:44:55 -0400
xslt apply templates order
When you call <xsl:apply-templates/> in your <xsl:template match="record">
template, the child elements for "record" are processed in the document
order, irrespective of the order of those matching template declarations. To
have the order you want, you should simple do:

<xsl:template match="record">
   <newrecord>
      <xsl:apply-templates select="c"/>
	<xsl:apply-templates select="b"/>
	<xsl:apply-templates select="a"/>
   </newrecord>
</xsl:template>

or

<xsl:template match="record">
   <newrecord>
      <xsl:apply-templates >
		<xsl:sort select="name()" order="descending" />
	</xsl:apply-templates>
   </newrecord>
</xsl:template>


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Charlie Wu
Sent: Wednesday, April 18, 2001 8:41 PM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  changing the order of xml elements when doing XSLT


hi all..

i have a need to accomplish the following.. i.e. when doing an XSLT over an
XML file.. have the output xml be in a specific order that is NOT the same
as the order in the original XML. i guess it can only be done in the xsl
file somehow.. if at all possible.. but i couldn't figure it out.

to clarify what i mean.. here's an example:

source.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mapper.xsl"?>
<record>
<a>1</a>
<b>2</b>
<c>3</c>
</record>

mapper.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
        <xsl:template match="/">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="record">
	       	<newrecord><xsl:apply-templates/></newrecord>
	</xsl:template>
	<xsl:template match="c">
		<CC>
			<xsl:value-of select="."/>
		</CC>
	</xsl:template>
	<xsl:template match="a">
		<AA><xsl:value-of select="."/></AA>
	</xsl:template>
	<xsl:template match="b">
			<BB>
			<xsl:value-of select="."/>
		</BB>
	</xsl:template>
</xsl:stylesheet>

current output:

<newrecord
xmlns:fo="http://www.w3.org/1999/XSL/Format"><AA>1</AA><BB>2</BB><CC>3</CC><
/newrecord>

desired output:

<newrecord
xmlns:fo="http://www.w3.org/1999/XSL/Format"><CC>3</CC><BB>2</BB><AA>1</AA><
/newrecord>

any ideas would be highly appreciated..

thanks!

Charlie


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


 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.