3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"../xpath-test-pre.js"></script>
7 <div id=
"console"></div>
10 var doc
= (new DOMParser
).parseFromString(
12 '<item id="1" color="red" />' +
14 '<item id="2" color="blue" />' +
19 var ROOT
= doc
.documentElement
;
20 var DI1
= ROOT
.firstChild
;
21 var DC1
= DI1
.nextSibling
;
22 var DI2
= DC1
.firstChild
;
24 var docns
= (new DOMParser
).parseFromString(
25 '<doc xmlns="http://a.example.com" xmlns:b="http://b.example.com">' +
26 '<item id="1" color="red"/>' +
27 '<a:item id="2" xmlns:a="http://a.example.com" a:color="orange"/>' +
28 '<b:item id="3" color="yellow" />' +
29 '<item id="4" xmlns="http://a.example.com" color="green"/>' +
30 '<chapter id="c1" xmlns="http://b.example.com">' +
31 '<item id="5" color="blue" />' +
32 '<b:item id="6" b:color="indigo"/>' +
34 '<chapter id="c2" xmlns="http://b.example.com" xmlns:b="http://a.example.com">' +
35 '<item id="7" b:color="violet"/>' +
36 '<b:item id="8" a:color="brown" xmlns:a="http://b.example.com"/>' +
41 var XROOT
= docns
.firstChild
;
42 var XI1
= XROOT
.firstChild
;
43 var XI2
= XI1
.nextSibling
;
44 var XI3
= XI2
.nextSibling
;
45 var XI4
= XI3
.nextSibling
;
46 var XC1
= XI4
.nextSibling
;
47 var XI5
= XC1
.firstChild
;
48 var XI6
= XI5
.nextSibling
;
49 var XC2
= XC1
.nextSibling
;
50 var XI7
= XC2
.firstChild
;
51 var XI8
= XI7
.nextSibling
;
53 function nsResolver(prefix
)
56 return "http://b.example.com";
58 return "http://a.example.com";
62 // Some of these tests originally used a default namespace, which is not available in JavaScript XPathEvaluator.
63 test(doc
, doc
, '/descendant::item', [DI1
, DI2
]);
64 test(docns
, docns
, '/descendant::a:item', [XI1
, XI2
, XI4
, XI8
], nsResolver
);
65 test(docns
, docns
, '/descendant::b:*', [XI3
, XC1
, XI5
, XI6
, XC2
, XI7
], nsResolver
);
66 shouldThrow('docns.evaluate("//x:*", docns, nsResolver, XPathResult.ANY_TYPE, null)');
67 test(doc
, doc
, 'doc/child::*', [DI1
, DC1
]);
68 test(docns
, docns
, 'a:doc/child::*', [XI1
, XI2
, XI3
, XI4
, XC1
, XC2
], nsResolver
);
69 test(doc
, doc
, '//attribute::color', [DI1
.getAttributeNode("color"), DI2
.getAttributeNode("color")]);
70 test(docns
, docns
, '//attribute::color', [XI1
.getAttributeNode("color"), XI3
.getAttributeNode("color"), XI4
.getAttributeNode("color"), XI5
.getAttributeNode("color")], nsResolver
);
71 test(docns
, docns
, '//attribute::b:*', [XI6
.getAttributeNodeNS("http://b.example.com", "color"), XI8
.getAttributeNodeNS("http://b.example.com", "color")], nsResolver
);
72 test(doc
, doc
, '//attribute::*', [DI1
.getAttributeNode("id"), DI1
.getAttributeNode("color"), DC1
.getAttributeNode("id"), DI2
.getAttributeNode("id"), DI2
.getAttributeNode("color")]);
73 test(docns
, docns
, 'count(//attribute::*)', 18, nsResolver
);
76 var doc
= (new DOMParser
).parseFromString(
77 '<doc><element />text<?one pi?><?two pi?><!--comment--></doc>',
80 var ROOT
= doc
.documentElement
;
81 var TEXT
= ROOT
.firstChild
.nextSibling
;
82 var COMMENT
= ROOT
.lastChild
;
83 var PI1
= TEXT
.nextSibling
;
84 var PI2
= PI1
.nextSibling
;
86 test(doc
, doc
, 'doc/child::text()', [TEXT
]);
87 test(doc
, doc
, 'doc/child::comment()', [COMMENT
]);
88 test(doc
, doc
, 'doc/child::processing-instruction()', [PI1
, PI2
]);
89 test(doc
, doc
, 'doc/child::processing-instruction("one")', [PI1
]);