fn-lang.html (1959B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://www.w3.org/TR/1999/REC-xpath-19991116/#function-lang"> 3 <body> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script> 7 // Set the context node to the first child of the root element, and evaluate 8 // the specified XPath expression. The test passes if 9 // - The first child element name is 'match' and XPath result is true, or 10 // - The first child element name is not 'match' and XPath result is false. 11 function testFirstChild(expression, xmlString) { 12 let doc = (new DOMParser()).parseFromString(xmlString, 'text/xml'); 13 test(() => { 14 let element = doc.documentElement.firstChild; 15 let result = doc.evaluate(expression, element, null, XPathResult.BOOLEAN_TYPE, null); 16 assert_equals(result.resultType, XPathResult.BOOLEAN_TYPE); 17 assert_equals(result.booleanValue, element.localName == 'match', element.outerHTML); 18 }, `${expression}: ${doc.documentElement.outerHTML}`); 19 } 20 21 testFirstChild('lang("en")', '<root><match xml:lang="en"/></root>'); 22 testFirstChild('lang("en")', '<root><match xml:lang="EN"/></root>'); 23 testFirstChild('lang("en")', '<root><match xml:lang="en-us"/></root>'); 24 testFirstChild('lang("en")', '<root><unmatch/></root>'); 25 26 // XPath 1.0 says: 27 // if the context node has no xml:lang attribute, by the value of the 28 // xml:lang attribute on the nearest ancestor of the context node that has 29 // an xml:lang attribute. 30 testFirstChild('lang("ja")', '<root xml:lang="ja"><match/></root>'); 31 32 // XPath 1.0 says: 33 // if there is some suffix starting with - such that the attribute value is 34 // equal to the argument ignoring that suffix of the attribute value 35 testFirstChild('lang("ja")', '<root xml:lang="ja-jp"><unmatch xml:lang="ja_JP"/></root>'); 36 37 // XPath 3.1 is not to be followed as per: https://github.com/whatwg/dom/issues/1199 38 testFirstChild('lang("ko")', '<root><unmatch xml:lang="Ko"/></root>'); 39 </script> 40 </body>