无论出于何种原因,如果我输入源 XML,评估就可以了。但是,如果我使用样式表转换 XML 并且它是 DocumentFragment,它会转到警报(“否”)。有人知道会发生什么吗?也许需要在运行评估之前转换 DocumentFragment?但是为了什么?非常感谢。
doc_trans=xsltProcessor.transformToFragment(doc_xml_source, document);
//var resultDoc=doc_xnl_source;
var resultDoc=doc_trans;
//var path = "/catalog/cd/title"
path="/html/body/table//row";
if (resultDoc.evaluate) {
alert("yes");
var nodes = rDoc.evaluate(path, resultDoc, null, XPathResult.ANY_TYPE, null);
var result = nodes.iterateNext();
while (result) {
alert(result.childNodes[0].nodeValue);
txt += result.childNodes[0].nodeValue + "<br>";
result = nodes.iterateNext();
}
} else {
alert("no");
var evaluator = new XPathEvaluator();
//DocumentFragment not a valid node type exception thrown here...
var resulty = evaluator.evaluate("//tbody/tr", resultDoc, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
alert( resulty.snapshotLength);
}