- From: Michael Brundage <xquery@comcast.net>
- Date: Tue, 23 Sep 2003 08:04:39 -0700
- To: "'Jan Hidders'" <jan.hidders@ua.ac.be>, <www-ql@w3.org>
Hi Jan, I don't know about the formal semantics, but the main language spec defines the behavior quite clearly. Document order doesn't play a role in your query. FLWOR does not automatically apply document ordering to its result. For example, the query let $tree := (<y id="1"/>, <y id="2"/>) return $tree[2], $tree[1] always results in <y id="2"/><y id="1"/> When ordering a FLWOR that has no "order by" clause, all that matters are the orders of the for bindings. This is explained in section 3.8.1 of the current spec: http://www.w3.org/TR/xquery/#id-for-let Completely separately from this, every node in the data model is ordered relative to every other one. Your query happens to be creating a sequence of c elements, each in its own fragment. Consider the two queries below: let $tree1 := (<x><y/><y/></x>)/y return $tree1[1] << $tree1[2] always returns true. The two y child elements of x are siblings of one another, and the first one always comes before the second in document order. However, this query: let $tree2 := (<y/>, <y/>) return $tree[1] << $tree[2] may return true or false (and the result may even vary when executed multiple times on the same implementation). The two y elements are unrelated to one another. Each resides in a different fragment, and the relative order of nodes in different fragments is implementation-dependent (but stable within the execution of a single query). See section 2.3.1 of the current spec http://www.w3.org/TR/xquery/#N108C2 [Combine them into a single query: let $unrelated := (<y/>, <y/>) let $related := (<x>{$unrelated}</x>)/y return $related[1] << $related[2], (: always true :) $unrelated[1] << $unrelated[2] (: implementation-dependent :) and you have one of the examples from my book.] Hope that helps, Michael Brundage xquery@comcast.net Writing as Author, "XQuery: The XML Query Language" (Addison-Wesley, to appear 2003) Co-author, "Professional XML Databases" (Wrox Press, 2000) not as Technical Lead Common Query Runtime/XML Query Processing WebData XML Team Microsoft -----Original Message----- From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of Jan Hidders Sent: Tuesday, September 23, 2003 6:35 AM To: www-ql@w3.org Subject: creation order vs. document order L.S., I have a question regarding the place in the document order of newly created element nodes. Suppose I have a join-like query like the following: for $a in $list1 for $b in $list2 where $a/name = $b/name return <c> $a, $b </c> Must the result of this always be a list that is sorted in document order? Intuitively I would expect them to be sorted in the order in which they were created, but as far as I can tell the formal semantics leaves this unspecified. -- Jan Hidders .---------------------------------------------------------------------. | Post-doctoral researcher e-mail: jan.hidders@ua.ac.be | | Dept. Math. & Computer Science tel: (+32) 3 218 08 73 | | University of Antwerp fax: (+32) 3 218 07 77 | | Middelheimlaan 1, BE-2020 Antwerpen, BELGIUM room: G 3.21 | `---------------------------------------------------------------------'
Received on Tuesday, 23 September 2003 10:58:30 UTC