XALAN Tutorial (Version 1.6)
By: Matt Flood
These are the steps I took to install and use the XALAN 1.6 XSLT Engine.
Part I
Obtain the source distributions for Xalan, Xerces and ICU
(ICU allows you to use number formatting)
If you don't want ICU, then ignore the items highlighted in GREEN
Part II
Make and Install ICU, Xerces and Xalan
(ICU allows you to use number formatting)
If you don't want ICU, then ignore the items highlighted in GREEN
$>chmod +x runConfigureICU configure install-sh
$>./runConfigureICU --help
$>./runConfigureICU LinuxRedHat -P/usr (yes - even on SuSE)
$> ./configure -prefix=/usr
$>gmake
$>su
$>gmake install
$>exit (from root)
Install Xerces
http://xml.apache.org/xerces-c/build-misc.html#ICUPerl
http://xml.apache.org/xerces-c/build.html
$>export XERCESCROOT=/home/homeless/bin/xerces-c-src2_4_0
$>export ICUROOT=/home/homeless/bin/icu
$>cd src
$>cd xercesc
$>./runConfigure -plinux -cgcc -xg++ -minmem -nsocket -tnative -rpthread -ticu -P/usr
$>gmake
$>su
$>gmake install
$>exit (from root)
Install Xalan
http://xml.apache.org/xalan-c/readme.html#unix
$>export XALANCROOT=/home/homeless/bin/xml-xalan/c
$>export XALAN_USE_ICU=1
$>cd c
$>cd src
$>cd xalanc
$>./runConfigure -plinux -cgcc -xc++ -P/usr
$>gmake
$>su
$>gmake install
$>exit (from root)
Test the installation. Possibly copy libraries from /usr/local/lib to /usr/lib
$> cd ../../../..
$> cd xml-xalan/c/bin
$> ldd Xalan
If the output shows that some libraries cannot be found then:
$> su
$> cd /usr/local/lib
$> cp libxalan*.* /usr/lib
$> cp libxerces*.* /usr/lib
$> cp libicu*.* /usr/lib
Part III
Examples
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
// We use a macro for every Xerces / Xalan
// object we will use
//
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(XSLTInputSource)
XALAN_USING_XALAN(XSLTResultTarget)
int main(void)
{
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
// The following block ensures that
// the XalanTransformer instance is
// destroyed before XMLPlatformUtils::Terminate is called
//
{
XalanTransformer theXalanTransformer;
XSLTInputSource xmlIn("foo.xml");
XSLTInputSource xslIn("foo.xsl");
XSLTResultTarget xmlOut("foo-out.xml");
int theResult = theXalanTransformer.transform(xmlIn,xslIn,xmlOut);
}
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
XalanTransformer::ICUCleanUp();
return 0;
}
compile test.cpp
g++ test.cpp -lxalan-c -lxerces-c
test a.out using foo.xml and foo.xsl (below)
foo.xml
<?xml version="1.0"?>
<!DOCTYPE si>
<s1 title="s1 foo">
<s2 title="Foo">
<p>Hello</p>
</s2>
</s1>
foo.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s1">
<html>
<head><title><xsl:value-of select="@title"/></title></head>
<body bgcolor="#ffffff" text="#000000">
<xsl:apply-templates select="s2"/>
</body>
</html>
</xsl:template>
<xsl:template match="s2">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td bgcolor="#006699">
<font color="#ffffff" size="+1">
<b><xsl:value-of select="@title"/></b>
</font>
</td>
</tr>
</table>
<xsl:apply-templates/>
<br/>
</xsl:template>
<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>
</xsl:stylesheet>