namespace-uri-for-prefix function

The fn:namespace-uri-for-prefix function returns the namespace URI that is associated with a prefix in the in-scope namespaces for an element.

Syntax

Read syntax diagramSkip visual syntax diagramfn:namespace-uri-for-prefix( prefix, element)
prefix
The prefix for which the namespace is returned.

prefix has the xs:string data type, which can have zero length, or is an empty sequence.

element
An element that has an in-scope namespace that is bound to prefix.

Returned value

The returned value depends on the value of prefix:
  • If element has an in-scope namespace whose prefix value matches the value of prefix, the namespace URI for that namespace is returned.
  • If element does not have an in-scope namespace whose prefix value matches the value of prefix, the empty sequence is returned.
  • If prefix is a string of length 0 or is an empty sequence, the namespace URI for the default namespace is returned.

Example

The following query returns the value "http://www.mycompany.com":
declare namespace d="http://www.mycompany.com";
let $department := document {
    <comp:dept xmlns:comp="http://www.mycompany.com" id="A07">
        <comp:emp id="31201" />
    </comp:dept> }
return fn:namespace-uri-for-prefix("comp", $department/d:dept/d:emp)