XPath on DOM nodes not inserted in the owner document
Martin Honnen <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
The XPath data model is defined on a complete document tree and only for nodes in that document tree. The W3C DOM Level 3 XPath note however defines XPath on DOM nodes and with the DOM you can have nodes that are not (currently) inserted in the DOM document tree (e.g. by creating a node with a factory method like createElement and not inserting it in the document or by taking a node in the document and calling node.parentNode.removeChild on the node). Is there any specification that defines how the XPath data model with things like the root node denoted by '/' applies to DOM nodes that have parentNode as being null? Mozilla and Opera 9 behave differently here, with Mozilla the XPath / evaluated relatively to a node with no parent node does not find any node while with Opera 9 the node itself is returned as the "root node". I am considering filing a bug on Opera to have both browser implementing DOM Level 3 XPath behave the same but I would like to know whether the Mozilla implementation of this detail is based on some spec or just the decision of the implementor. A test case is here: <http://home.arcor.de/martin.honnen/javascript/2006/12/test2006120701.html> it runs XPath expressions like /, .., and ancestor::node() first on two nodes inserted in the document, then remove the nodes from the document and runs the XPath expressions again. -- Martin Honnen http://JavaScript.FAQTs.com/