As part of an XSLT transform, I need to sort the output based on a numeric field. Using the following (simplified) stylesheet:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<root>
<xsl:for-each select="/root/data">
<xsl:sort select="number(order)"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
and this input:
<root>
<data><order>1</order></data>
<data><order>2</order></data>
<data><order>12</order></data>
</root>
I expect the output to have the same order as the input, i.e. "1", "2", "12". However, the transform returns the elements in alphabetical order, i.e. "1", "12", "2". This is not what I would expect. Other implementations (e.g. XML Spy) yield the order I want, but the XSLT implementation shipped with JDeveloper and BPEL Process Manager (SOA Suite 10.1.3.4) seems to always perform an alphabetic sort. Supplying an attribute datatype="number" does not help, either.
I am able to work around the issue by using
<xsl:sort select="format-number('000000', order)"/>
instead, thus converting the number to a zero-padded string and making the alphabetic sort identical to the numerical, but this isn't very satisfactory.
Is this a known issue? Will there be a fix in later versions or patches?