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

RE: Problem with sort order

Subject: RE: Problem with sort order
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 22 Aug 2006 21:20:04 +0100
xsl reserved order
You need to do two passes: construct the output, then sort it.

You can either do that in a single stylesheet (in XSLT 1.0 you'll need the
xx:node-set() extension), or in two stylesheets chained together in a
pipeline.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Per Eberg [mailto:aberg.per@xxxxxxxx]
> Sent: 22 August 2006 19:23
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Problem with sort order
>
> Hi,
>
> In my xslt file, I want to examine the attributes of the xml
> elements, transform some of them (if needed), and then sort
> the output after the attributes. My problem is that the
> transformed attributes become sorted after their "ingoing"
> value instead of their new value. The following invented
> example shows the problem. According to the xsl 1.0 specs the
> output of the transformation should be sorted, but here it
> seems like the input is being sorted. Does anyone know how I
> can get it right?
>
> Thanks in advance,
> Per
>
> The xml-file:
>
> <?xml version="1.0" encoding="utf-8"?>
> <?xml-stylesheet type="text/xsl" href="xslt_file.xsl"?> <animal>
>     <species>
>         <name language="English">Wolf</name>
>         <name language="Spanish">Lobo</name>
>         <name language="Danish">Canis Lupus</name>
>         <name language="French">Loup</name>
>     </species>
> </animal>
>
> The xsl-file:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>     <xsl:output method="xml"/>
>     <xsl:template match="/animal">
>         <animal>
>             <xsl:apply-templates select="species"/>
>         </animal>
>     </xsl:template>
>     <xsl:template match="species">
>         <species>
>             <xsl:for-each select="name">
>             <xsl:sort select="@language"/>
>                <xsl:choose>
>                     <xsl:when test="@language='Danish'">
>                         <name language="Latin"><xsl:value-of
> select="."/></name>
>                     </xsl:when>
>                     <xsl:otherwise>
>                         <name language="{@language}"><xsl:value-of
> select="."/></name>
>                     </xsl:otherwise>
>                 </xsl:choose>
>             </xsl:for-each>
>         </species>
>     </xsl:template>
> </xsl:stylesheet>
>
> The output:
>
> <animal>
>      <species>
>           <name language="Latin">Canis Lupus</name>
>           <name language="English">Wolf</name>
>           <name language="French">Loup</name>
>           <name language="Spanish">Lobo</name>
>      </species>
> </animal>
>
> The desired output:
>
> <animal>
>      <species>
>           <name language="English">Wolf</name>
>           <name language="French">Loup</name>
>           <name language="Latin">Canis Lupus</name>
>           <name language="Spanish">Lobo</name>
>      </species>
> </animal>

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.