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

Subject: RE: [xsl] Using xsl:sort to sort negative values
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 21 Feb 2007 09:33:49 -0000
>    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>

If data selects anything, then it will select 7 child elements of <xml>, and
a sort key consisting of a sequence of 7 elements is unlikely to be useful.
Chances are you want

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

Incidentally, element names beginning with "xml" are reserved for future
standardization, therefore best avoided.

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

Current Thread