How do i sort a list of numbers using XSL

How do i sort a list of numbers using XSL

Post by Prabakar » Wed, 05 Jul 2000 04:00:00



Hi,
  I have the following XML fragment.
<group>
   <person>
      <name>abc</name>
      <age>1</age>
    </person>
    ...
</group>

I have three other <person> nodes with ages 2, 10 and 11. Now, i use XSL
to represent this data in a table format. I want the rows of the table
to be sorted based on the age.

<xsl:for-each select="//group/person" order-by="age">

But, the order by doesnt seem to work properly. It shows the order as
follows:
1
10
11
2

It looks as though it has done a sort by taking the values as strings
and not numbers.
        How do i make it sort properly ?

Thanks,
Prabakar S

 
 
 

How do i sort a list of numbers using XSL

Post by Kamra » Wed, 05 Jul 2000 04:00:00


Hi Prabakar,

try this:

<xsl:for-each select="//group/person" order-by="number(age)">

good luck

Kamran :-)

In article


Quote:> Hi,
>   I have the following XML fragment.
> <group>
>    <person>
>       <name>abc</name>
>       <age>1</age>
>     </person>
>     ...
> </group>

> I have three other <person> nodes with ages 2, 10 and 11. Now, i use
XSL
> to represent this data in a table format. I want the rows of the table
> to be sorted based on the age.

> <xsl:for-each select="//group/person" order-by="age">

> But, the order by doesnt seem to work properly. It shows the order as
> follows:
> 1
> 10
> 11
> 2

> It looks as though it has done a sort by taking the values as strings
> and not numbers.
>         How do i make it sort properly ?

> Thanks,
> Prabakar S

--
Thanx

Kamran  :-)

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

How do i sort a list of numbers using XSL

Post by Anto » Thu, 06 Jul 2000 04:00:00


order-by is not a standard by the way and is used in the old namespace.
In the new namespace you make use of xsl:sort which is a standard, you
will find that you will not get much help on order-by on MSDN because it
is outdated but...

if you put a number around your order-by like order-by="number(age)"
your problem will be solved.

Cheers.