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,

XSLT says (

[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