1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"xpath-test-pre.js"></script>
8 <div id=
"console"></div>
11 doc
= (new DOMParser
).parseFromString(
13 '<CHILD attr1="val1" attr31="31">' +
14 '<GCHILD name="GCHILD11"/>' +
15 '<GCHILD name="GCHILD12"/>' +
19 '<GCHILD name="GCHILD21"/>' +
24 CHILD1
= doc
.getElementsByTagName("CHILD")[0];
25 CHILD2
= doc
.getElementsByTagName("CHILD")[1];
26 attr1
= CHILD1
.getAttributeNode("attr1");
27 attr31
= CHILD1
.getAttributeNode("attr31");
28 attr4
= CHILD2
.getAttributeNode("attr4");
29 GCHILD11
= doc
.getElementsByTagName("GCHILD")[0];
30 GCHILD12
= doc
.getElementsByTagName("GCHILD")[1];
31 GCHILD21
= doc
.getElementsByTagName("GCHILD")[2];
32 TEXT1
= GCHILD12
.nextSibling
;
35 result
= doc
.evaluate("ancestor::*", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
36 checkSnapshot("ancestor::* (context = attr1)",
38 [doc
.documentElement
, CHILD1
]);
40 result
= doc
.evaluate("ancestor::*", GCHILD11
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
41 checkSnapshot("ancestor::* (context = GCHILD11)",
43 [doc
.documentElement
, CHILD1
]);
45 result
= doc
.evaluate("ancestor::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
46 checkSnapshot("ancestor::node() (context = attr1)",
48 [doc
, doc
.documentElement
, CHILD1
]);
50 result
= doc
.evaluate("ancestor::node()", GCHILD11
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
51 checkSnapshot("ancestor::node() (context = GCHILD11)",
53 [doc
, doc
.documentElement
, CHILD1
]);
55 result
= doc
.evaluate("preceding::node()", attr4
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
56 checkSnapshot("preceding::node() (context = attr4)",
58 [CHILD1
, GCHILD11
, GCHILD12
, TEXT1
]);
60 result
= doc
.evaluate("preceding::node()", CHILD2
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
61 checkSnapshot("preceding::node() (context = CHILD2)",
63 [CHILD1
, GCHILD11
, GCHILD12
, TEXT1
]);
65 result
= doc
.evaluate("preceding::node()", GCHILD12
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
66 checkSnapshot("preceding::node() (context = GCHILD12)",
70 result
= doc
.evaluate("following::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
71 checkSnapshot("following::node() (context = attr1)",
73 [GCHILD11
, GCHILD12
, TEXT1
, CHILD2
, GCHILD21
]);
75 result
= doc
.evaluate("following::node()", CHILD1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
76 checkSnapshot("following::node() (context = CHILD1)",
80 result
= doc
.evaluate("following::node()", GCHILD11
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
81 checkSnapshot("following::node() (context = GCHILD11)",
83 [GCHILD12
, TEXT1
, CHILD2
, GCHILD21
]);
85 result
= doc
.evaluate("following::node()", CHILD2
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
86 checkSnapshot("following::node() (context = CHILD2)",
90 result
= doc
.evaluate("//CHILD | //@attr1", doc
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
91 checkSnapshot("//CHILD | //@attr1",
93 [CHILD1
, attr1
, CHILD2
]);
95 result
= doc
.evaluate("//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31", doc
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
96 checkSnapshot("//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31",
98 [CHILD1
, attr1
, attr31
, GCHILD12
, CHILD2
]);
100 result
= doc
.evaluate("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[3]", doc
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
101 checkSnapshot("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[3]",
105 result
= doc
.evaluate("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[position() = last()]", doc
, null, XPathResult
.UNORDERED_NODE_SNAPSHOT_TYPE
, null);
106 checkSnapshot("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[position() = last()]",
110 result
= doc
.evaluate("//CHILD[2]/GCHILD | //CHILD[1]/GCHILD", doc
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
111 checkSnapshot("//CHILD[2]/GCHILD | //CHILD[1]/GCHILD",
113 [GCHILD11
, GCHILD12
, GCHILD21
]);
115 shouldBe('doc.evaluate("string(//*[@name=\'GCHILD12\'] | //CHILD | //@attr1 | //@attr31)", doc, null, XPathResult.STRING_TYPE, null).stringValue', '"TEXT1"');
117 result
= doc
.evaluate("descendant::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
118 checkSnapshot("descendant::node() (context = attr1)",
122 result
= doc
.evaluate("child::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
123 checkSnapshot("child::node() (context = attr1)",
127 result
= doc
.evaluate("parent::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
128 checkSnapshot("parent::node() (context = attr1)",
132 result
= doc
.evaluate("following-sibling::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
133 checkSnapshot("following-sibling::node() (context = attr1)",
137 result
= doc
.evaluate("preceding-sibling::node()", attr4
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
138 checkSnapshot("preceding-sibling::node() (context = attr4)",
142 result
= doc
.evaluate("attribute::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
143 checkSnapshot("attribute::node() (context = attr1)",
147 result
= doc
.evaluate("self::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
148 checkSnapshot("self::node() (context = attr1)",
152 result
= doc
.evaluate("self::*", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
153 checkSnapshot("self::* (context = attr1)",
157 result
= doc
.evaluate("descendant-or-self::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
158 checkSnapshot("descendant-or-self::node() (context = attr1)",
162 result
= doc
.evaluate("ancestor-or-self::node()", attr1
, null, XPathResult
.ORDERED_NODE_SNAPSHOT_TYPE
, null);
163 checkSnapshot("ancestor-or-self::node() (context = attr1)",
165 [doc
, doc
.documentElement
, CHILD1
, attr1
]);