Description
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 TypeName | Type | Description |
$qname |
xs:string? |
the QName to resolve |
$element |
element() |
the element to use for the scope |
return value |
xs:QName? |
Examplesdeclare namespace ord = "http://datypic.com/ord";
declare namespace dty = "http://datypic.com";
declare namespace dty2 = "http://datypic.com/ns2"; | let $root := | <root>
<order xmlns:ord="http://datypic.com/ord"
xmlns="http://datypic.com">
<!-- ... -->
</order>
</root>
| return |
XQuery Example | Results |
---|
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 |
resolve-QName(
'ord:myName', $root/dty:order) |
A QName whose namespace is http://datypic.com/ord , whose prefix is ord , and whose local part is myName |
resolve-QName(
'dty2:myName', $root/dty:order) |
Error FONS0004 |
See AlsoHistory |
Recommended Reading:
|