What is going on here is that the results of the path expression
$test/self::object/@object-id is being returned in document order.
However, what you have is three independent nodes, and document
order is undefined in such a case.  If you want to force a guaranteed
order, you need to put them in the same "document", for example:

let $test :=
<root>
   <object object-id="a"/>
   <object object-id="b"/>
   <object object-id="c"/>
</root>

with the corresponding change to the path expression.

//Mary

On Tue, 28 Apr 2009 02:52:08 -0700, Geert Josten <[email protected]> wrote:

Hi,

I was testing code that returned a sorted sequence of nodes, but my test cases were failing irratically. It took me some time to figure out the exact cause, but it looks like the order of sorted node sets is not maintained properly. I think that it should be maintained, and am failing to see a logical reason for this behaviour. Contrarely, the order of sorted sequences of atomic values is mainted properly.

Anyone observed this behaviour before? Anyone who would like to comment on this behaviour? Is there a logical explanation? The declare ordering doesn't seem to influence this behaviour. Should it?

Here the code to reproduce the problem. Run it multiple times in CQ to see what happens..

        xquery version "1.0";

declare default function namespace "http://www.w3.org/2005/xpath-functions";;

        declare ordering ordered;
        declare default order empty least;
        declare construction preserve;

        let $test := (
          <object object-id="a"/>,
          <object object-id="b"/>,
          <object object-id="c"/>
        )

        return (
          '>>Predictable order<<',

          $test/self::object/@object-id/string(.),

          '>>Unpredictable order<<',

          for $id in $test/self::object/@object-id
          return
                string($id)
        )

Kind regards,
Geert

[email protected]
Principal Engineer
Mark Logic Corporation
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to