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

Re: Using xsl:sort to sort negative values

Subject: Re: Using xsl:sort to sort negative values
From: "Sola Awe" <sodana@xxxxxxxxxxx>
Date: Wed, 21 Feb 2007 03:57:10 +0000
Re:  Using xsl:sort to sort negative values
Hi all,
Thanks for the reply. I actually got this resolved. I really appreciate your help.
I made a mistake in my code.
Thanks,
Sola





From: Abel Braaksma <abel.online@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Using xsl:sort to sort negative values
Date: Tue, 20 Feb 2007 23:09:46 +0100

Hi Sola,

You didn't show your full code and you didn't tell what processor you are using and what XSLT version. If you specifiy "number" for the data-type, then the content is converted to a numeric value. This includes the minus sign.

Note that your data is illegal XML as where legal XML it is not allowed to have any element starting with xml, XML or any combination of case, see http://www.w3.org/TR/xml/#IDAKKFS. However, most XML processors dig it anyway ;)

I tried the following stylesheet and ran it with Saxon 8. It gives the result you want:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:template match="/xml">
<xsl:apply-templates select="data">
<xsl:sort select="." data-type="number" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="data">
<xsl:text>
</xsl:text>
       <xsl:value-of select="text()"/>
   </xsl:template>
  </xsl:stylesheet>


If this does not work with your processor, it is likely a bug.


Good luck with it,

Cheers,
-- Abel



Sola Awe wrote:
Hi,
  Can anyone tell why the code below will not work?

<xsl:sort select="data" data-type="number"/>

I am trying to sort numeric data that contains negative values but the order seems to be wrong

<xml>
<data>22</data>
<data>2</data>
<data>-5</data>
<data>42</data>
<data>0</data>
<data>-1</data>
<data>0</data>
</xml>


This is the output


0
-1
0
-5
2
22
42

I want
-5
-1
0
0
2
22
42

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.