O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required