Inside XSL-T (1/4) - exploring XML
Inside XSL-T
Now that we have had so many columns with XSL examples and so few about XSL, it seems like a good idea to study XSL in more detail. XSL comes out to be a very generic mechanism for transforming document trees, at least the paperless ones...
XSL was initially devised to solve two problems:
- Transforming an XML document into something else.
- Formatting an XML document for display on a page-oriented device, such as a printer or a browser.
Subsequently it has proven difficult to solve the second problem in a fashion that satisfies all the different requirements from low resolution screen displays all the way to hi-res printing and copying. Furthermore, screen formatting is currently done with Cascading Style Sheets (CSS), so little interest developed in yet another method. The World Wide Web Committee (W3C) then decided to split the two tasks into separate sub-standards, XSL Transformations (XSL-T) and XSL formatting objects (XSL-FO). While XSL-T has been an official recommendation since November of last year, XSL-FO is still in the making.
The T in XSLT
A transformation expressed in XSLT describes rules for transforming a source tree into a result tree. The transformation is achieved by associating patterns with templates. Whenever a pattern matches elements in the source tree, a template is used to create part of the result tree. The result tree is separate from the source tree, and their structures can be completely different. In constructing the result tree, elements from the source tree can be filtered and reordered, and new elements can be added. A transformation expressed in XSLT is called a stylesheet in the case where XSLT is transforming into a display language, such as HTML or WML.
Stylesheet structure
This example shows the structure of a stylesheet. Ellipses (...
)
indicate where attribute values or content have been omitted. Although this
example shows one of each type of allowed element, stylesheets may contain zero
or more of each of these elements.
<xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform"> <xsl:import href="..."/> <xsl:include href="..."/> <xsl:output method="..."/> <xsl:strip-space elements="..."/> <xsl:preserve-space elements="..."/> <xsl:decimal-format name="..."/> <xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/> <xsl:key name="..." match="..." use="..."/> <xsl:attribute-set name="..."> ... </xsl:attribute-set> <xsl:variable name="...">...</xsl:variable> <xsl:param name="...">...</xsl:param> <xsl:template match="..."> ... </xsl:template> <xsl:template name="..."> ... </xsl:template> </xsl:stylesheet>
The order in which the children of the xsl:stylesheet
element
occur is not significant except for xsl:import
elements and for
error recovery.
In addition, the xsl:stylesheet
element may contain any element
not from the XSLT namespace. Such elements can provide, for example,
- information about what to do with the result tree.
- information about how to obtain the source tree.
- metadata about the stylesheet.
- structured documentation for the stylesheet.
On to servlets.
Produced by Michael Claßen
All Rights Reserved. Legal Notices.
URL: https://www.webreference.com/xml/column17/index.html
Created: Aug 13, 2000
Revised: Aug 13, 2000