[xquery-talk] Node sequences and Path Expressions

Michael Kay mhk at mhk.me.uk
Fri Nov 4 10:31:59 PST 2005


> > let $a := <x><y><z/></y></x>
> >   return ($a, $a/*)/* 
> > 
> > Saxon 8.6 ;-) returns :
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <y>
> >    <z/>
> > </y>
> > <z/>
> 
> This order is required by the XPath step semantics (in this case, the
> outer child::* step is relevant): the result has to be returned in
> document order (with duplicates removed).  Since the y element node
> occurs before the z element node in document order (in the mini XML
> fragment bound to variable $a), the order is fixed.

Yes, that's right.

Just to make a two rather subtle points: 

(a) In this case it's the semantics of the "/" operator that impose document
order in the result, not the semantics of the child::* step per se. If the
query were ($a/*, $a)/(z, y) the results would still be in document order (z
after y), even though neither operand is in document order.

(b) the query actually returns a sequence of two element nodes. The result
you showed is the way that a sequence of two element nodes is displayed on
the console when running Saxon from the command line with default
serialization options. The indentation, for example, is not part of the
query result, it's just one of many possible renditions of the result.

Michael Kay
http://www.saxonica.com/




More information about the talk mailing list