[2.0] Sequences and Atomic Values

Working with the XPath 2.0 data model is probably the biggest change in XSLT 2.0. We’ll mention the changes to the model as we go along, but we’ll discuss three topics outright: sequences, atomic values, and schema support. We’ll look at sequences and atomic values now and discuss schema support later in this chapter.

A sequence is, well, a sequence of items. Those items might be nodes from an XML document, or they might be simple values such as 'June' or 3.14. A sequence has an order and a length. You can use XPath 2.0 functions to see how many items are in a sequence, you can retrieve a subset of the items in the sequence, and you can insert or delete items at a particular point in the sequence. Here is a variable that contains a sequence:

<!-- sequences1.xsl -->
...
<xsl:variable name="months" as="xs:string*"
  select="('January', 'February', 'March', 'April', 
             'May', 'June', 'July', 'August', 
             'September', 'October', 'November', 
             'December')"/>

There are several things to point out here. First of all, notice that we used the new as attribute to define the datatype of this variable. The asterisk here means that the variable can have any number of values. If we defined this variable with the datatype xs:string, the variable $months could only be a single xs:string. The code here would cause a fatal error.

The values in the sequence are all atomic values. An atomic value is a simple value, as opposed to a node. A sequence can contain atomic values, as in ...

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.