"Anthony Jones" <AnthonyWJones@yadayadayada.comwrote in message
news:e4Dm6y1DJHA.4132@TK2MSFTNGP03.phx.gbl...
Quote:
If this is true its very unsatisfactory. XPath does not define that the
root node should be the Document.
Well, XPath 2.0 does explicitly call that type of node a "document node"
(this of course doesn't mean that it must necessarily be a ***Document class
in .NET). XPath 1.0 calls it a "root node" without further clarification,
but it does specify that it is distinct from element nodes:
http://www.w3.org/TR/xpath#data-model
The tree contains nodes. There are seven types of node:
- root nodes
- element nodes
- text nodes
- attribute nodes
- namespace nodes
- processing instruction nodes
- comment nodes
...
Every node other than the root node has exactly one parent, which is
either an element node or the root node.
...
The root node is the root of the tree. A root node does not occur except
as the root of the tree. The element node for the document element is a
child of the root node. The root node also has as children processing
instruction and comment nodes for processing instructions and comments that
occur in the prolog and after the end of the document element.
...
The root node does not have an expanded-name.
Note that this final requirement clearly marks root node as distinct from
element node. An element node _must_ have a non-empty expanded name (because
you can't have a nameless element in XML).
Quote:
Indeed in many cases its important that it isn't. E.g applying XSL to a
child node in a document should have that child node treated as the root
as far as any XPath present in the XSL is concerned.
The XSLT spec explicitly says that there is always a single root (i.e.,
non-element node) in the source (input) tree, even though it allows that to
have more than one-child (i.e., represent an XML fragment rather than
document), "when the source tree is created in some other way, for example
by using the DOM".