Reputation: 355
my xml file has multiple plant tags in it. Basic code is:
<plant>
<common>snakeroot</common>
<botanical>cimicifuga</botanical>
<zone>5</zone>
<light>shade</light>
<price>$5.63</price>
<availability>071114</availability>
</plant>
I want to sort this file based on price. If i use
<xsl:sort select="//price" data-type="number" order="descending" />
but its not sorting and the reason is i have a dollar sign infront of it. Can someone advice on how to remove it or format it so that i get desired result.
Thanks
Upvotes: 1
Views: 179
Reputation: 122394
If it's always a dollar sign then you could do
<xsl:sort select="substring-after(price, '$')" data-type="number"
order="descending" />
You definitely don't want the leading //
as this makes it an absolute path which will pick out exactly the same sort key value for every single plant
(namely the very first price
element in the entire document), as opposed to a relative path to pick out a price
from within the particular plant
it's looking at at the time.
Upvotes: 1