How Does XSLT Work?


What Is XSLT, XSL, and XPath?

XSLT was originally part of XSL, the Extensible Stylesheet Language. In fact, it’s still technically a part of
it. The XSL specification describes XSL as a language with two parts: a language for transforming XML
documents and an XML vocabulary for describing how to format document content. This vocabulary
is a collection of specialized elements called “formatting objects” that 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.

XSL transforms an XML document into another XML document by transforming each XML element into
an (X)HTML element. XSLT can also add new elements into the output file, or remove elements. It can
rearrange and sort elements, and test and make decisions about which elements to display, and a lot more.

One great feature of XSLT is its capability, while processing any part of a document, to grab information
from any other part of that document. The mini-language developed 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
element.” This capability proved so valuable that the W3C also broke XPath out into its own specification
so that other W3C specifications could incorporate this language.



The transformation process needs two input files, the XML document, which makes up the source tree
and the XSLT file, which consists of elements used to transform data to the required format. You can also
use more than one XSLT file in the transformation process. The output file is a result tree, which can be
an XML, HTML, or any other format. Several parsers are available for the transformation process using
XSLT. Parsers are applications that validate an XML document and perform transformations to generate
the required output. Figure 7-1 shows the transformation process.


learn guitarphysics learnteliphonyxmlphysicsenjoylife