Description
The fn:data function accepts a sequence of items and returns their typed values. For atomic values, this simply means returning the value itself, unchanged. For nodes, this means extracting the typed value of the node.
Calling this function is often unnecessary because the typed value of a node is extracted automatically (in a process known as atomization) for many XQueryXPath 2.0 expressions, including comparisons, arithmetic operations and function calls. The most common use case for the fn:data function is in XQuery element constructors.
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 |
$arg |
item()* |
the item to get the value of |
return value |
xs:anyAtomicType* |
Examples<xsl:variable name="cat" select="doc('https://www.datypic.com/functx./input/catalog.xml')"/>
|
XPath Example | Results |
---|
data($cat//product[1]/number) |
557 |
data($cat//number) |
(557, 563, 443, 784) |
data($cat//product[1]/@dept) |
WMN |
data($cat//product[1]/colorChoices) |
navy black |
data($cat//product[1]) |
557 Fleece Pullover navy black |
data($cat//product[4]/desc) |
Our favorite shirt! |
The additional examples below yield different results if the input document was validated with the schema shown here. |
data($cat//product[1]/colorChoices) |
('navy', 'black') |
data($cat//product[1]) |
Error FOTY0012 |
History |
Recommended Reading:
|