home contribute faq download

FunctX XQuery Functions


Resolves a QName based on the in-scope namespaces of an element



The fn:resolve-QName function resolves a QName based on the in-scope namespaces of an element. The $qname argument is a string representing a qualified name. It may be prefixed (for example, prod:number), or unprefixed (for example, number). The $element argument is the element whose in-scope namespaces are to be used to determine which namespace URI is mapped to the prefix. If $qname is unprefixed, the default namespace declaration of $element is used. If there is no default namespace declaration in scope, the constructed QName has no namespace.

Note that when using the function, the prefix is never resolved using the context of the query. For example, if you map the prefix pre to the namespace http://datypic.com/pre in the query prolog, that is irrelevant when you call the fn:resolve-QName function with the first argument pre:myName. It is only how that prefix is mapped in $element that is relevant. If you want to use the context of the query, you can simply use the xs:QName constructor, as in xs:QName("pre:myName").

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

$qname xs:string? the QName to resolve
$element element() the element to use for the scope
return value xs:QName?


declare namespace ord = "http://datypic.com/ord";
declare namespace dty = "http://datypic.com";
declare namespace dty2 = "http://datypic.com/ns2";
let $root :=
  <order xmlns:ord="http://datypic.com/ord"
   <!-- ... -->
XQuery ExampleResults
resolve-QName('myName', $root)
A QName whose namespace is empty, whose prefix is empty, and whose local part is myName
resolve-QName('myName', $root/dty:order)
A QName whose namespace is http://datypic.com, whose prefix is empty, and whose local part is myName
resolve-QName('ord:myName', $root)
Error FONS0004
   'ord:myName', $root/dty:order)
A QName whose namespace is http://datypic.com/ord, whose prefix is ord, and whose local part is myName
   'dty2:myName', $root/dty:order)
Error FONS0004

See Also

fn:QNameConstructs a QName from a namespace and local part
fn:local-name-from-QNameThe local part of a QName
fn:namespace-uri-from-QNameThe namespace part of a QName
fn:namespace-uri-for-prefixThe namespace associated with a prefix, in the scope of an element


Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading: