I’m trying to order items based on an attribute value:
<xsl:apply-templates select='Question'> <xsl:sort order='ascending' select='@Value'></xsl:sort> </xsl:apply-templates>
This does order them, but I could have values like 1,2,3, … 10, 11, … 20 and it will order them 1,10,11, … 2,20… 3. etc.
I could also have values like 1.A, 1.B, 2.A, 2.B etc.
How can I order these values to take into account the numeric content and the alphabetic, in that priority?
If you know that every question has a multi-part number, you could handle them with two
<xsl:sort>instructions:If some of the numbers might have multiple parts and some not, I guess the best thing to do is:
The extra
concat(@Value, '.')adds a ‘.‘ to the end of the value so that thesubstring-before()always gets the number.