XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Functions in connection with qualified identifiers (QNames)
A xs:QName QName in expanded form which is built by the resolution of a non-expanded QName candidate in xs:string string form towards the in the context of the element passed on currently valid namespace URI.
Obligatory. A xs:string string which has to lexically correspond to a non-expanded QName. The string may – but does not have to – contain a prefix portion separated by a colon.
Obligatory. An element whose namespace nodes are tested whether they are bound to a prefix which corresponds to the prefix portion contained in the QName string.
Purpose of use:
The fn:resolve-QName() function represents a constructor for a xs:QName QName in its expanded form and uses as input values a string containing the non-expanded QName candidate as well as a reference element for the determination of the namespace to be used.
If the QName candidate has not the required lexical form, the error »Invalid lexical value« (err:FOCA0002) is reported. However, if the empty sequence is passed on as QName candidate, the function outputs an empty result sequence without reporting an error.
The namespace nodes of the reference element (more exactly: all namespaces being in its scope) are tested whether one of them is bound to a prefix which equals the prefix portion of the QName string passed on.
If such a namespace is found, its namespace URI is outputted together with the local name portion of the QName string passed on and is accordingly typed as xs:QName.
If the QName string has no prefix portion, the scope of the element is examined for a default namespace (which is bound to no prefix) and – in case such a default namespace exists – it is outputted together with the local name portion of the QName string as expanded xs:QName QName.
If the QName string has no prefix portion and the element is not in the default namespace, a xs:QName QName without namespace portion is outputted.
However, it is an error (»No namespace found for prefix«, err:FONS0004) if the QName string has a prefix portion, but the reference element has no namespace bound to an appropriate prefix.
The function can also be used in case a prefixless, expanded xs:QName QName shall be generated without accessing the default namespace. The problem here is that the default namespace (if declared) is normally valid for the reference element. Therefore, it must be ensured that the fn:resolve-QName() function is not used in this case, but alternatively the fn:expanded-QName() function (XQuery).
This is possible with the following XPath expression which tests by means of the composition of the $qnamestring QName string to be used whether it contains a prefix portion or not:
If no prefix portion is contained, fn:contains() finds the colon and the first branch of the condition is pursued. In this case, fn:resolve-QName() can be used as described above, because there is no danger that a prefixless QName candidate binds the resulting QName to the default namespace (which shall be avoided).
Otherwise the condition is not met. In the else branch the fn:expanded-QName() function is executed with the empty string as first argument and the (as proven prefixless) QName string as second argument. In this case, the return value is as desired an expanded QName which is in the null namespace, meaning in no namespace.
Alternatively, the constructor function for QNames can be applied, provided that the namespaces of the static context may be used:
Example 1 – generating a QName without namespace:
The <test> reference element has any prefix-bound namespace nodes. However, the prefixless default namespace is not in scope. The following call:
returns an expanded my_name QName which is in no namespace (this is not the case if the default namespace is in scope of the reference element, see example 3).
Example 2 – generating a QName with namespace:
The <test> reference element has among other things a namespace node which is bound to the example: prefix. The following call:
returns an expanded your_name QName which is bound to the namespace indicated by the example: prefix for the reference element.
Example 3 – generating a QName in the default namespace:
The <defaultTest> reference element has any namespaces in scope, including the default namespace. The following call:
returns an expanded his_name QName which is in the default namespace, because this is the namespace which is assigned to the empty string (as prefix) for the reference element.
The function is not available.
fn:resolve-QName($qname as xs:string?,
$element as element()) as xs:QName?
|<< back||next >>|
Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany