XML technologies / XML / Python & XML / Transforming XML with XSLT / XSLT processors
(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)
There are many XSLT processors on the market, both free and commercial. XSLT matters because of the transformations it enables, but the processor performs the actual work. Depending on your environment, you may choose a processor for its speed or accessibility from a platform such as Python. Alternatively, you may choose one you can control programmatically.
An XSLT processor applies an XSL stylesheet’s transformation rules to an existing XML document to produce a new document. The W3C describes XSLT as intended for XML-to-XML transformation. That is true, but it can also produce HTML or other formats. It is often used to transform XML into HTML or XHTML for viewing in a web browser.
XSLT is an independent language with no special connection to Python. You can therefore convert documents for Python programs using any XSLT processor. To embed XSLT functionality within Python programs, however, you need a processor accessible from Python, either natively, such as 4XSLT, or through a bridge, as when using MSXML 3.0 from Python, as discussed in Working with MSXML 3.0 ).
For Python, the 4XSLT package is an open-source XSLT processor usable from both the command line and Python programs. It is implemented mainly in Python, with some C modules for performance. Fourthought, Inc. provides 4XSLT as part of its 4Suite package.
Other languages and platforms have XSLT processors that can perform batch transformations for use in Python applications. Microsoft Internet Explorer includes an XSLT processor and can transform XML to HTML in the client browser, although versions before 6.0 are highly nonconformant. SAXON is a collection of XML tools including a Java-based XSLT processor running in any Java Virtual Machine. Sablotron is a fast C++ XSLT processor. The W3C XSLT site contains many links to XSLT software.
For the rest of this section, we use 4XSLT because it is entirely Python-based and makes its functionality available at runtime in Python applications.
Copyright © 2002 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "Python & XML" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top