Name

[2.0] data()

Given a sequence of items, returns a sequence of atomic values that represent the set of items.

Syntax

xs:anyAtomicType* data(item()*)

Inputs

A sequence of items.

Output

A sequence in which each item in the input sequence has been converted to an atomic value. If an item in the input sequence is an atomic value, it is returned as is in the result sequence. For nodes, any item with a datatype is converted to an atomic value and returned in the result sequence.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 2, “Accessors.”

Example

Here is a stylesheet that creates a sequence of atoms and elements and lists them, identifying atomic values versus elements in the sequence. Next, the stylesheet lists the sequence returned by the data() function:

<?xml version="1.0"?>
<!-- data.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:datatest="http://www.oreilly.com"> <xsl:output method="text"/> <xsl:template match="/"> <!-- Before we test the data() function, we create a sequence. --> <xsl:variable name="testSequence" as="item()*"> <xsl:sequence select="(3, 4, 5)"/> <xsl:element name="currentDate"> <xsl:value-of select="current-date()"/> </xsl:element> <xsl:element name="currentTime"> <xsl:value-of select="current-time()"/> </xsl:element> <xsl:element name="integerTest"> <xsl:value-of select="xs:integer(8)"/> </xsl:element> <xsl:sequence select="('blue', 'red')"/> <xsl:element name="floatTest1"> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.