fn:namespace-uri-for-prefix

Returns the namespace URI of one of the in-scope namespaces for $element, identified by its namespace prefix.

Signature

fn:namespace-uri-for-prefix(
    $prefix as xs:string?, 
    $element as element()
) as xs:anyURI?

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

If $element has an in-scope namespace whose namespace prefix is equal to $prefix, the function returns the namespace URI of that namespace.

If $element has no in-scope namespace whose namespace prefix is equal to $prefix, the function returns the empty sequence.

If $prefix is the zero-length string or the empty sequence, then if $element has a default namespace (that is, a namespace node with no name), the function returns the namespace URI of the default namespace. If $element has no default namespace, the function returns the empty sequence.

Prefixes are equal only if their Unicode codepoints match exactly.

Examples

let $e := 
<z:a xmlns="http://example.org/one" xmlns:z="http://example.org/two">
  <b xmlns=""/>
</z:a>

The expression fn:namespace-uri-for-prefix("z", $e) returns "http://example.org/two".

The expression fn:namespace-uri-for-prefix("", $e) returns "http://example.org/one".

The expression fn:namespace-uri-for-prefix((), $e) returns "http://example.org/one".

The expression fn:namespace-uri-for-prefix("xml", $e) returns "http://www.w3.org/XML/1998/namespace".

The expression fn:namespace-uri-for-prefix("xml", $e) returns "http://www.w3.org/XML/1998/namespace".