Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<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("namespace-uri(./*[1])", context, "http://example.com/alpha");
testFunction("name(./*[1]/@*)", context, "gamma:delta");
testFunction("local-name(./*[1]/@*)", context, "delta");
testFunction("namespace-uri(./*[1]/@*)", context, "http://example.com/gamma");
</script>
</body>