Thank you, Michael.  Yes, I was looking at the fact that they were comparable (we can use 'eq' and 'ne'), but I missed the fact ordering is based on 'lt' as well.

  Adding it for XPath 3.1 would be a good idea I think, unless there is a good reason to forbid it.  Have you already open a ticket, or do you want me to add one in Bugzilla?

  In a few words, just if that can be of any interest, my use case is an algorithm that makes a comparison of 2 sequences, a bit like deep-equal but customizable (like ignoring or not comments and whitespace-only text nodes), for a unit test framework.  In order to compare the attributes of two elements, I first sort both lists by name so I can recursively compare them 2 by 2.  I will use the 2 keys approach using the namespace URI and the local name.

  Thanks for the answer (sorry it was not specific to Saxon), regards,

Florent Georges

Le Mardi 15 avril 2014 1h34, Michael Kay <> a écrit :
Sadly, there is no ordering defined for the xs:QName type.

"The combinations of atomic types that are accepted by the various value comparison operators, and their respective result types, are listed in B.2 Operator Mapping "

The operator mapping table has no entry for QName lt QName,

[ERR XTDE1030] It is a dynamic error if, for any sort key component, the set of sort key values evaluated for all the items in the initial sequence, after any type conversion requested, contains a pair of ordinary values for which the result of the XPath lt operator is an error.

We're (hopefully) adding ordering comparisons for the binary data types in XPath 3.1. Perhaps we should add one for QNames as well.

Michael Kay

On 14 Apr 2014, at 23:50, Florent Georges <> wrote:


  I am trying to order a list of attributes by name.  So I use a
for-each with a sort on node-name(.), to compare the attribute
names as QNames:

    <xsl:for-each select="$attrs">
       <xsl:sort select="node-name(.)"/>
       <xsl:sequence select="."/>

  But this gives me the following error, even though QName are
comparable (unless I am mistaken):

    XTDE1030: Non-comparable types found while sorting: Values
    are not comparable (xs:QName, xs:QName)

  The following variant works:

    <xsl:for-each select="$attrs">
       <xsl:sort select="namespace-uri(.)"/>
       <xsl:sort select="local-name(.)"/>
       <xsl:sequence select="."/>

  Complete repro:

    <xsl:stylesheet xmlns:xsl=""

          Sort a list of attributes, by name.
       <xsl:function name="my:sort-attrs" as="attribute()*">
          <xsl:param name="attrs" as="attribute()*"/>
          <xsl:for-each select="$attrs">
             <xsl:sort select="node-name(.)"/>
             <xsl:sequence select="."/>

          Output attribute values, with attributes sorted by name.
       <xsl:template name="main">
          <xsl:variable name="elem" as="element()">
             <dummy one="1" two="2" three="3" four="4"/>
          <xsl:value-of select="my:sort-attrs($elem/@*)" separator=", "/>



Florent Georges

Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
saxon-help mailing list archived at