Dave Brosius wrote:
Hello

Is there any guarantee as to the order or returned nodes in an xpath query, say the path is

//Foo

Are the nodes guaranteed to be depth-first, breadth-first, other, or no guarantee at all?

In XPath 1.0, node sets are unordered:

http://www.w3.org/TR/xpath#section-Introduction

"The primary syntactic construct in XPath is the expression. An expression matches the production Expr. An expression is evaluated to yield an object, which has one of the following four basic types:

    * node-set (an unordered collection of nodes without duplicates)
    * boolean (true or false)
    * number (a floating-point number)
    * string (a sequence of UCS characters)"

That said, I suspect most implementations will deliver them in document order, given the requirements of XSLT 1.0.

Note that predicates have an interesting twist:

http://www.w3.org/TR/xpath#node-sets

"3.3 Node-sets

A location path can be used as an expression. The expression returns the set of nodes selected by the path.

The | operator computes the union of its operands, which must be node-sets.

Predicates are used to filter expressions in the same way that they are used in location paths. It is an error if the expression to be filtered does not evaluate to a node-set. The Predicate filters the node-set with respect to the child axis.

NOTE: The meaning of a Predicate depends crucially on which axis applies. For example, preceding::foo[1] returns the first foo element in reverse document order, because the axis that applies to the [1] predicate is the preceding axis; by contrast, (preceding::foo)[1] returns the first foo element in document order, because the axis that applies to the [1] predicate is the child axis."

Dave

Reply via email to