Using the Xalan-Java XSLT Processor

There are many available XSLT processors (programs that implement the XSLT Recommendation of W3C). We will use Xalan-Java as our XSLT processor in the following exercises.

What is Xalan-Java and where to get it?

Xalan-Java is an XSLT processor for transforming XML documents into HTML, text, or other XML document types. It implements XSL Transformations (XSLT) Version 1.0 and XML Path Language (XPath) Version 1.0 and can be used from the command line, in an applet or a servlet, or as a module in other program.

Xalan-Java is implemented in Java and has been developed as part of the Apache XML Project by the Apache Software Foundation. Xalan-Java is open source software. The software can be downloaded from its web site (http://xml.apache.org/xalan-j/) and can be freely used, distributed, and modified.

How to install Xalan-Java?

Before you download and install Xalan-Java, make sure that the Java Runtime Environment (JRE) has already been properly installed in your system. JRE often is pre-installed in a computer system. If not, you can find it at Sun's web site (http://java.sun.com/j2se/1.4.2/download.html).

After downloading the Xalan-Java package and unzipping it, you can find the software in a directory named xalan-j_2_7_0 (or something like that). You can move it to a system directory, say /MySystemLibrary/xalan-j_2_7_0, to be used later on. We will be using Xalan-Java's command-line utility which is documented at http://xml.apache.org/xalan-j/commandline.html. Here is an example:

java org.apache.xalan.xslt.Process -IN foo.xml -XSL foo.xsl -OUT foo.out

The above command requests the XSLT processor to apply stylesheet foo.xsl to XML document foo.xml and write the output to file foo.out. However, you must first take care that the directory /MySystemLibrary/xalan-j_2_7_0 is included in the CLASSPATH environment variable. How to do this will depend on your system. If you are using bash as the shell language, you can add the following line to file .profile in your home directory:

export CLASSPATH=$CLASSPATH:/MySystemLibrary/xalan-j_2_7_0

Note: Your computer may have already installed Xalan-Java as part of the operating system. It may have set up the CLASSPATH environment variable as well. (This is the case for Mac OS X Version 10.4.9.) In such a case, you need not download and install Xalan-Java at all!

Try them on!

Use the examples in Section D of XSL Transformations (XSLT) Version 1.0 and try them on your computer!

Document Example:
The input document (doc.xml), its DTD (doc.dtd), and the stylesheet (doc2html.xsl).
Data Example:
The input document (sales.xml) and the stylesheets (sales2html.xsl, sales2svg.xsl, sales2vrml.xsl).