Re: XPath difference between <xsl:output method="html"> and "xml"
Martin Honnen <[email protected]> Thu, 12 Apr 2007 14:13:09 +0200
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
C.W.Holeman II wrote:
> How do I locate the body element with XPath?
With XPath 1.0 if you have a path
element-name
(or e.g. body) then the XPath expression selects elements of that name
(e.g element-name or body) in _no_ namespace while XHTML elements are in
the namespace http://www.w3.org/1999/xhtml. To select elements in a
namespace you need to bind a prefix (e.g. 'xhtml) to the namespace URI
and use that prefix in your expression (e.g. xhtml:body). So with the
W3C DOM Level 3 XPath API you use a namespace resolver as follows
var body = document.evaluate(
"//xhtml:body",
document,
function lookupNamespaceURI (prefix) {
switch (prefix) {
case 'xhtml':
return 'http://www.w3.org/1999/xhtml';
}
}, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
--
Martin Honnen
http://JavaScript.FAQTs.com/