[xpath] non-document root nodes

Section 3.2 of XPath 2.0 states:

A "/" at the beginning of a path expression is an abbreviation for the 
initial step fn:root(self::node()) treat as document-node() (this is 
true even if the "/" is the entire path expression). The effect of this 
initial step is to begin the path at the root node of the tree that 
contains the context node. If the context item is not a node, a type 
error is raised.[err:XP0020] At evaluation time, if the root node above 
the context node is not a document node, a dynamic error is 
raised.[err:XP0050]

A "//" at the beginning of a path expression is an abbreviation for the 
initial steps fn:root(self::node()) treat as 
document-node()/descendant-or-self::node()/. The effect of these initial 
steps is to establish an initial node sequence that contains the root of 
the tree in which the context node is found, plus all nodes descended 
from this root. This node sequence is used as the input to subsequent 
steps in the path expression. If the context item is not a node, a type 
error is raised.[err:XP0020] At evaluation time, if the root node above 
the context node is not a document node, a dynamic error is 
raised.[err:XP0050]


I'm concerned about the last two sentences of each of these paragraphs.

In XOM, in XPath 1, I've found it useful to query trees with no document 
nodes above them by inserting a sort of pseudo-document node. This makes 
expressions like /a/b/c meaningful, whether or not the context node is 
in a document. However, this pseudo-root is never actually returned. For 
instance the expression / would return an empty list rather than this 
pseudo-root. I'm just not sure an error should be raised here. The 
principle of least surprise would seem to dictate that users can always 
begin expressions that use / and // regardless of the context node, 
especially since most of those expressions will not actually be trying 
to find the root node, just work down from there to something else in 
the tree.

Practically, in the case of DOM, I wonder what happens if the root node 
is a DocumentFragment rather than a Document. perhaps that's just 
treated as another document node for XPath 2.0's purpose?

-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

Received on Friday, 25 February 2005 15:13:42 UTC