fn:resolve-QName
Returns an xs:QName value (that is, an expanded-QName) by taking an
xs:string that has the lexical form of an xs:QName (a
string in the form "prefix:local-name" or "local-name") and resolving it using the
in-scope namespaces for a given element.
Signature
fn:resolve-QName(
$qname as xs:string?,
$element as element()
) as xs:QName?Properties
This function is deterministic, context-independent, and focus-independent.
Rules
If $qname is the empty sequence, returns the empty sequence.
More specifically, the function searches the namespace bindings of $element
for a binding whose name matches the prefix of $qname, or the zero-length
string if it has no prefix, and returns an expanded-QName whose local name is taken
from the supplied $qname, and whose namespace URI is taken from the string
value of the namespace binding.
If the $qname has no prefix, and there is no namespace binding for
$element corresponding to the default (unnamed) namespace, then the
resulting expanded-QName has no namespace part.
The prefix (or absence of a prefix) in the supplied $qname argument is
retained in the returned expanded-QName, as described in Terminology.
Error Conditions
A dynamic error is raised [ERRFOCA0002] if $qname does
not have the correct lexical form for an instance of xs:QName.
A dynamic error is raised [ERRFONS0004] if $qname has
a prefix and there is no namespace binding for $element that matches this
prefix.
Notes
Sometimes the requirement is to construct an xs:QName without using the
default namespace. This can be achieved by writing:
if (contains($qname, ":")) then fn:resolve-QName($qname, $element) else
fn:QName("", $qname)If the requirement is to construct an xs:QName using the namespaces in the
static context, then the xs:QName constructor should be used.
Examples
Assume that the element bound to $element has a single namespace binding
bound to the prefix eg.
fn:resolve-QName("hello", $element) returns a QName with local name
"hello" that is in no namespace.
fn:resolve-QName("eg:myFunc", $element) returns an xs:QName
whose namespace URI is specified by the namespace binding corresponding to the prefix
"eg" and whose local name is "myFunc".