0

I'm try to understand how saxon processor selecting ascending order.

I have xml like follows,

<catalog>
    <cd>
        <title lan="en">Empire Burlesque</title>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title lan="en">Hide your heart</title>
        <price> </price>
        <year>1988</year>
    </cd>
    <cd>
        <title lan="fr">Greatest Hits</title>
        <price>13.90</price>
        <year>1982</year>
    </cd>
    <cd>
        <title lan="sp">Still got the blues</title>
        <price>abc</price>
        <year>1990</year>
    </cd>
    <cd>
        <title lan="fr">Eros</title>
        <price>24.90</price>
        <year>1997</year>
    </cd>
</catalog>

when I sort this by price I it give me following results. note that I put empty string to one price value and string 'abc' no another price value.

<catalog>
       <cd>
            <title lan="en">Hide your heart</title>
            <price> </price>
            <year>1988</year>
        </cd>        
        <cd>
            <title lan="en">Empire Burlesque</title>
            <price>10.90</price>
            <year>1985</year>
        </cd>

        <cd>
            <title lan="fr">Greatest Hits</title>
            <price>13.90</price>
            <year>1982</year>
        </cd>

        <cd>
            <title lan="fr">Eros</title>
            <price>24.90</price>
            <year>1997</year>
        </cd>
        <cd>
            <title lan="sp">Still got the blues</title>
            <price>abc</price>
            <year>1990</year>
        </cd>    
</catalog>

It seems empty string has comes first, then price has numbers, have sorted as expected and price has string value, has comes first,

How this order decides by Saxon processor??

2 Answers 2

1

when I sort this by price I it give me following results

It will give you the result you show only if you are sorting alphabetically - i.e. treating the contents of price as text. You will get a different result if you sort as:

<xsl:sort select="price" data-type="number" order="ascending"/>

In this case, all the values that cannot be converted to numbers will come first.

Note that the default data-type for sorting is text - and unless you override it explicitly1, you will also see the price of "9.00" sorted after "100.00".


(1) or if you have a schema defining price as a numeric data-type, and you are using a schema-aware processor.

Sign up to request clarification or add additional context in comments.

1 Comment

More specifically: XSLT 2.0 says the default order is implementation-dependent. In the Saxon implementation, the default order is by Unicode code values. If you want numeric sorting, using data-type="number" works well. If you have a mixture of text and numeric, specifying collation="http://saxon.sf.net/collation?alphanumeric=yes might give the best results - though I'm not sure whether it handles decimal numbers as well as integers.
1

Its sorting natural order as like others. Space <32> coming first and numbers 0-9 <48-57> then alphabets. See ASCII Code - The extended ASCII table

enter image description here

2 Comments

There is no such thing as a "natural" order. And even alphabetical order does not always follow ASCII order.
Regardless of the encoding of an XML document, all characters are translated and processed as Unicode. And, since, as your linked web page says, "There are several different variations of the 8-bit [Extended ]ASCII table," it does little good to hold one out as an unnamed standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.