1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 2 <html> 3 <head> 4 <link rel="stylesheet" href="../js/resources/js-test-style.css"> 5 <script src="../js/resources/js-test-pre.js"></script> 6 <script src="xpath-test-pre.js"></script> 7 </head> 8 <body> 9 <div id="console"></div> 10 11 <script> 12 doc = (new DOMParser).parseFromString( 13 '<doc>' + 14 '<CHILD attr1="val1" attr31="31">' + 15 '<GCHILD name="GCHILD11"/>' + 16 '<GCHILD name="GCHILD12"/>' + 17 'TEXT1' + 18 '</CHILD>' + 19 '<CHILD attr4="4">' + 20 '<GCHILD name="GCHILD21"/>' + 21 '</CHILD>' + 22 '</doc>', 23 'application/xml'); 24 25 CHILD1 = doc.getElementsByTagName("CHILD")[0]; 26 CHILD2 = doc.getElementsByTagName("CHILD")[1]; 27 attr1 = CHILD1.getAttributeNode("attr1"); 28 attr31 = CHILD1.getAttributeNode("attr31"); 29 attr4 = CHILD2.getAttributeNode("attr4"); 30 GCHILD11 = doc.getElementsByTagName("GCHILD")[0]; 31 GCHILD12 = doc.getElementsByTagName("GCHILD")[1]; 32 GCHILD21 = doc.getElementsByTagName("GCHILD")[2]; 33 TEXT1 = GCHILD12.nextSibling; 34 35 36 result = doc.evaluate("ancestor::*", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 37 checkSnapshot("ancestor::* (context = attr1)", 38 result, 39 [doc.documentElement, CHILD1]); 40 41 result = doc.evaluate("ancestor::*", GCHILD11, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 42 checkSnapshot("ancestor::* (context = GCHILD11)", 43 result, 44 [doc.documentElement, CHILD1]); 45 46 result = doc.evaluate("ancestor::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 47 checkSnapshot("ancestor::node() (context = attr1)", 48 result, 49 [doc, doc.documentElement, CHILD1]); 50 51 result = doc.evaluate("ancestor::node()", GCHILD11, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 52 checkSnapshot("ancestor::node() (context = GCHILD11)", 53 result, 54 [doc, doc.documentElement, CHILD1]); 55 56 result = doc.evaluate("preceding::node()", attr4, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 57 checkSnapshot("preceding::node() (context = attr4)", 58 result, 59 [CHILD1, GCHILD11, GCHILD12, TEXT1]); 60 61 result = doc.evaluate("preceding::node()", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 62 checkSnapshot("preceding::node() (context = CHILD2)", 63 result, 64 [CHILD1, GCHILD11, GCHILD12, TEXT1]); 65 66 result = doc.evaluate("preceding::node()", GCHILD12, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 67 checkSnapshot("preceding::node() (context = GCHILD12)", 68 result, 69 [GCHILD11]); 70 71 result = doc.evaluate("following::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 72 checkSnapshot("following::node() (context = attr1)", 73 result, 74 [GCHILD11, GCHILD12, TEXT1, CHILD2, GCHILD21]); 75 76 result = doc.evaluate("following::node()", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 77 checkSnapshot("following::node() (context = CHILD1)", 78 result, 79 [CHILD2, GCHILD21]); 80 81 result = doc.evaluate("following::node()", GCHILD11, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 82 checkSnapshot("following::node() (context = GCHILD11)", 83 result, 84 [GCHILD12, TEXT1, CHILD2, GCHILD21]); 85 86 result = doc.evaluate("following::node()", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 87 checkSnapshot("following::node() (context = CHILD2)", 88 result, 89 []); 90 91 result = doc.evaluate("//CHILD | //@attr1", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 92 checkSnapshot("//CHILD | //@attr1", 93 result, 94 [CHILD1, attr1, CHILD2]); 95 96 result = doc.evaluate("//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 97 checkSnapshot("//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31", 98 result, 99 [CHILD1, attr1, attr31, GCHILD12, CHILD2]); 100 101 result = doc.evaluate("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[3]", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 102 checkSnapshot("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[3]", 103 result, 104 [attr31]); 105 106 result = doc.evaluate("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[position() = last()]", doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); 107 checkSnapshot("(//CHILD | //@attr1 | //*[@name='GCHILD12'] | //@attr31)[position() = last()]", 108 result, 109 [CHILD2]); 110 111 result = doc.evaluate("//CHILD[2]/GCHILD | //CHILD[1]/GCHILD", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 112 checkSnapshot("//CHILD[2]/GCHILD | //CHILD[1]/GCHILD", 113 result, 114 [GCHILD11, GCHILD12, GCHILD21]); 115 116 shouldBe('doc.evaluate("string(//*[@name=\'GCHILD12\'] | //CHILD | //@attr1 | //@attr31)", doc, null, XPathResult.STRING_TYPE, null).stringValue', '"TEXT1"'); 117 118 result = doc.evaluate("descendant::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 119 checkSnapshot("descendant::node() (context = attr1)", 120 result, 121 []); 122 123 result = doc.evaluate("child::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 124 checkSnapshot("child::node() (context = attr1)", 125 result, 126 []); 127 128 result = doc.evaluate("parent::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 129 checkSnapshot("parent::node() (context = attr1)", 130 result, 131 [CHILD1]); 132 133 result = doc.evaluate("following-sibling::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 134 checkSnapshot("following-sibling::node() (context = attr1)", 135 result, 136 []); 137 138 result = doc.evaluate("preceding-sibling::node()", attr4, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 139 checkSnapshot("preceding-sibling::node() (context = attr4)", 140 result, 141 []); 142 143 result = doc.evaluate("attribute::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 144 checkSnapshot("attribute::node() (context = attr1)", 145 result, 146 []); 147 148 result = doc.evaluate("self::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 149 checkSnapshot("self::node() (context = attr1)", 150 result, 151 [attr1]); 152 153 result = doc.evaluate("self::*", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 154 checkSnapshot("self::* (context = attr1)", 155 result, 156 []); 157 158 result = doc.evaluate("descendant-or-self::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 159 checkSnapshot("descendant-or-self::node() (context = attr1)", 160 result, 161 [attr1]); 162 163 result = doc.evaluate("ancestor-or-self::node()", attr1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 164 checkSnapshot("ancestor-or-self::node() (context = attr1)", 165 result, 166 [doc, doc.documentElement, CHILD1, attr1]); 167 168 var successfullyParsed = true; 169 170 </script> 171 <script src="../js/resources/js-test-post.js"></script> 172 </body> 173 </html> 174