Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
You can only use this shorthand in a predicate; that is, within square brackets. If you use a numeric value in other contexts where a Boolean is expected, the number is converted to a boolean on the basis that 0 is false; everything else is true. So
not
mean
See Also
last()
on page 820
prefix-from-QName
The
prefix-from-QName()
function extracts the prefix from an expanded QName. For example,
prefix-from-QName(node-name(@xml:space))
returns the string
xml
.
Signature
Argument | Type | Meaning |
value | xs:QName? | The supplied QName |
Result | xs:NCName | The prefix of the QName if there is one, or the empty sequence otherwise |
Effect
If the first argument is an empty sequence, the function returns an empty sequence.
If the supplied QName includes a prefix, the prefix is returned as an instance of
xs:NCName
. This is derived from
xs:string
, so the value can be used anywhere that a string can be used. If the QName is unprefixed, the function returns an empty sequence.
Usage
In the XML Schema specifications, it is stated that the value space for the type
xs:QName
contains two parts: the local name and the namespace URI. The XPath data model (XDM), however, modifies this to say that it also retains a third part, the namespace prefix. The main reason for this difference is to ensure that every value in XDM can be converted to a string; without this rule, a great number of special exceptions were needed to cater for the fact that not all values could be serialized successfully. Retaining the prefix also gives usability benefits, because although in theory the choice of namespace prefixes is arbitrary, in practice choosing familiar prefixes greatly aids human readability of XML documents. There is also software around that attaches more significance to namespace prefixes than it probably should—which is excusable, since the base XML specification itself describes DTD-based validation in a way that treats namespace prefixes, rather than the associated URIs, as significant.
QNames arise most often as the names of elements and attributes. If XDM documents are constructed in the normal way by parsing source XML (with or without schema validation), then the original prefixes from the source document will be retained in the tree, and will be accessible by calling
prefix-from-QName(node-name($node))
. If there was no prefix, this returns an empty sequence. When nodes are constructed using instructions such as
namespace fixup
).
A QName can also arise as the typed value of a node (an example is the attribute
xsi:type=“xs:integer”
, where both the name and the value of the attribute are QNames). In this case, assuming a schema-aware processor, the expression
prefix-from-QName(@xsi:type)
will return the string
xs
.