XALAN Tutorial

by Matt Flood

NOTE: Instructions updated for version 1.6 can be found here.

This tutorial will show you how to install Xalan 1.4 and compile an application that uses Xalan on RedHat linux system.


Step 1. Download the xalan and xerces binaries

Visit http://xml.apache.org/
Find and download Xalan-C_1_4-linux.tar.gz
Find and download xerces-c2_1_0-linux7.2gcc31.tar.gz

 

Step 2. Extract the binaries

>tar -xzf Xalan-C_1_4-linux.tar.gz
>tar -xzf xerces-c2_1_0-linux7.2gcc31.tar.gz

Give them simple names:

>mv xml-xalan xalan
>mv xerces-c2_1_0-linux7.2gcc31 xerces

Step 3. Copy the shared libraries to the system directory (/usr/lib)

>su

>cp xalan/c/lib/libxalan-c1_4_0.so /usr/lib
>cp xerces/lib/libxerces-c.so.21.0 /usr/lib

AND EITHER

>cp xerces/lib/libxerces-c.so.21 /usr/lib
>cp xerces/lib/libxerces-c.so /usr/lib

OR (instead of copying all 3 xerces libraries)

>ln -s /usr/lib/libxerces-c.so.21.0 /usr/lib/libxerces-c.so.21
>ln -s /usr/lib/libxerces-c.so.21 /usr/lib/libxerces-c.so

 

Step 4. Link libstdc++.so.4 to the existing c++ library so the compiler can find it

>ln -s /usr/lib/libstdc++.so.5 /usr/lib/libstdc++.so.4

 

Step 5. Test the installation by executing the Xalan binary

>xalan/c/vin/Xalan

Which should result in output similar to:

Xalan version 1.4.0
Xerces version 2.1.0
Usage: Xalan [options] source stylesheet

etc....

 

Step 6. Create test xml file called foo.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<maphrase>
My First Xalan XML Page!
</maphrase>


Step 7. Create test xslt file called foo.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="maphrase">
<html><body><xsl:apply-templates/></body></html>
</xsl:template>
</xsl:stylesheet>

 

Step 8. Create a test application


test.cpp uses foo.xml, foo.xsl, and foo-out.html
test2.cpp uses a string containing xml, foo.xsl, and outputs to cout (More like a CGI application would work)
test3.cpp Sample CGI application


compile test.cpp with:

>g++ -o test -Ixalan/c/src -Ixerces/include -Ixercesc test.cpp /usr/lib/libxalan-c1_4_0.so /usr/lib/libxerces-c.so

compile test2.cpp with:

>g++ -o test2 -Ixalan/c/src -Ixerces/include -Ixercesc test2.cpp /usr/lib/libxalan-c1_4_0.so /usr/lib/libxerces-c.so