Description
The fn:prefix-from-QName function returns the prefix associated with a particular qualified name. Note that the prefix associated with a qualified name selected from an input document will be the prefix that is used in that input document, not a prefix used in the query.
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 |
$arg |
xs:QName? |
return value |
xs:NCName? |
Examples<xsl:stylesheet xmlns:pre2="http://datypic.com/pre"
xmlns:unpre="http://datypic.com/unpre">... | <xsl:variable name="in-xml" as="item()*"> | | <noNamespace>
<pre:prefixed xmlns="http://datypic.com/unpre"
xmlns:pre="http://datypic.com/pre">
<unprefixed pre:prefAttr="a" noNSAttr="b">123</unprefixed>
</pre:prefixed>
</noNamespace> |
| </xsl:variable> |
XPath Example | Results | Explanation |
---|
prefix-from-QName(
node-name($in-xml)) |
() |
The prefix pre2 is used rather than pre to demonstrate that
when selecting nodes from an instance document, it is the
prefix used in the instance document (not the query) that
is returned. |
prefix-from-QName(
node-name($in-xml//pre2:prefixed)) |
pre |
prefix-from-QName(
node-name($in-xml//unpre:unprefixed)) |
() |
prefix-from-QName(
node-name($in-xml//@pre2:prefAttr)) |
pre |
prefix-from-QName(
node-name($in-xml//@noNSAttr)) |
() |
prefix-from-QName(
node-name(<pre2:new>xyz</pre2:new>)) |
pre2 |
when constructing a new element, the prefix used in the query itself is the one associated with the name |
See AlsoHistory |
Recommended Reading:
|