, XPath EXSLT. javascript, EXSLT, , exslt, in-browser.javascript. , .
Firefox, , Saxon-B XSLT2.0 Saxon-B exslt ( Saxon-HE), , , XSLT/XPath 2.0. , , . , , Mozilla Saxon-B, , Chrome .
, - EXSLT XPath. DOM 3 XPath XPath 1.0 EXSLT. , INVALID_EXPRESSION_ERR :
if the expression has a syntax error or otherwise is not a legal expression according to the rules of the specific XPathEvaluator or contains specialized extension functions or variables not supported by this implementation.
, bugzilla Firefox, EXSLT DOM 3 XPath. , NEW 2007 . , :
Currently Mozilla gives an exception "The expression is not a legal expression." even if a namespace resolver correctly resolving the EXSLT prefixes to the corresponding URLs is passed in. .
-
, , ? , XPath?
-
UPDATE. XPath XSLT ( ), , , . XSLT , , .
, Mozilla ( Chrome) XSLT XML, , DOM . XSLTProcessor , tranformToFragment(), , will only produce HTML DOM objects if the owner document is itself an HTMLDocument, or if the output method of the stylesheet is HTML.
XPath, , :
1) XSLT .
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:regexp="http://exslt.org/regular-expressions"
extension-element-prefixes="regexp">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
JavaScript document.implementation.createDocument APi, , . FF - document.load, Chrome XHR. Chrome --allow-file-access-from-files, XHR .
2) , select xsl:copy-of XPath, :
function runXPath(xpath) {
var processor = new XSLTProcessor();
var xsltns = 'http://www.w3.org/1999/XSL/Transform';
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", "xpathrunner.xslt", false);
xmlhttp.send(null);
var transform = xmlhttp.responseXML.documentElement;
var copyof = transform.getElementsByTagNameNS(xsltns, 'copy-of')[0];
copyof.setAttribute('select', xpath);
processor.importStylesheet(transform);
var body = document.getElementById('body');
return processor.transformToFragment(body, document);
}
- :
var nodes = runXPath('//div[@id]');
console.log(nodes.hasChildNodes());
if (nodes.firstChild) {
console.log(nodes.firstChild.localName);
}
"" XPath, //div[@id] ( //div[@not-there]) , regexp:test. //div[regexp:test(string(@id), "a")] , .
Mozilla XSLT- EXSLT. , libxml/libxslt . , Mozilla.
, .
, jQuery regexp? XPath builder, HTML.