resolve-QName function
The fn:resolve-QName function converts a string containing a lexical QName into an expanded QName by using the in-scope namespaces of an element to resolve the namespace prefix to a namespace URI.
Syntax
- qualified-name
- A string that is in the form of a qualified name.
qualified-name has the xs:string data type, or is the empty sequence.
- element-for-namespace
- An element that provides the in-scope namespaces for qualified-name.
element-for-namespace is an element node.
Returned value
If qualified-name is
not the empty sequence, the returned value is an expanded name that
is constructed as follows:
- The prefix and local name of the expanded QName is taken from qualified-name.
- If qualified-name has a prefix, and that prefix matches a prefix in the in-scope namespaces of element-for-namespace, the namespace URI to which this prefix is bound is the namespace URI for the returned value.
- If qualified-name has no prefix, and a default namespace URI is defined in the in-scope namespaces of element-for-namespace, this default namespace URI is the namespace URI for the returned value.
- If qualified-name has no prefix, and no default namespace URI is defined in the in-scope namespaces of element-for-namespace, the returned value has no namespace URI.
- If the prefix for qualified-name does not match a namespace prefix in the in-scope namespaces of element-for-namespace, or qualified-name is not in the form of a valid qualified name, an error is returned.
If qualified-name is the empty sequence, the empty sequence is returned.
Example
The following query returns the
expanded QName that corresponds to the URI http://www.mycompany.com
and the lexical QName comp:dept:
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:resolve-QName("comp:dept", $department/d:dept/d:emp)