xsl-list
[Top] [All Lists]

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

2007-03-15 17:01:22

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/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>