Altova Mailing List Archives

Re: [xsl] Using xsl:sort to sort negative values

From: "Sola Awe" <sodana@----------->
Date: 2/21/2007 3:58:00 AM
Hi all,

 Thanks for the reply.  I actually got this resolved.  I really appreciate 
your help.

I made a mistake in my code.



From: Abel Braaksma <>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] 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 

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

     <xsl:output indent="yes" />

     <xsl:template match="/xml">

       <xsl:apply-templates select="data">

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



     <xsl:template match="data">

       <xsl:value-of select="text()"/>

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

Good luck with it,

-- Abel

Sola Awe wrote:
  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


This is the output


I want


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.