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>
11 var doc = (new DOMParser).parseFromString(
12 '<doc>' +
13 '<para id="1" />' +
14 '<div id="2" />' +
15 '<para id="3" />' +
16 '</doc>',
17 'application/xml');
18 test(doc, doc.documentElement, 'child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
19 test(doc, doc.documentElement, 'child::*', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
20
21 var doc = (new DOMParser).parseFromString(
22 '<doc>This is <i>some</i> text.</doc>',
23 'application/xml');
24 test(doc, doc.documentElement, 'child::text()', [doc.documentElement.firstChild, doc.documentElement.lastChild]);
25 test(doc, doc.documentElement, 'child::node()', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
26
27 var doc = (new DOMParser).parseFromString(
28 '<doc name="foo" value="bar" />',
29 'application/xml');
30 test(doc, doc.documentElement, 'attribute::name', [doc.documentElement.getAttributeNode("name")]);
31 test(doc, doc.documentElement, 'attribute::*', [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]);
32
33 var 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');
41 test(doc, doc.documentElement, 'descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
42
43 var 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');
54 test(doc, '//context', 'ancestor::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[1]]);
55
56 var 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');
65 test(doc, '//div[@id="3"]', 'ancestor-or-self::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[2]]);
66
67 var 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');
75 test(doc, doc.documentElement, 'descendant-or-self::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
76
77 var doc = (new DOMParser).parseFromString(
78 '<doc>' +
79 '<para />' +
80 '</doc>',
81 'application/xml');
82 test(doc, doc.documentElement, 'self::para', []);
83 test(doc, 'para', 'self::para', [doc.documentElement.firstChild]);
84
85 var 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');
92 test(doc, doc.documentElement, 'child::chapter/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
93
94 var 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');
101 test(doc, doc.documentElement, 'child::*/child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
102
103 var doc = (new DOMParser).parseFromString(
104 '<doc><a><b><context /></b></a></doc>',
105 'application/xml');
106 test(doc, '//context', '/', [doc]);
107
108 var doc = (new DOMParser).parseFromString(
109 '<doc>' +
110 '<para id="1"><context /></para>' +
111 '<para id="2" />' +
112 '</doc>',
113 'application/xml');
114 test(doc, '//context', '/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
115
116 var 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');
125 test(doc, '//context', '/descendant::olist/child::item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]);
126
127 var doc = (new DOMParser).parseFromString(
128 '<doc>' +
129 '<div id="1" />' +
130 '<para id="2" />' +
131 '<para id="3" />' +
132 '</doc>',
133 'application/xml');
134 test(doc, doc.documentElement, 'child::para[position()=1]', [doc.getElementsByTagName("para")[0]]);
135
136 var doc = (new DOMParser).parseFromString(
137 '<doc>' +
138 '<para id="1" />' +
139 '<para id="2" />' +
140 '<div id="3" />' +
141 '</doc>',
142 'application/xml');
143 test(doc, doc.documentElement, 'child::para[position()=last()]', [doc.getElementsByTagName("para")[1]]);
144
145 var 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');
153 test(doc, doc.documentElement, 'child::para[position()=last()-1]', [doc.getElementsByTagName("para")[1]]);
154
155 var 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');
162 test(doc, doc.documentElement, 'child::para[position()>1]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
163
164 var 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');
171 test(doc, '//context', 'following-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[2]]);
172 test(doc, '//context', 'preceding-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[1]]);
173
174 var xml = "<doc>"
175 for (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 += '';
180 }
181 xml += "</doc>"
182 var doc = (new DOMParser).parseFromString(xml, 'application/xml');
183 test(doc, doc.documentElement, '/descendant::figure[position()=42]', [doc.getElementsByTagName("figure")[41]]);
184
185 var doc = (new DOMParser).parseFromString(
186 '' +
187 '' +
188 '' +
189 '' +
190 '' +
191 '' +
192 '' +
193 '' +
194 '',
195 'application/xml');
196 test(doc, doc.documentElement, '/child::doc/child::chapter[position()=5]/child::section[position()=2]', [doc.getElementsByTagName("section")[4]]);
197
198 var doc = (new DOMParser).parseFromString(
199 '' +
200 '' +
201 '' +
202 '' +
203 '' +
204 '' +
205 '' +
206 '' +
207 '',
208 'application/xml');
209 test(doc, doc.documentElement, 'child::para[attribute::type="warning"][position()=5]', [doc.getElementsByTagName("para")[6]]);
210 test(doc, doc.documentElement, 'child::para[position()=5][attribute::type="warning"]', []);
211
212 var doc = (new DOMParser).parseFromString(
213 '' +
214 '' +
215 'Introduction' +
216 'Body' +
217 '' +
218 'Another' +
219 'Introduction' +
220 '' +
221 '',
222 'application/xml');
223 test(doc, doc.documentElement, "child::chapter[child::title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]);
224
225 var doc = (new DOMParser).parseFromString(
226 '' +
227 '' +
228 '' +
229 '' +
230 '',
231 'application/xml');
232 test(doc, doc.documentElement, "child::chapter[child::title]", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[2]]);
233
234 var doc = (new DOMParser).parseFromString(
235 '' +
236 '' +
237 '' +
238 '' +
239 '' +
240 '',
241 'application/xml');
242 test(doc, doc.documentElement, "child::*[self::chapter or self::appendix]", [doc.getElementsByTagName("chapter")[0], doc.getElementsByTagName("appendix")[0], doc.getElementsByTagName("chapter")[1]]);
243
244 var doc = (new DOMParser).parseFromString(
245 '' +
246 '' +
247 '' +
248 '' +
249 '' +
250 '' +
251 '',
252 'application/xml');
253 test(doc, doc.documentElement, "child::*[self::chapter or self::appendix][position()=last()]", [doc.getElementsByTagName("chapter")[1]]);
254
255
256 var successfullyParsed = true;
257
258 </script>
259 <script src="../../js/resources/js-test-post.js"></script>
260 </body>
261 </html>
262