XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / Processing XML with XSLT
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)
An XML document describes only the structure of its information, which must be put into a suitable form, for example for presentation. This often involves transformation of that structure, such as sorting or filtering. Even information exchange in XML, as required in B2B, needs conversion to differently structured target formats. New content may come from other sources or be derived by summarizing or calculating original data.
Figure: Schematic XSLT processing.
The original remains intact: a source document always produces a new result document, either XML again or almost any other format.
This kind of XML processing is described using XSL, the “Extensible Stylesheet Language”, an XML application. XSL has two subdivisions: XSL-FO (XSL Formatting Objects) handles print presentation. (Note: A separate book would be needed for XSL-FO. For us, note that generating an FO representation from XML is itself an XSLT transformation, so XSL-FO can follow XSLT.)
The other subdivision, this book’s subject, concerns only transformation of XML documents: XSLT, the “Extensible Stylesheet Language Transformations”. Historically, documents written in XSLT are called “XSLT stylesheets” even though their functionality goes far beyond static presentation.
Since this book is titled “XSLT 2.0 und XPath 2.0”, it also frequently discusses XPath. The “XML Path Language” is primarily a path-description language. Embedded in XSLT, XPath expressions control transformation and generate content. They describe information through match patterns, or a path for direct access. XPath navigates the source and makes its information available for processing. Expressions can also generate new content independently of the source and send it to the result.
XPath and XSLT versions must match!
With XSLT 2.0 always use XPath 2.0; similarly, XSLT 1.0 works only with XPath 1.0. Other combinations or mixtures within a document are expressly forbidden.
XPath 2.0, the current version discussed here, is a substantial subset of XQuery 1.0, a powerful XML query language whose full functionality is usable only independently of XSLT.
There is broad compatibility between XSLT 1.0 and 2.0. Every 1.0 element remains, sometimes with changed behavior or added features. This reflects XPath 2.0’s expansion and XSLT 2.0’s key difference: support for typing of processed information according to an XML Schema.
XSLT 1.0 is not this book’s subject, though compatibility problems are discussed where necessary, especially in the reference. Henceforth XSLT 2.0 and XPath 2.0 are shortened to XSLT and XPath.
Note: Install an XSLT 2.0 processor now!
The following simple examples can be understood theoretically. To run them immediately, first install the XSLT processor Saxon 9 (or Kernow with Saxon 8.9), or AltovaXML Suite, optionally with your preferred XML development environment.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn