• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<link rel="stylesheet" href="../../js/resources/js-test-style.css">
4<script src="../../js/resources/js-test-pre.js"></script>
5<script src="../xpath-test-pre.js"></script>
6</head>
7<body>
8<div id="console"></div>
9
10<script>
11var doc = (new DOMParser).parseFromString(
12    '<doc>' +
13        '<para id="1" />' +
14        '<div id="2" />' +
15        '<para id="3" />' +
16   '</doc>',
17    'application/xml');
18test(doc, doc.documentElement, 'child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
19test(doc, doc.documentElement, 'child::*', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
20
21var doc = (new DOMParser).parseFromString(
22    '<doc>This is <i>some</i> text.</doc>',
23    'application/xml');
24test(doc, doc.documentElement, 'child::text()', [doc.documentElement.firstChild, doc.documentElement.lastChild]);
25test(doc, doc.documentElement, 'child::node()', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
26
27var doc = (new DOMParser).parseFromString(
28    '<doc name="foo" value="bar" />',
29    'application/xml');
30test(doc, doc.documentElement, 'attribute::name', [doc.documentElement.getAttributeNode("name")]);
31test(doc, doc.documentElement, 'attribute::*', [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]);
32
33var doc = (new DOMParser).parseFromString(
34    '<doc>' +
35        '<para id="1">' +
36            '<div id="2" />' +
37            '<para id="3" />' +
38        '</para>' +
39   '</doc>',
40    'application/xml');
41test(doc, doc.documentElement, 'descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
42
43var doc = (new DOMParser).parseFromString(
44    '<doc>' +
45        '<div id="1">' +
46            '<div id="2">' +
47                '<context />' +
48            '</div>' +
49            '<div id="3" />' +
50        '</div>' +
51        '<div id="4" />' +
52   '</doc>',
53    'application/xml');
54test(doc, '//context', 'ancestor::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[1]]);
55
56var doc = (new DOMParser).parseFromString(
57    '<doc>' +
58        '<div id="1">' +
59            '<div id="2" />' +
60            '<div id="3" />' +
61        '</div>' +
62        '<div id="4" />' +
63   '</doc>',
64    'application/xml');
65test(doc, '//div[@id="3"]', 'ancestor-or-self::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[2]]);
66
67var doc = (new DOMParser).parseFromString(
68    '<para id="0">' +
69        '<div id="1" />' +
70        '<para id="2">' +
71            '<para id="3" />' +
72        '</para>' +
73   '</para>',
74    'application/xml');
75test(doc, doc.documentElement, 'descendant-or-self::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
76
77var doc = (new DOMParser).parseFromString(
78    '<doc>' +
79        '<para />' +
80   '</doc>',
81    'application/xml');
82test(doc, doc.documentElement, 'self::para', []);
83test(doc, 'para', 'self::para', [doc.documentElement.firstChild]);
84
85var doc = (new DOMParser).parseFromString(
86    '<doc>' +
87        '<chapter><para id="1" /><para id="2" /></chapter>' +
88        '<chapter><section><para id="3" /></section></chapter>' +
89        '<para id="4" />' +
90   '</doc>',
91    'application/xml');
92test(doc, doc.documentElement, 'child::chapter/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
93
94var doc = (new DOMParser).parseFromString(
95    '<doc>' +
96        '<chapter><para id="1" /><para id="2" /></chapter>' +
97        '<section><para id="3" /><sub><para id="4" /></sub></section>' +
98        '<para id="4" />' +
99   '</doc>',
100    'application/xml');
101test(doc, doc.documentElement, 'child::*/child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
102
103var doc = (new DOMParser).parseFromString(
104    '<doc><a><b><context /></b></a></doc>',
105    'application/xml');
106test(doc, '//context', '/', [doc]);
107
108var doc = (new DOMParser).parseFromString(
109    '<doc>' +
110        '<para id="1"><context /></para>' +
111        '<para id="2" />' +
112   '</doc>',
113    'application/xml');
114test(doc, '//context', '/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
115
116var doc = (new DOMParser).parseFromString(
117    '<doc>' +
118        '<item id="1">' +
119            '<context />' +
120            '<olist><item id="2" /></olist>' +
121        '</item>' +
122        '<olist><item id="3" /></olist>' +
123   '</doc>',
124    'application/xml');
125test(doc, '//context', '/descendant::olist/child::item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]);
126
127var doc = (new DOMParser).parseFromString(
128    '<doc>' +
129        '<div id="1" />' +
130        '<para id="2" />' +
131        '<para id="3" />' +
132   '</doc>',
133    'application/xml');
134test(doc, doc.documentElement, 'child::para[position()=1]', [doc.getElementsByTagName("para")[0]]);
135
136var doc = (new DOMParser).parseFromString(
137    '<doc>' +
138        '<para id="1" />' +
139        '<para id="2" />' +
140        '<div id="3" />' +
141   '</doc>',
142    'application/xml');
143test(doc, doc.documentElement, 'child::para[position()=last()]', [doc.getElementsByTagName("para")[1]]);
144
145var doc = (new DOMParser).parseFromString(
146    '<doc>' +
147        '<para id="1" />' +
148        '<para id="2" />' +
149        '<para id="3" />' +
150        '<div id="4" />' +
151   '</doc>',
152    'application/xml');
153test(doc, doc.documentElement, 'child::para[position()=last()-1]', [doc.getElementsByTagName("para")[1]]);
154
155var doc = (new DOMParser).parseFromString(
156    '<doc>' +
157        '<div id="1" /><para id="2" />' +
158        '<div id="3" /><para id="4" />' +
159        '<div id="5" /><para id="6" />' +
160   '</doc>',
161    'application/xml');
162test(doc, doc.documentElement, 'child::para[position()>1]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
163
164var doc = (new DOMParser).parseFromString(
165    '<doc>' +
166        '<chapter id="1" /><chapter id="2" />' +
167        '<context />' +
168        '<chapter id="3" /><chapter id="4" />' +
169   '</doc>',
170    'application/xml');
171test(doc, '//context', 'following-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[2]]);
172test(doc, '//context', 'preceding-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[1]]);
173
174var xml = "<doc>"
175for (i = 1; i <= 10; ++i) {
176    for (j = 1; j <= 10; ++j)
177        xml += '<figure id="' + ((i*10)+j) + '%d">';
178    for (j = 1; j <= 10; ++j)
179        xml += '</figure>';
180}
181xml += "</doc>"
182var doc = (new DOMParser).parseFromString(xml, 'application/xml');
183test(doc, doc.documentElement, '/descendant::figure[position()=42]', [doc.getElementsByTagName("figure")[41]]);
184
185var doc = (new DOMParser).parseFromString(
186    '<doc>' +
187        '<chapter id="1" /><chapter id="2" /><chapter id="3" />' +
188        '<chapter id="4">' +
189          '<section id="4.1" /><section id="4.2" /><section id="4.3" />' +
190        '</chapter>' +
191        '<chapter id="5">' +
192          '<section id="5.1" /><section id="5.2" /><section id="5.3" />' +
193        '</chapter>' +
194   '</doc>',
195    'application/xml');
196test(doc, doc.documentElement, '/child::doc/child::chapter[position()=5]/child::section[position()=2]', [doc.getElementsByTagName("section")[4]]);
197
198var doc = (new DOMParser).parseFromString(
199    '<doc>' +
200        '<para id="1" type="info" />' +
201        '<para id="2" type="warning" />' +
202        '<para id="3" type="warning" />' +
203        '<para id="4" type="warning" />' +
204        '<para id="5" type="error" />' +
205        '<para id="6" type="warning" />' +
206        '<para id="7" type="warning" />' +
207   '</doc>',
208    'application/xml');
209test(doc, doc.documentElement, 'child::para[attribute::type="warning"][position()=5]', [doc.getElementsByTagName("para")[6]]);
210test(doc, doc.documentElement, 'child::para[position()=5][attribute::type="warning"]', []);
211
212var doc = (new DOMParser).parseFromString(
213    '<doc>' +
214        '<chapter id="1" />' +
215        '<chapter id="2"><title>Introduction</title></chapter>' +
216        '<chapter id="3"><title>Body</title></chapter>' +
217        '<chapter id="4">' +
218            '<title>Another</title>' +
219            '<title>Introduction</title>' +
220        '</chapter>' +
221    '</doc>',
222    'application/xml');
223test(doc, doc.documentElement, "child::chapter[child::title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]);
224
225var doc = (new DOMParser).parseFromString(
226    '<doc>' +
227        '<chapter id="1" />' +
228        '<chapter id="2"><title /></chapter>' +
229        '<chapter id="3"><title /><title /></chapter>' +
230    '</doc>',
231    'application/xml');
232test(doc, doc.documentElement, "child::chapter[child::title]", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[2]]);
233
234var doc = (new DOMParser).parseFromString(
235    '<doc>' +
236        '<chapter id="1" />' +
237        '<appendix id="2" />' +
238        '<para id="3" />' +
239        '<chapter id="4" />' +
240    '</doc>',
241    'application/xml');
242test(doc, doc.documentElement, "child::*[self::chapter or self::appendix]", [doc.getElementsByTagName("chapter")[0], doc.getElementsByTagName("appendix")[0], doc.getElementsByTagName("chapter")[1]]);
243
244var doc = (new DOMParser).parseFromString(
245    '<doc>' +
246        '<chapter id="1" />' +
247        '<appendix id="2" />' +
248        '<para id="3" />' +
249        '<chapter id="4" />' +
250        '<para id="5" />' +
251    '</doc>',
252    'application/xml');
253test(doc, doc.documentElement, "child::*[self::chapter or self::appendix][position()=last()]", [doc.getElementsByTagName("chapter")[1]]);
254
255
256var successfullyParsed = true;
257
258</script>
259<script src="../../js/resources/js-test-post.js"></script>
260</body>
261</html>
262