Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /domxpath/fns-name-related.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel="help-local-name" href="https://www.w3.org/TR/1999/REC-xpath-19991116/#function-local-name">
<link rel="help-namespace-uri" href="https://www.w3.org/TR/1999/REC-xpath-19991116/#function-namespace-uri">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Test the functions with various scenarios
function testFunction(expression, xmlString, expected) {
const doc = (new DOMParser()).parseFromString(xmlString, 'text/xml');
test(() => {
const result = doc.evaluate(expression, doc.documentElement, null, XPathResult.STRING_TYPE, null);
assert_equals(result.resultType, XPathResult.STRING_TYPE);
assert_equals(result.stringValue, expected);
})
}
const context = '<root xmlns:alpha="http://example.com/alpha" xmlns:gamma="http://example.com/gamma"><alpha:beta gamma:delta="epsilon"></alpha:beta></root>';
testFunction("name(./*[1])", context, "alpha:beta");
testFunction("local-name(./*[1])", context, "beta");
testFunction("name(./*[1]/@*)", context, "gamma:delta");
testFunction("local-name(./*[1]/@*)", context, "delta");
</script>
</body>