libxslt: An Extended Tutorial

Panos Louridas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Table of Contents

Introduction
Setting the Scene
Program Start
Arguments Collection
Parsing
File Processing
*NIX Compiling and Linking
MS-Windows Compiling and Linking
Building the Ports in MS-Windows
zlib, iconv and All That
The Complete Program

Introduction

The Extensible Stylesheet Language Transformations (XSLT) specification defines an XML template language for transforming XML documents. An XSLT engine reads an XSLT file and an XML document and transforms the document accordingly.

We want to perform a series of XSLT transformations to a series of documents. An obvious solution is to use the operating system's pipe mechanism and start a series of transformation processes, each one taking as input the output of the previous transformation. It would be interesting, though, and perhaps more efficient if we could do our job within a single process.

libxslt is a library for doing XSLT transformations. It is built on libxml, which is a library for handling XML documents. libxml and libxslt are used by the GNOME project. Although developed in the *NIX world, both libxml and libxslt have been ported to the MS-Windows platform. In principle an application using libxslt should be easily portable between the two systems. In practice, however, there arise various wrinkles. These do not have anything to do with libxml or libxslt per se, but rather with the different compilation and linking procedures of each system.

The presented solution is an extension of John Fleck's libxslt tutorial, but the present tutorial tries to be self-contained. It develops a minimal libxslt application (libxslt_pipes) that can perform a series of transformations to a series of files in a pipe-like manner. An invocation might be:

libxslt_pipes --out results.xml foo.xsl bar.xsl doc1.xml doc2.xml

The foo.xsl stylesheet will be applied to doc1.xml and the bar.xsl stylesheet will be applied to the resulting document; then the two stylesheets will be applied in the same sequence to bar.xsl. The results are sent to results.xml (if no output is specified they are sent to standard output).

The application is compiled in both *NIX systems and MS-Windows, where by *NIX systems we mean Linux, BSD, and other members of the family. The gcc suite is used in the *NIX platform and the Microsoft compiler and linker are used in the MS-Windows platform.

Setting the Scene

We need to include the necessary libraries:

  
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
  
  #include <libxslt/transform.h>
  #include <libxslt/xsltutils.h>
  

The first group of include directives includes general C libraries. The libraries we need to make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file declares the API for some generic utilitith make libxslt work are in the second group. The transform.h header file declares the API that does the bulk of the actual processing. The xsltutils.h header file decla