3 <script src=
"../../resources/js-test.js"></script>
4 <script src=
"xpath-test-pre.js"></script>
7 <p>This tests that XPath expressions with prefixes work correctly.
</p>
8 <div id=
"console"></div>
10 var xmlString
= '<ns:foo xmlns:ns="http://www.example.org" xmlns:foo="urn:foobar"/>';
12 var doc
= (new DOMParser()).parseFromString(xmlString
, "text/xml");
13 var contextNode
= doc
.documentElement
;
14 var nsResolver
= document
.createNSResolver(contextNode
);
16 var expr
= doc
.createExpression("/ns:foo", nsResolver
);
17 var result
= expr
.evaluate(contextNode
, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
18 checkSnapshot("/ns:foo", result
, [doc
.documentElement
]);
20 var expr
= doc
.createExpression("/ns:*", nsResolver
);
21 var result
= expr
.evaluate(contextNode
, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
22 checkSnapshot("/ns:*", result
, [doc
.documentElement
]);
24 var expr
= doc
.createExpression("/foo:*", nsResolver
);
25 var result
= expr
.evaluate(contextNode
, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
26 checkSnapshot("/foo:*", result
, []);
28 // Now try a resolver originating from the function
29 var namespaces
= { xmpl
: "http://www.example.org" };
30 var mapResolver = function(prefix
) { return namespaces
[prefix
]; };
32 var expr
= doc
.createExpression("/xmpl:*", mapResolver
);
33 var result
= expr
.evaluate(contextNode
, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
34 checkSnapshot("/xmpl:*", result
, [doc
.documentElement
]);
36 var evaluator
= new XPathEvaluator();
37 var result
= evaluator
.evaluate("/xmpl:*", doc
, mapResolver
, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
38 checkSnapshot("/xmpl:*", result
, [doc
.documentElement
]);