Sadly, there is no ordering defined for the xs:QName type.

See http://www.w3.org/TR/xquery-30/#id-value-comparisons

"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 (http://www.w3.org/TR/xslt-30/#comparing-sort-keys)

[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
Saxonica



On 14 Apr 2014, at 23:50, Florent Georges <lists@fgeorges.org> wrote:

  Hi,

  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="."/>
    </xsl:for-each>

  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="."/>
    </xsl:for-each>

  Complete repro:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:my="..."
                    version="2.0">

       <!--
          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="."/>
          </xsl:for-each>
       </xsl:function>

       <!--
          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:variable>
          <xsl:value-of select="my:sort-attrs($elem/@*)" separator=", "/>
       </xsl:template>

    </xsl:stylesheet>

  Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/


------------------------------------------------------------------------------
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!
http://p.sf.net/sfu/NeoTech_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help