XML technologies / XML / Python & XML / Transforming XML with XSLT / Using XSLT from the command line
(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)
Before learning to embed XSLT transformations in Python programs, we first need to focus on XSLT itself. While learning, it is generally easier to launch transformations from the command line than from a Python script. Many processors provide a command-line transformation tool. We use the 4XSLT package included in 4Suite; if you prefer another tool, consult its documentation for correct usage.
4XSLT includes a script for running transformations from the command line. On Windows, the script 4xslt.bat is installed by the 4Suite installer in the Scripts directory of your Python installation. To make the script easier to use, either add the Scripts directory to your environment variable PATH or copy the file 4xslt.bat to a directory already listed in PATH.
Normal execution of 4xslt requires only two parameters: the XML document to transform and the stylesheet to apply. This example was used to apply the stylesheet from the example ships.xsl and produce the output shown in the example ships2.html:
C:\mein-dir> 4xslt ships.xml ships.xsl > ships2.html
To save the transformation result, redirect the output to a file.
4XSLT and the 4xslt script support both simplified and standalone stylesheets. Embedded stylesheets are not supported.
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