Saxon/C  0.3.1
Saxon Processor library for C/C++
 All Classes Functions Variables
Saxon/C Documentation

Back to web page

Saxon/C is an beta release of Saxon-HE on the C/C++ programming platform. APIs are offered currently to run XSLT 2.0 from C/C++ or PHP applications.

Platforms supported: Linux and Windows



To install the Saxon-HEC beta release, unzip the the file and execute the command './libsaxon-HEC-setup-v0.3.1' First step is to select the destination of where the product files will be installed. The product files are unpacked in the directory 'Saxon-HEC'

You need to setup the environment for the jet jvm. The jvm is in the directory JET-home=Saxonica/Saxon-HEC0.3.1/rt The directory JET-home/lib/i386 or JET_home/lib/amd64 (for 64-bit machines) must be listed in the LD_LIBRARY_PATH environment variable. For instance, if you are using bash or Bourne shell, use the following commands:

export LD_LIBRARY_PATH=/usr/lib/rt/lib/i386:$LD_LIBRARY_PATH

We assume that the 'rt' directory is in the location /usr/lib. The Saxon-HEC API assumes the library is installed as follows: '/usr/lib/' The directory 'saxon-data' must be copied to '/usr/lib'

PHP extension:

To build the php extension follow the steps below:

Run the commands:

Update the php.ini file (if using ubuntu it is usually in the location '/etc/php5/apache2/') to contain the php extension: insert the following in the Dynamic Extensions section:

Check that the extension has installed properly:

Getting started:

To get started please browse the Saxon/C API starting with the class SaxonProcessor class which acts as a factory class for generating the processors.


See the C code along with the build and run script are in the folder 'c'.


    SaxonProcessor *processor = new SaxonProcessor();
    XsltProcessor * xslt = processor->newTransformer();
    cout<<"Hello World"<<endl;
    cout<<"Test output: "<<xslt->xsltApplyStylesheet("cat.xml","test.xsl")<<endl;

    SaxonProcessor * processor = new SaxonProcessor(false);
    XsltProcessor * xslt = processor->newTransformer();
    XdmValue * xdmvaluex = new XdmValue("string", "Hello to you");
    if(xdmvaluex !=NULL){
        cerr<< "xdmvaluex ok"<<endl;            
    xslt->setParameter("a-param", xdmvaluex);
        const char * result = test->xsltApplyStylesheet(NULL, "xsl/foo.xsl");
    if(result != NULL) {
    } else {
        cerr<<"Result is NULL"<<endl;

See the files SaxonProcessor.cpp, XsltProcessor.cpp and XQueryProcessor.cpp

To compile the sample C++ program remove the line '#include 'php_saxon.h' in the file then execute the command:

g++ -m32 -o xsltProcessor -ldl -L . -lstdc++



SaxonProcessor class

SaxonProcessor() //constructor
XdmValue createXdmValue($value) //Create an XdmValue object. Value can be a boolean, int or string type
void setSourceValue(XdmValue $value) //The source used for a query or stylesheet. Requires an XdmValue object
void setSourceFile(string $filename) //The source used for query or stylesheet. Requires a file name as string
XdmValue parseString(string $str) // Create an Xdm node value from string 
XdmValue parseFile(string  $filename) // Create an Xdm node value from file
void setParameter(string $name, XdmValue $value) //Set the parameters required for XSLT stylesheet
void setProperty(string $name, string $value) // Set properties for Query or stylesheet.
void clearParameters()
void clearProperties()
void setStylesheetContent(string $str) //Stylesheet supplied as string
void setStylesheetFile(string $filename) // Stylesheet suplied as a file
void setQueryContent(string $str) // query supplied as a string
void setQueryFile($string $filename) // query supplied as a file
void transformToFile(string $outfilename) // compile and execute the stylesheet. Save the result to file
string transformToString() // compile and execute the stylesheet. Result returned as string. If there are failures then a null is returned
XdmValue transformToValue() // compile and execute the stylesheet. Result returned as an XdmValue object. If there are failures then a null is returned
void queryToFile(string $outfilename) // compile and evaluate the query. Save the result to file
XdmValue queryToValue() // compile and evaluate the query. Result returned as an XdmValue object. If there are failures then a null is returned
string queryToString() // compile and evaluate the query. Result returned as string. If there are failures then a null is returned
void exceptionClear()
string getErrorCode(int $i) // Get the ith error code if there are any errors
string getErrorMessage(int $i) // Get the ith error message if there are any error
int getExceptionCount() // Get number of error during execution or evaluate of stylesheet and query, respectively
string version() // Report the java Saxon-HE version 

XdmValue class

The XdmValue class is created via the createXdmValue method in the SaxonProcessor class

In the Saxon/C download please see the PHP file 'xsltExamples.php' in the 'samples' folder which contains many useful examples which will get you started. Example code from the xsltExamples.php file:

            $xmlfile = "xml/foo.xml";
            $xslFile = "xsl/foo.xsl";
        $proc = new SaxonProcessor();
                $version = $proc->version();
                echo 'Saxon Processor version: '.$version;
                $result = $proc->transformToString();               
        if($result != null) {               
          echo 'exampleSimple1:
'; echo 'Output:'.$result; } else { echo "Result is null"; } $proc->clearParameters(); $proc->clearProperties(); ?>

In the example below we show how to debug if something unexpected is happening. It is also very useful to examine the apache error.log file:

            $xmlfile = "xml/foo.xml";
            $xslFile = "xsl/foo.xsl";
        $proc = new SaxonProcessor();
                $result = $proc->transformToString();
                if($result == NULL) {
                    $errCount = $proc->getExceptionCount();
                    if($errCount > 0 ){ 
                        for($i = 0; $i < $errCount; $i++) {
                           $errCode = $proc->getErrorCode(intval($i));
                           $errMessage = $proc->getErrorMessage(intval($i));
                           echo 'Expected error: Code='.$errCode.' Message='.$errMessage;
                echo $result;

Also look at the file xslt30TestSuite.php

Technical Information:

Saxon/C is built by cross compiling the Java code of Saxon-HE 9.5 using the Excelsior Jet tool. This generates platform specific machine code, which we interface with C/C++ using the Java Native Interace (JNI).

The PHP interface is in the form of a C/C++ PHP extension to Saxon/C created using the Zend module API.

The XML parser used is the one supplied by the Excelsior JET runtime. There are currently no links to libxml.


The following limitations apply to the alpha release, but we expect to remove them in later releases:


Please use the help forums and bug trackers at if you need help or advice.