[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] changing the order of xml elements when doing XSLT


Subject: RE: [xsl] changing the order of xml elements when doing XSLT
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 10:40:21 +0100

> 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. 


Do
 <xsl:template match="/">
   <xsl:apply-templates>
     <xsl:sort select="name()"/>
   </xsl:apply-templates>
</xsl:template>

Mike Kay
Software AG

> 
> 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
> 

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



Current Thread
Keywords