XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (156 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
11.94Mb size Format: txt, pdf, ePub

Example 2: Non-Western Digits

This example shows how digits other than the Western digits 0–9 can be used. I will use the Indic Arabic digits (that is, the digits used in many Arabic countries, as distinct from the so-called Arabic digits used in the West):


Number
Format pattern
Result
12345
• (x0660)

The digits will be output in the output XML or HTML file in the usual order (most significant digit first). Displaying the number correctly when it appears as part of text that runs from right to left is the job of the browser or other display software, and you shouldn't worry about it at the XSLT level.

Example 3: NaN and Infinity

This example shows how the exceptional numeric values NaN and Infinity can be shown, for example in a statistical table.


Number
Format pattern
Result
number(‘a’)
any
Not Applicable
1e0 div
0
any
Out of
Range
-1e0 div
0
any
-Out of
Range

See Also

format-number()
function in Chapter 13, page 788


on page 403

xsl:document

The

instruction creates a document node and adds it to the result sequence. The most likely reason for using it is to perform document-level validation on a temporary tree.

Changes in 2.0

This instruction is new in XSLT 2.0. It should not be confused with the

instruction described in the abandoned XSLT 1.1 working draft, which was the precursor to the

instruction in XSLT 2.0. The document created by

is a temporary document that becomes available for further processing within the stylesheet; the document created by

is a final output from the transformation.

Format

  validation? = “strict” | “lax” | “preserve” | “strip”

  type? = qname>

  


Position


is used as an instruction within a sequence constructor.

Attributes

Name
Value
Meaning
validation
optional
strict
,
lax
,
preserve
, or
skip
Indicates whether and how the document should be subjected to schema validation
type
optional
Lexical QName
Identifies a type declaration (either a built-in type, or a user-defined type imported from a schema) against which the outermost element of the new document is to be validated

The
type
and
validation
attributes are mutually exclusive: if one is present, the other must be absent. These attributes are available only with a schema-aware XSLT processor.

Content

A sequence constructor.

Effect

The following sections describe firstly how the content of the document node is constructed and secondly how document-level validation works.

The Content of the Document

The

instruction creates a new document node. The content of the document is constructed by evaluating the sequence constructor within the

element.

The child nodes of the new document node are constructed in a process that is very similar to that used for constructing the content of an element node, described under

on page 306. There are differences, however, because unlike an element node, a document node cannot have attribute or namespace nodes.

Although the XML specification requires a well-formed document to contain exactly one element node, optionally preceded or followed by comments and processing instructions, this restriction is not carried forward into the XDM data model. In XDM, a document node can contain any sequence of elements, text nodes, comments, and processing instructions (including an empty sequence) as its children. In fact, a document node can have any content that is allowed for an element node, except for the namespaces and attributes.

The process of forming the content of the document node is described below.

The first stage is to evaluate the sequence constructor contained in the

instruction (or in any other instruction that is being used to create a new document node, for example,

,

,

, or

). The sequence constructor is a sequence of instructions, and as its name implies, the result of evaluating these instructions is a sequence of items. Usually these values will all be newly constructed nodes but the sequence might also contain atomic values and/or references to existing nodes.

The way that the instructions in the sequence constructor are evaluated is described in the rules for each instruction; the items produced by each instruction are concatenated together (in the order in which the instructions appear in the stylesheet) to produce the final result sequence.

The second stage of the process is to use the result sequence delivered by evaluating the sequence constructor to create the content of the new document node. This process works as follows:

1.
If there are any atomic values in the sequence, they are converted to strings using the XPath casting rules.

2.
Any sequence of adjacent strings is converted to a single text node, using a single space as a separator between adjacent strings.

3.
If there is a document node in the sequence, then it is replaced in the sequence by its children (this may produce an arbitrary sequence of elements, text nodes, comments, and processing instructions).

4.
Adjacent text nodes within the sequence are combined into a single text node,
without
any space separator. Zero-length text nodes are removed completely.

Other books

The Lost Bird by Margaret Coel
Mrs. Ted Bliss by Stanley Elkin
The Mosaic of Shadows by Tom Harper
Tales of Adventurers by Geoffrey Household
Obsession by Maya Moss
Taking Liberties by Diana Norman
Living With Leanne by Margaret Clark
Indexing by Seanan McGuire