What Is XSLT (And XSL, And XPATH)?
October 19, 2001
Extensible Stylesheet Language Transformations (XSLT) is a
language that lets you convert XML documents into other XML
documents, into HTML documents, or into almost anything you like.
When you specify a series of XSLT instructions for converting a
class of XML documents, you do so by creating a “stylesheet,” an
XML document that uses specialized XML elements and attributes
that describe the changes you want made. The definition of these
specialized elements and attributes comes from the World Wide Web
Consortium (W3C), the same standards body responsible for XML and
HTML.
Why is XSLT necessary? XML’s early users were excited about their
new ability to share information, but they gradually realized
that sharing this information often assumed that both sharing
parties used the same schema or DTD—a lot to assume. Assembling a
schema that both parties could agree on was a lot of trouble,
especially if they didn’t need to exchange information often.
XSLT solves this problem by pro-viding an easy, W3C-sanctioned
way to convert XML documents that conform to one schema into
documents that conform to others, making information much easier
to pass back and forth between different systems.
Figure 1.1 XSLT stylesheets can automate
the conversion of the same input into multiple output
formats.
XSLT was originally part of the Extensible Stylesheet Language
(XSL). In fact, XSLT is still technically a part of XSL. The XSL
specification describes XSL as a language with two parts: a
language for transforming XML documents and an XML vocabu-lary
for describing how to format document content. This vocabulary is
a collection of specialized elements called “formatting objects,”
which specify page layout and other presentation-related details
about the text marked up with these elements’ tags: font family,
font size, margins, line spacing, and other settings.
Because a powerful formatting language should let you rearrange
your input document in addition to assigning these presentation
details, the original XSL spec-ification included specialized
elements that let the stylesheet delete, rename, and reor-der the
input document’s components. As they worked on this collection of
elements, the W3C XSL Working Group saw that it could be useful
for much more than con-verting documents into formatting object
files—that it could convert XML docu-ments into almost
anything else. They called this transformation language
XSLT and split it out into its own separate specification,
although the XSL specification still said that everything in the
XSLT specification was considered to be part of the XSL spec-
ification as well.
One great feature of XSLT is its ability, while processing any
part of a document, to grab information from any other part of
that document. The mini-language devel-oped as part of XSLT for
specifying the path through the document tree from one part to
another is called "XPath." XPath lets you say things like "get
the revisionDate attribute value of the element
before the current element’s chapter ancestor ele-
ment." This ability proved so valuable that the W3C also broke
XPath (see figure 1.2) out into its own specification so that
other W3C specifications could incorporate this language. For
example, an XLink link can use an XPath expression as part of an
XPointer expression that identifies one end of a link.
Figure 1.2 The W3C released the first
Working Draft of XSL in August 1998, split XSLT out into its own
Working Draft in April of 1999, then split XPath out from XSLT
into its own working Draft in July 1999.
XSLT Quickly
XSLT and Alternatives - Page 2
|