namespace-uri function

The fn:namespace-uri function returns the namespace URI of the qualified name for a node.

Syntax

Read syntax diagramSkip visual syntax diagramfn:namespace-uri(node)
node
The qualified name of a node for which the namespace URI is to be retrieved. If node is not specified, fn:namespace-uri is evaluated for the current context node.

Returned value

The returned value depends on the value of node:
  • If node meets any of the following conditions, a string of length 0 is returned:
    • node is the empty sequence.
    • node is not an element node or an attribute node.
    • node is an element node or an attribute node, but the expanded qualified name for node is not in a namespace.
  • If node meets any of the following conditions, an error is returned:
    • node is undefined.
    • node is not a node.
  • Otherwise, an xs:string value is returned that contains the namespace URI of the expanded name for node.

Examples

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($department/d:dept/d:emp)
The following query also 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 $department/d:dept/d:emp/fn:namespace-uri()