3.6. Using XSieve in bindings

Many languages, including PHP, Perl and Python, use libxml and libxslt for XML processing. These languages automatically support XSieve transformations because XSieve is implemented as a libxslt plugin.

Before executing XSieve transformations, set the environment variable LIBXSLT_PLUGINS_PATH to the value $XSIEVE_DIR/lib, where $XSIEVE_DIR is the XSieve installation directory.

Be aware that XSieve has issues which are not compatible with big long-running applications.

Example 1. Using XSieve in Python

The libxst package provides a sample program pyxsltproc.py, which is a Python re-implementation of XSLT processor xsltproc. In this example, we suppose that libxml and libxslt are installed to the private directories $LIBXML_DIR and $LIBXSLT_DIR, correspondingly.

$ export LIBXSLT_PLUGINS_PATH=$XSIEVE_DIR/lib   1
$ export PYTHONPATH=$LIBXML_DIR/lib/python2.3/site-packages:$LIBXSLT_DIR/lib/python2.3/site-packages   2
$ cd $XSIEVE_SRC_DIR/example/hello              3
$ python $LIBXSLT_DIR/share/doc/libxslt-python-1.1.15/examples/pyxsltproc.py hello.xsl hello.xsl       4
<?xml version="1.0"?>                           5
<article id="hw">
  <title>Hello</title>
  <para>Hello, <object>World</object>!</para>
</article>
Memory leak 159 bytes                           6
1

Set the path to the XSieve plugin binary.

2

Specify Python to use the private versions of the libxml and libxslt bindings.

3

Enter to the directory with the sample XSieve program hello.xsl.

4

Run the Python XSLT processor.

5

The XSieve transformation result.

6

pyxsltproc.py is smart to detect some memory problems.