- Terminology changes
-
XSLT makes a number of refinements to terminology, and a glossary is now available at the end of the specification. For example, the term result tree fragment has been replaced by the term temporary tree. A temporary tree is natively a sequence of nodes, obviating the need for an extension function for node-sets to cast a result tree fragment to a node-set. Another example: a template is now known as a sequence constructor. A sequence can contain nodes or atomic values.
- XHTML output
-
In addition to xml, html, and text, XSLT 2.0 adds the xhtml output method (see Section 20 of XSLT 2.0 and Section 5 of the serialization specification).
- Multiple result trees
-
One of the most welcome new features in XSLT 2.0 is the ability to produce multiple result trees, rather than just one. This is accomplished through the result-document element. This element is similar to the saxon:output element you saw in the last chapter, though it has somewhat different attributes. You will see an example of this in Section 16.3, later in this chapter. Also see Section 19.1 of XSLT 2.0.
- Regular expressions
-
A regular expression describes text with a pattern made up of characters that have special meaning within the expression. The analyze-string element, together with matching-substring and non-matching-substring child elements, allows you to analyze a string using a regular expression. The XPath 2.0 functions matches( ), replace( ), and tokenize( ) also make use of regular expressions. See "Using Regular Expressions" later in this chapter for an example. See also Section 15 of XSLT 2.0.
- Validation support for XML Schema
-
A schema-aware XSLT processor supports validation using W3C XML Schema. This support is not required, however. There is also a conformance level for a basic XSLT processor that does not support validation. See Section 21 of XSLT 2.0. XML Schema support, in fact, goes well beyond just validation (in the sense of rejecting invalid documents). Once a source document has been processed by a schema, you can use information about the types of different nodes. For example, you could write a template rule that processes any attribute of type date.
- Date format
-
Just as numbers could be formatted with the format-number( ) function and the decimal-format element in XSLT 1.0, a date may be formatted with the format-date( ) function used with the date-format element. See Section 16.5 of XSLT 2.0.
- Character maps
-
A new character map declaration using the character-map element enables a stylesheet to support sets of characters for output. Similarly, the output-character element maps a single character to a string for output. This functionality is an improvement over the disable-output-escaping attribute functionality in XSLT 1.0. See Section 20.1 of XSLT 2.0.
- Grouping
-
Using the new for-each-group element, XSLT 2.0 now offers a built-in grouping feature, rather than depending on common yet nonstandard approaches used in XSLT 1.0. See "Grouping in XSLT 2.0" in this chapter as well as Section 14 of XSLT 2.0.
- Parameters in new places
-
You can pass a parameter to the template rule having the highest import precedence using with-param as a child of the apply-imports element. You can also pass parameters using the next-match element, which matches other template rules beside the current one (that also happens to have the highest priority). See Section 6.7 of XSLT 2.0.
- New elements
-
Besides those already mentioned, XSLT 2.0 adds a half dozen other elements:
- function element
-
Defines a stylesheet function. Stylesheet functions are similar to named templates, except that rather than invoking them using a call-template instruction, you can invoke them using a function call anywhere in an XPath expression. This makes them more versatile than templates for example, you can write a function to compute a sort key.
- import-schema element
-
Imports an XML Schema for validation by a schema-aware XSLT processor.
- namespace element
-
Creates a namespace node. This is useful (in rare cases) when you need to decide at runtime which namespaces to include in the result tree.
- next-match element
-
Overrides a template rule with another rule of lower priority or precedence; works with the current or imported stylesheets.
- sequence element
-
Constructs a sequence of nodes or atomic values.
- sort-key element
-
Declares a named sort key; holds one or more sort elements.
- New attributes on existing elements
-
A number of new attributes appear on elements that have existed since XSLT 1.0 and are listed here:
- as attribute
-
Added to key, param, template, and variable, this attribute specifies the required type for the result.
- collation attribute
-
Identifies a named collation for ordering strings; this attribute has now been added to the key and sort elements.
- copy-namespaces attribute
-
Available on the copy and copy-of elements with a value of yes or no. The default is yes.
- disable-output-escaping attribute
-
Now appears on attribute; it appeared only on text and value-of in XSLT 1.0.
- type attribute
-
Appears on attribute, copy, copy-of, and element in order to associate with the item type from a schema.
- undeclare-namespaces attribute
-
Appears on output to specify whether to undeclare namespaces in the output. This feature anticipates support for XML Namespaces 1.1, which allows namespaces to be undeclared.
- validation attribute
-
Appears on attribute, copy, copy-of, and element, with one of four possible values: lax, preserve, strict, or strip. This is closely associated with the type attribute.
- New attributes on output
-
A number of new attributes also have been added to the output element:
- escape-uri-attributes attribute
-
Specifies whether a processor escapes URIs in HTML and XHTML; value must be yes or no.
- include-content-type attribute
-
Specifies whether to add a meta element in HTML and XHTML output; value must be either yes or no.
- name attribute
-
An output declaration may now be labeled with a name attribute. This is used in conjunction with result-document which allows multiple result trees; these can either all use the same output format or use a variety of different output formats.
- normalize-unicode attribute
-
Indicates whether, yes or no, the Unicode output should use Normalization Form C (see http://www.unicode.org/unicode/reports/tr15/).
- use-character-maps attribute
-
Identifies a named character map defined by the character-map element.
That's just a few of the new features in XSLT 2.0; next, I'll discuss some of the new ones found in XPath 2.0.