By default xslt sorts numerically then alphabetically. What if I want alphabetically first then numerically.
<root>
<item>B3</item>
<item>A1</item>
<item>C2</item>
<item>3B</item>
<item>2C</item>
<item>1A</item>
</root>
I'd want:
<root>
<item>A1</item>
<item>B3</item>
<item>C2</item>
<item>1A</item>
<item>2C</item>
<item>3B</item>
</root>
The thing is I don't know how long or how many letters numbers are in the names. It could be 1054-FS or C104-G. Also C20-H should comme before C101-H.
Is that something easy to achieve without knowledge of what will be pushed through ?
Thanks.
I think that what you are saying is that you want a collation sequence in which letters precede digits.
If you want C20 to precede C101 then you are also looking for a collation that groups consecutive digits and sorts them as numbers.
It's incorrect to say that XSLT (always) sorts digits before letters. The default collation depends on the XSLT processor you are using, it's not defined in the language specification.
In XSLT 3.0, and in Saxon 9.6, you can use the Unicode Collation Algorithm to achieve this effect. You would write
<xsl:sort select="..."
collation="http://www.w3.org/2013/collation/UCA?numeric=yes;reorder=Latn,digit"/>
(I haven't tested this specific example).
If you're using some other processor, you'll have to check its documentation to see what collation options it provides. You can sometimes play tricks for example by using <xsl:sort select="translate(....)"/>
to compute a sort key that works the way you want.