XSLT primer

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

XSLT is a flexible and powerful language for transforming XML documents. An XSLT stylesheet contains detailed instructions on how to process the different types of elements in an XML document. The instructions in the stylesheet are then interpreted by a special program, called an XSLT processor, which applies them to the input document to produce another document as output.

XSLT is part of the XSL family of standards developed by the W3C for expressing style information in XML documents. In addition to XSLT, XSL consists of two other standards: XPath and XSL Formatting Objects (XSL-FO). XPath is a special syntax for referring to specific parts of an XML document. XPath syntax is used extensively in XSLT stylesheets for specifying what parts of an input document should be selected.

XSL-FO is an XML vocabulary for specifying the detailed layout and formatting of a document. XSLT was originally developed as a means for applying styles to arbitrary XML documents by translating them into XSL-FO documents. However, XSLT has turned out to be much more broadly useful and is now used as a general-purpose transformation language for XML documents.

The primary purpose of XSLT is for converting one type of XML document into another. For example, there are XSLT stylesheets for converting DocBook documents into XHTML or for converting MathML expressions into Scalable Vector Graphics (SVG) graphics. However, the output is not restricted to being in XML format. By using an appropriate stylesheet, you can convert XML documents into other document formats, such as HTML or PDF.

XSLT is, in fact, widely used for converting XML documents into HTML so they can be displayed by Web browsers. A Web browser cannot properly interpret an arbitrary XML document since the document can contain tag names that are not defined in HTML. The solution is to write an XSLT stylesheet that replaces the document-specific element names with standard HTML elements. The resulting HTML document can even include CSS commands for specifying how different elements should be formatted. XSLT and CSS are therefore complementary and can be used effectively in combination with each other.

XSLT is powerful because it allows you to select specific parts of the XML document tree in any desired order and perform arbitrary transformations on them. An XSLT processor can select and manipulate an element based on various criteria such its position in the document tree, the text it contains, or the names and values of its attributes. It is possible to write an XSLT stylesheet, for example, to extract all elements with a certain name, and then rename them, combine them with additional text, and insert them into the output document in a different order.

XSLT stylesheets have a variety of uses in MathML documents, from specifying styles for particular types of notation to creating macros for complicated markup. In the rest of this chapter, we give a brief overview of the key concepts of XSLT and then provide some simple examples of how it can be used in the context of MathML.



<< back next >>




Tipp der data2type-Redaktion:
Zum Thema MathML bieten wir auch folgende Schulungen zur Vertiefung und professionellen Fortbildung an:


Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America