RE: [xsl] how to sort a union using number()?

Subject: RE: [xsl] how to sort a union using number()?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 16 Mar 2007 00:01:05 -0000
> I encountered a point where I needed to apply templates to a 
> union of nodes, sorting them on a common element.
> 
> The naive approach was (XPaths radically simplified for brevity):
> 
> <xsl:apply-templates
>      select="Classifier.feature/Attribute|$associations">
>   <xsl:sort
>        select="number(NumberString|$associations/NumberString)"/>
> </xsl:apply-templates>

Remember that the sort key is evaluated once for each node in the sequence
being sorted, with that node as the context node. And of course, the system
has no idea by the time it evaluates the sort key which "half" of the union
the node came from. So including $a/Numberstring in the sort key, when $a is
the sequence you are sorting, is going to give strange results.

I haven't seen your data, but I suspect you just want

<xsl:sort select="number(NumberString)"/>

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

Current Thread