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
http://fgeorges.org/
http://h2oconsulting.be/

Le Mardi 15 avril 2014 1h34, Michael Kay <mike@saxonica.com> 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
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