Chapter 4. XSL Translators Use

Table of Contents

XT/XP
Installing XT/XP
Publishing in HTML with XT
Xalan J2
Installing Xalan J2
Publishing in HTML with Xalan
xsltproc -- The Gnome Toolkit
Installing the Gnome libraries
Publishing in HTML with xsltproc
Saxon

This chapter gives standard intall procedure examples for the most usual translators: XT, Xalan, xsltproc and Saxon. Besides, it tries to list the particularities in using each of them.

XT/XP

Installing XT/XP

XT is a translator that seems a bit lighter than Xalan. However some features are missing. Anyway, HTML transformation works without problem provided that the N. Walsh XSL stylesheets used are compliant to this tool. Here is an install procedure example:

  1. First, check that java is installed.

  2. Download the XT distribution.

  3. Download an XML parser that supports SAX, let's say XP.

  4. Unzip de XT/XP packages:

    % mkdir /usr/local/xt /usr/local/xp
    % unzip xt.zip -d /usr/local/xt
    % unzip xp.zip -d /usr/local/xp
        
  5. Put the XT libraries (xt.jar and sax.jar) and the XP library (xp.jar) in your CLASSPATH:

    % CLASSPATH=$CLASSPATH:/usr/local/xt/xt.jar:/usr/local/xt/sax.jar
    % CLASSPATH=$CLASSPATH:/usr/local/xp/xp.jar
    % export CLASSPATH
        

Publishing in HTML with XT

Creating a single HTML file

To create a single HTML file use the html/docbook.xsl stylesheet:

java com.jclark.xsl.sax.Driver mydoc.xml (path)/docbook/htm/docbook.xsl > mydoc.html
    

Chunking with XT

Chunking with XT is possible by using the dedicated html/xtchunk.xsl stylesheet. The stylesheet creates a file for each part, chapter and section named automatically with their identifier.

java com.jclark.xsl.sax.Driver mydoc.xml (path)/docbook/htm/xtchunk.xsl > mydoc.html
    

Xalan J2

Xalan Java 1.x should not be used anymore, since the current XSL stylesheets cannot work with these versions anymore. I suggest to use Xalan Java 2.0.1, that works fine on my machine.

Installing Xalan J2

  1. First, check that java is installed.

  2. Download the package from the Xalan page. You don't need to download an XML parser since Xalan provides the Xerces java archive.

  3. Unzip the package:

    % cd /usr/local/xslt/
    % tar xvzf xalan-j_2_*_*.tar.gz
        
  4. Put the Xalan java archives in your CLASSPATH:

    % CLASSPATH=$CLASSPATH:/usr/local/xslt/xalan-j_2_*_*/bin/xalan.jar
    % CLASSPATH=$CLASSPATH:/usr/local/xslt/xalan-j_2_*_*/bin/xerces.jar
    % export CLASSPATH
        
  5. Some extensions are sometimes required by the stylesheets (e.g, for tables). Add the DocBook XSL Xalan2 extension archive in your CLASSPATH:

    % CLASSPATH=$CLASSPATH:/(path)/docbook/extensions/xalan2.jar
        

Publishing in HTML with Xalan

Particularity

Absolute paths for XSL stylesheets must be prefixed by file://. For instance, using the HTML stylesheet with Xalan looks like:

java org.apache.xalan.xslt.Process -in mydoc.xml -xsl file:///path/to/docbook/html/docbook.xsl

    

Creating a single HTML file

To create a single HTML file use the html/docbook.xsl stylesheet:

java org.apache.xalan.xslt.Process -in mydoc.xml -xsl file:///(path)/html/docbook.xsl -out mydoc.html
    

Chunking with Xalan

You can chunk by using the html/chunk.xsl stylesheet. The stylesheet creates a file for each part, chapter and section named automatically with their identifier.

java org.apache.xalan.xslt.Process -in mydoc.xml -xsl file:///(path)/html/chunk.xsl
    

xsltproc -- The Gnome Toolkit

xsltproc is the XSLT program example provided with the libxslt library from Gnome. The libxslt/libxml2 libraries development is a Gnome project, written entirely in C (not in C++ nor in Java). This default XSLT is good enough to publish the XML documents, but one can always create its own program linked to the Gnome libraries. The big advantage of these libraries are:

  • It is really fast,

  • No java virtual machine is needed,

  • It seems closer to the XML/XSL specifications.

Installing the Gnome libraries

Here is an install procedure example, for those installing the packages from the gzipped sources:

  1. Download the libxml2 library from the XML page.

  2. Unpack the package:

    % tar xvfz libxml2-<version>.tar.gz
        
  3. Configure and build the binaries:

    % cd libxml2-<version>
    % ./configure
    % make
        
  4. Install the package:

    % make install
        
  5. Download the libxslt library from the XSLT page.

  6. Unpack the package:

    % tar xvfz libxslt-<version>.tar.gz
        
  7. Configure and build the binaries:

    % cd libxslt-<version>
    % ./configure
    % make
        
  8. Install the package:

    % make install
        

Once done, xsltproc is available, and the libxml2/libxslt libaries are installed.

Publishing in HTML with xsltproc

Catalog resolution

Libxml2 supports catalog resolution, and thus xsltproc supports this feature too. To use you just need to:

  1. Define a catalog that gives the XML DocBook DTD path. For example the catalog would look like this:

     -- Catalog to find the DTD DocBook XML file--
     
    PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
        "file:///path/to/docbook/docbkx412/docbookx.dtd"
         
  2. Add this catalog location in the SGML_CATALOG_FILES variable:

    export SGML_CATALOG_FILES=$SGML_CATALOG_FILES:/path/of/the/catalog
         
  3. Call xsltproc with the option --catalogs.

Creating a single HTML file

To create a single HTML file use the html/docbook.xsl stylesheet:

xsltproc --catalogs /(path)/html/docbook.xsl mydoc.xml > mydoc.html
    

Chunking with xsltproc

You can chunk by using the html/chunk.xsl stylesheet. The stylesheet creates a file for each part, chapter and section named automatically with their identifier.

xsltproc --catalogs /(path)/html/chunk.xsl mydoc.xml
    

Saxon

TDB.