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(
17 test(doc
, doc
.documentElement
, 'child::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1]]);
18 test(doc
, doc
.documentElement
, 'child::*', [doc
.documentElement
.firstChild
, doc
.documentElement
.firstChild
.nextSibling
, doc
.documentElement
.lastChild
]);
20 var doc
= (new DOMParser
).parseFromString(
21 '<doc>This is <i>some</i> text.</doc>',
23 test(doc
, doc
.documentElement
, 'child::text()', [doc
.documentElement
.firstChild
, doc
.documentElement
.lastChild
]);
24 test(doc
, doc
.documentElement
, 'child::node()', [doc
.documentElement
.firstChild
, doc
.documentElement
.firstChild
.nextSibling
, doc
.documentElement
.lastChild
]);
26 var doc
= (new DOMParser
).parseFromString(
27 '<doc name="foo" value="bar" />',
29 test(doc
, doc
.documentElement
, 'attribute::name', [doc
.documentElement
.getAttributeNode("name")]);
30 test(doc
, doc
.documentElement
, 'attribute::*', [doc
.documentElement
.getAttributeNode("name"), doc
.documentElement
.getAttributeNode("value")]);
32 var doc
= (new DOMParser
).parseFromString(
40 test(doc
, doc
.documentElement
, 'descendant::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1]]);
42 var doc
= (new DOMParser
).parseFromString(
53 test(doc
, '//context', 'ancestor::div', [doc
.getElementsByTagName("div")[0], doc
.getElementsByTagName("div")[1]]);
55 var doc
= (new DOMParser
).parseFromString(
64 test(doc
, '//div[@id="3"]', 'ancestor-or-self::div', [doc
.getElementsByTagName("div")[0], doc
.getElementsByTagName("div")[2]]);
66 var doc
= (new DOMParser
).parseFromString(
74 test(doc
, doc
.documentElement
, 'descendant-or-self::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1], doc
.getElementsByTagName("para")[2]]);
76 var doc
= (new DOMParser
).parseFromString(
81 test(doc
, doc
.documentElement
, 'self::para', []);
82 test(doc
, 'para', 'self::para', [doc
.documentElement
.firstChild
]);
84 var doc
= (new DOMParser
).parseFromString(
86 '<chapter><para id="1" /><para id="2" /></chapter>' +
87 '<chapter><section><para id="3" /></section></chapter>' +
91 test(doc
, doc
.documentElement
, 'child::chapter/descendant::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1], doc
.getElementsByTagName("para")[2]]);
93 var doc
= (new DOMParser
).parseFromString(
95 '<chapter><para id="1" /><para id="2" /></chapter>' +
96 '<section><para id="3" /><sub><para id="4" /></sub></section>' +
100 test(doc
, doc
.documentElement
, 'child::*/child::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1], doc
.getElementsByTagName("para")[2]]);
102 var doc
= (new DOMParser
).parseFromString(
103 '<doc><a><b><context /></b></a></doc>',
105 test(doc
, '//context', '/', [doc
]);
107 var doc
= (new DOMParser
).parseFromString(
109 '<para id="1"><context /></para>' +
113 test(doc
, '//context', '/descendant::para', [doc
.getElementsByTagName("para")[0], doc
.getElementsByTagName("para")[1]]);
115 var doc
= (new DOMParser
).parseFromString(
119 '<olist><item id="2" /></olist>' +
121 '<olist><item id="3" /></olist>' +
124 test(doc
, '//context', '/descendant::olist/child::item', [doc
.getElementsByTagName("item")[1], doc
.getElementsByTagName("item")[2]]);
126 var doc
= (new DOMParser
).parseFromString(
133 test(doc
, doc
.documentElement
, 'child::para[position()=1]', [doc
.getElementsByTagName("para")[0]]);
135 var doc
= (new DOMParser
).parseFromString(
142 test(doc
, doc
.documentElement
, 'child::para[position()=last()]', [doc
.getElementsByTagName("para")[1]]);
144 var doc
= (new DOMParser
).parseFromString(
152 test(doc
, doc
.documentElement
, 'child::para[position()=last()-1]', [doc
.getElementsByTagName("para")[1]]);
154 var doc
= (new DOMParser
).parseFromString(
156 '<div id="1" /><para id="2" />' +
157 '<div id="3" /><para id="4" />' +
158 '<div id="5" /><para id="6" />' +
161 test(doc
, doc
.documentElement
, 'child::para[position()>1]', [doc
.getElementsByTagName("para")[1], doc
.getElementsByTagName("para")[2]]);
163 var doc
= (new DOMParser
).parseFromString(
165 '<chapter id="1" /><chapter id="2" />' +
167 '<chapter id="3" /><chapter id="4" />' +
170 test(doc
, '//context', 'following-sibling::chapter[position()=1]', [doc
.getElementsByTagName("chapter")[2]]);
171 test(doc
, '//context', 'preceding-sibling::chapter[position()=1]', [doc
.getElementsByTagName("chapter")[1]]);
174 for (i
= 1; i
<= 10; ++i
) {
175 for (j
= 1; j
<= 10; ++j
)
176 xml
+= '<figure id="' + ((i
*10)+j
) + '%d">';
177 for (j
= 1; j
<= 10; ++j
)
181 var doc
= (new DOMParser
).parseFromString(xml
, 'application/xml');
182 test(doc
, doc
.documentElement
, '/descendant::figure[position()=42]', [doc
.getElementsByTagName("figure")[41]]);
184 var doc
= (new DOMParser
).parseFromString(
186 '<chapter id="1" /><chapter id="2" /><chapter id="3" />' +
188 '<section id="4.1" /><section id="4.2" /><section id="4.3" />' +
191 '<section id="5.1" /><section id="5.2" /><section id="5.3" />' +
195 test(doc
, doc
.documentElement
, '/child::doc/child::chapter[position()=5]/child::section[position()=2]', [doc
.getElementsByTagName("section")[4]]);
197 var doc
= (new DOMParser
).parseFromString(
199 '<para id="1" type="info" />' +
200 '<para id="2" type="warning" />' +
201 '<para id="3" type="warning" />' +
202 '<para id="4" type="warning" />' +
203 '<para id="5" type="error" />' +
204 '<para id="6" type="warning" />' +
205 '<para id="7" type="warning" />' +
208 test(doc
, doc
.documentElement
, 'child::para[attribute::type="warning"][position()=5]', [doc
.getElementsByTagName("para")[6]]);
209 test(doc
, doc
.documentElement
, 'child::para[position()=5][attribute::type="warning"]', []);
211 var doc
= (new DOMParser
).parseFromString(
213 '<chapter id="1" />' +
214 '<chapter id="2"><title>Introduction</title></chapter>' +
215 '<chapter id="3"><title>Body</title></chapter>' +
217 '<title>Another</title>' +
218 '<title>Introduction</title>' +
222 test(doc
, doc
.documentElement
, "child::chapter[child::title='Introduction']", [doc
.getElementsByTagName("chapter")[1], doc
.getElementsByTagName("chapter")[3]]);
224 var doc
= (new DOMParser
).parseFromString(
226 '<chapter id="1" />' +
227 '<chapter id="2"><title /></chapter>' +
228 '<chapter id="3"><title /><title /></chapter>' +
231 test(doc
, doc
.documentElement
, "child::chapter[child::title]", [doc
.getElementsByTagName("chapter")[1], doc
.getElementsByTagName("chapter")[2]]);
233 var doc
= (new DOMParser
).parseFromString(
235 '<chapter id="1" />' +
236 '<appendix id="2" />' +
238 '<chapter id="4" />' +
241 test(doc
, doc
.documentElement
, "child::*[self::chapter or self::appendix]", [doc
.getElementsByTagName("chapter")[0], doc
.getElementsByTagName("appendix")[0], doc
.getElementsByTagName("chapter")[1]]);
243 var doc
= (new DOMParser
).parseFromString(
245 '<chapter id="1" />' +
246 '<appendix id="2" />' +
248 '<chapter id="4" />' +
252 test(doc
, doc
.documentElement
, "child::*[self::chapter or self::appendix][position()=last()]", [doc
.getElementsByTagName("chapter")[1]]);