Saxon/C  1.1.2
Saxon Processor library for C/C++/PHP
Saxon/C Documentation

Back to web page

Table of Contents

  1. Installation
  2. Getting started with C/C++
  3. PHP API & Examples
  4. Technical
  5. Limitations

Saxon/C 1.1.2 is the latest release of Saxon-HE/PE/EE on the C/C++ programming platform. The APIs support the specifications XSLT 3.0, XQuery 3.0, Schema Validation 1.0/1.1 and XPath 2.0/3.0 from C/C++ or PHP applications.

Saxon/C is built from the Saxon 9.8.0.15 Java product using the Excelsior JET tool (version 15.3).

Platforms supported: Linux 32/64-bit, Mac OS and Windows 64-bit.

Saxon/C is release in three separate editions which replicating the products on the Java platform: Enterprise (Saxon-EE/C), Professional Editon (Saxon-PE/C), and Home Edition (Saxon-HE/C)

Installation:

Linux: Saxon-HE/C, Saxon-PE/C and Saxon-EE/C:

To install any of the Saxon/C releases, unzip the file libsaxon-EDITION-setup-v#.#.#.zip and execute the command './libsaxon-EDITION-setup-v#.#.#' First step is to select the destination of where the product files will be installed. The product files are unpacked in the directory 'Saxon-EDITIONC'
Link the dynamic saxon library so it can be found. For example:
ln -s /usr/lib/Saxonica/Saxon-EDITIONC#.#.#/libsaxonEDITION.so /usr/lib/libsaxonEDITION.so
You need to setup the environment for the jet jvm. The jvm is in the directory JET-home=Saxonica/Saxon-EDITION1.1.0/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.
Link the jetvm library so it can be found. For example:
ln -s /usr/lib/Saxonica/Saxon-EDITIONC#.#.#/rt /usr/lib/rt
The Saxon-EDITION API assumes the library is installed as follows: '/usr/lib/libsaxonhec.so', '/usr/lib/libsaxonpec.so' or '/usr/lib/libsaxoneec.so'

Mac OS: Saxon-HE/C, Saxon-PE/C and Saxon-EE/C:

To install any of the Saxon/C releases on the Mac OS system, unzip the self-contained file libsaxon-EDITION-mac-setup-v#.#.#.zip
The first step is to copy the library libsaxonEDITION.dylib and the rt directories to a your install location. The C/C++ interface by default assumes the library files and directories are installed in the directory '/usr/local/lib'. The location of the Saxon/C library can be set using the SAXONC_HOME environment variable.
The DYLD_LIBRARY_PATH environment variable must be set as follows:
export JET_HOME=/usr/local/lib/rt
export DYLD_LIBRARY_PATH=$JET_HOME/lib/lib/jetvm:$DYLD_LIBRARY_PATH

PHP extension:

A built php extension module is included in the Saxon/C distrubtion, see the directory 'php-library-module'. See the file saxon.so (Available for Linux and Mac OS). This was built using the php 7.2 version. For PHP5 please copy files in the PHP5-Build directory into the Saxon.C.API directory.
To build the php extension follow the steps below:
Run the commands:
  • phpize
  • ./configure –enable-saxon
  • make
  • sudo make install
Create a module conf file:
nano /etc/php5/mods-available/saxon.ini and add contents:
; configuration for php Saxon HE/PE/EE module
    extension=saxon.so
save the file.
Enable the module for PHP:
php5enmod saxon
Similar for PHP7
Alternatively, you can 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: extension=saxon.so
  • sudo service apache2 restart
Check that the extension has installed properly:
  • php -d"extension=saxon.so" -m
  • Also Create a php page and call the function 'phpinfo()'. Look for the Saxon/C entry.

Getting started with C/C++:

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.

C/C++

c:

For c programming see the test harnesses for XSLT, XQuery, Schema Validation and XPath in C code along with the build and run script in the directory 'cTests'.
The following files are required to build Saxon/C on C++: SaxonCGlue.c, SaxonXProcessor.c, SaxonCXPath.c
To compile the sample test code in C execute the 'build.sh' file the directory 'cTests'. This file builds executables for the test cases testing XSLT, XPath, XQuery and schema Validator. The command is similar to the following:

gcc -m32 -I$jdkdir/include -I$jdkdir/include/linux -I /System/Library/Frameworks/JavaVM.framework/Headers ../SaxonCGlue.c ../SaxonCProcessor.c ../SaxonCXPath.c testXSLT.c -o testXSLT -ldl -lc $1

Saxon/C can be run from the commandline in a similar way to its Java counterpart (same options are available). See the file Transform.c, Query.c and Validate.c (which is available in Saxon-EE/C) in the directory 'command'. The build.sh script can be executed to build the commandline programs.

C++:

For C++ programming see sample code for XSLT, XQuery, Schema Validation and XPath in C++ code along with the build and run script in the directory 'cppTests'.
The following files are required to build Saxon/C on C++: SaxonCGlue.c, SaxonCXPath.c, XdmValue.cpp, XdmItem.cpp, XdmNode.cpp, XdmAtomicValue.cpp, SaxonProcessor.cpp, XsltProcessor.cpp and XQueryProcessor.cpp, XPathProcessor.cpp, SchemaValidator.cpp
To compile the sample test code in C++ execute the 'build.sh' file the directory 'cppTests'. This file builds executables for the test cases testing XSLT, XPath, XQuery and schema Validator. The command is similar to the following:

g++ -m32 ../bin/SaxonCGlue.o ../bin/SaxonCXPath.o ../bin/SaxonProcessor.o ../bin/XQueryProcessor.o ../bin/XsltProcessor.o ../bin/XPathProcessor.o ../bin/XdmValue.o ../bin/XdmItem.o ../bin/XdmNode.o ../bin/XdmAtomicValue.o ../bin/SchemaValidator.o testXSLT.cpp -o testXSLT -ldl -lc $1 $2

Configuration of Processors - (setParameter & setProperty methods)

There are many parameters and options that can be set to control the way in which Saxon behaves. At a global level when the SaxonProcessor is created, the configuration features can be set with the method 'setConfigurationProperty(const char * name, const char * value)'. For a comprehensive guide on the configuration see the Saxon 9.6 documentation. There are some feature that don't work or are under tested. For eample, 'bytecode generation' we know does not work.
The example below shows how we can set the configuration features on the processor before we create any of the processors (.e.g. XsltProcessor, XQueryProcess, etc):

processor->setConfigurationProperty("xsdversion", "1.1");

or

processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");

The processors for XSLT, XQuery, XPath and Schema Validator can be configured using the methods setParameter and setProperty. Depending on the specific processor the exact purpose of these methods may differs. In the following sections we will go through the options available.
We now give a quick guide for running Saxon/C in C++

XSLT

setParameter(string $name, XdmValue $value) Method

Name Example Comme
'node'=xdmValue setParameter("node",xdmNodeObj) Sets the source document for transformation. We also accept the parameter names 'item'.
param=xdmValue setParameter("numParam",value1) set the value of a stylesheet parameter

setProperty(string $name, string $propValue) Method

The properties are a subset to those specified for running XSLT from the command line.
Name Example Comme
![serialization name]=value setProperty("!INDENT","yes") Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation
'o'=filename setProperty("o", "output.xml") Sets the destination for the result of the transformation to the specificed filename
'it'=name setProperty("it", "name") Set the initial named template for the transformation by name
'dtd'=boolean setProperty("dtd", "true") Set whether DTD validation should be applied to documents loaded
'im'=name setProperty("im", "mode-name") Set the initial mode for the transformation
's'=filename setProperty("s", "filename") Identifies the source file or directory. Mandatory unless the -it option is used.
'resources'=directory setProperty("resources", "dir") Specifies the directory where the resources file are found
'extc'=dir/saxonc setProperty("extc", "dir/saxonc") Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests
'm' setProperty("m", "") The presence of this property creates a message listener which is available in the C/C++ API of Saxon/C
Example 1:

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

    SaxonProcessor * processor = new SaxonProcessor(false);
    XsltProcessor * xslt = processor->newTransformer();
        xslt->setSourceFile("xml/foo.xml");
    XdmAtomicValue * xdmvaluex =processor->makeStringValue("Hello to you");
    if(xdmvaluex !=NULL){
        cerr<< "xdmvaluex ok"<<endl;            
    }
    xslt->setParameter("a-param", xdmvaluex);
        const char * result = test->transformFileToString(NULL, "xsl/foo.xsl");
    if(result != NULL) {
        cerr<<result<<endl;
    } else {
        cerr<<"Result is NULL"<<endl;
    }
    processor->clearParameters(true);
    processor->clearProperties();

XQuery

setParameter(string $name, XdmValue $value) Method

Name Example Comme
'node'=xdmValue setParameter("node",xdmNodeObj) Sets the source document for query. We also accept the parameter names 'item'.
param=xdmValue setParameter("numParam",value1) Set the value of external variable defined in the query

setProperty(string $name, string $propValue) Method

The properties are a subset to those specified for running XQuery from the command line.
Name Example Comme
'base'=base-URI setProperty("base", "/home/username/example")
'q'=query-fileName setProperty("q", "filename") Identifies the file containing the query.
'qs'=query-string setProperty("qs", "saxon:line-number((//person)[1])") Allows the query to be specified inline.
![serialization name]=value setProperty("!INDENT","yes") Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation
'o'=filename setProperty("o", "output.xml") Sets the destination for the result of the XQuery to the specificed filename
'dtd'=boolean setProperty("dtd", "true") Set whether DTD validation should be applied to documents loaded
's'=filename setProperty("s", "filename") Identifies the source file or directory. Mandatory unless the -it option is used.
'resources'=directory setProperty("resources", "dir") Specifies the directory where the resources file are found
'sa'=boolean setProperty("sa", "true") Invoke a schema-aware query. Requires Saxon-EE to be installed.
'extc'=dir/saxonc setProperty("extc", "dir/saxonc") Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests
Example:

    SaxonProcessor *processor = new SaxonProcessor(true);
    XsltProcessor * xslt = processor->newXQueryProcessor();
     queryProc->setProperty("s", "cat.xml");
        queryProc->setProperty("q", "family.xq");
        queryProc->runQueryToString();

XPath

setParameter(string $name, XdmValue $value) Method

Name Example Comme
'node'=xdmValue setParameter("node",xdmNodeObj) Sets the source document for query. We also accept the parameter names 'item'.
param=xdmValue setParameter("numParam",value1) Set the value of external variable defined in the query

setProperty(string $name, string $propValue) Method

Name Example Comme
![serialization name]=value setProperty("!INDENT","yes") Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation
'o'=filename setProperty("o", "output.xml") Sets the destination for the result of the XQuery to the specificed filename
'dtd'=boolean setProperty("dtd", "true") Set whether DTD validation should be applied to documents loaded
's'=filename setProperty("s", "filename") Identifies the source file or directory. Mandatory unless the -it option is used.
'resources'=directory setProperty("resources", "dir") Specifies the directory where the resources file are found
'extc'=dir/saxonc setProperty("extc", "dir/saxonc") Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests
Example:

    SaxonProcessor *processor = new SaxonProcessor();
    XPathProcessor * xpath = processor->newXPathProcessor();
    xpath->setContextFile("cat.xml");
    XdmValue * resultValues = xpath->evaluate("//person");
    if(resultValues == NULL) {
         printf("result is null \n");
    } else {
        cout<<"Number of items="<<resultValues->size()<<endl;
        for(int i =0; i< resultValues->size();i++){
            XdmItem * itemi = resultValues->itemAt(i);
            if(itemi == NULL) {
                cout<<"Item at position "<<i<<" should not be null"<<endl;
                break;
            }
            cout<<"Item at "<<i<<" ="<<itemi->getStringValue(processor)<<endl;      
        }
    }
    xpath->clearParameters(true);
    xpath->clearProperties();

XML Schema Validation

Name Example Comme
'node'=xdmValue setParameter("node",xdmNodeObj) Sets the source document for the validation. We also accept the parameter names 'item'.
param=xdmValue setParameter("numParam",value1) Set the value of external variable defined in the query

setProperty(string $name, string $propValue) Method

The properties are a subset to those specified for running the Schema Validator from the command line.
Name Example Comme
![serialization name]=value setProperty("!INDENT","yes") Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation
'o'=filename setProperty("o", "output.xml") Sets the destination for the result of the XQuery to the specificed filename
'string'=xml-string setProperty("string",xml-string) Sets the source document aas a string for validation. Parsing will happen when the validate method has been called.
'dtd'=boolean setProperty("dtd", "true") Set whether DTD validation should be applied to documents loaded
's'=filename setProperty("s", "filename") Identifies the source file or directory. Mandatory unless the -it option is used.
'resources'=directory setProperty("resources", "dir") Specifies the directory where the resources file are found
'report-node'=boolean setProperty("report-node", "true") Flag for validation reporting feature. Error validation failures are represented in an XML document
'report-file'=filename setProperty("report-file", "filename") Switches on the validation reporting feature. Validation failures collected and saved in an XML format in a file.
'verbose'=boolean setProperty("verbose", "true") Set verbose mode to output to the terminal validation exceptions. The default is on providing the reporting feature has not been enabled.
'element-type'=string setProperty("element-type", "{uri}local") Set the name of the required type of the top-level element of the document to be validated. The string should be in the Clark notation: {uri}local
'element-name'=string setProperty("element-name", "{uri}local") Set the name of the required top-level element of the document to be validated (that is, the name of the outermost element of the document). The string should be in the Clark notation: {uri}local
'lax'=boolean setProperty("lax", "true") The validation mode may be either strict or lax. Default is strict. This property indicates that lax validation is required.
Example:

    SaxonProcessor * processor = new SaxonProcessor(true);
    processor->setConfigurationProperty("xsdversion", "1.1");
    processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
    SchemaValidator * val = processor->newSchemaValidator();
    val->registerSchemaFromFile("family-ext.xsd");
    val->registerSchemaFromFile("family.xsd");
    val->setProperty("report-node", "true");    
    val->setProperty("verbose", "true");
    val->validate("family.xml");
    XdmNode * node = val->getValidationReport(); 
    if(node != NULL) {
        cout<<endl<<"Validation Report"<<node->getStringValue()<<endl;
    } else {
        cout<<endl<<"Error: Validation Report is NULL"<<endl;
    }

PHP

PHP API

The PHP API is split up in the following class (links are to the C++ classes): SaxonProcessor, XsltProcessor, XPathProcessor, XQueryProcessor and SchemaValidator. We also have class for a sub-set of the XDM data model: XdmValue, XdmNode, XdmItem and XdmAtomicValue.
The methods on these class are given below. For a more comprehensive description of the methods and their argument please see its counterpart in the C++ API.

Saxon\SaxonProcessor class

PHP API
SaxonProcessor()
Default Constructor. Create an unlicensed Saxon Processor
SaxonProcessor(boolean $license)
Constructor. Indicates whether the Processor requires features of Saxon that need a license file. If false, the method will creates a Configuration appropriate for Saxon HE (Home edition). If true, the method will create a Configuration appropriate to the version of the software that is running Saxon-PE or Saxon-EE
SaxonProcessor(boolean $license, string $cwd)
Constructor. Indicates whether the Processor requires features of Saxon that need a license file. The cwd arugment is used to manually set the current working directory used for executions of source files
XdmValue createAtomicValue($primitive_type val)
Create an Xdm Atomic value from any of the main primitive types (i.e. bool, int, float, double, string)
Saxon\XdmNode parseXmlFromString(string $value)
Create an XdmNode object. The $value is a lexical representation of the XML document
Saxon\XdmNode parseXmlFromFile(string $fileName)
Create an XdmNode object. Value is a string type and the file name to the XML document. File name can be relative or absolute. IF relative the cwd is used to resolve the file.
void setcwd(string $cwd)
Set the current working directory used to resolve against files
Saxon\XdmNode parseXmlFromFile(string $fileName)
Create an XdmNode object. Value is a string type and the file name to the XML document. File name can be relative or absolute. IF relative the cwd is used to resolve the file.
void setResourceDirectory(string $dir)
Set the resources directory of where Saxon can locate data folder
void setConfigurationProperty(string $name, string $value)
Set a configuration property specific to the processor in use. Properties specified here are common across all the processors. See Configuration Features
Saxon\XsltProcessor newXsltProcessor()
Create an XsltProcessor in the PHP environment. An XsltProcessor is used to compile and execute XSLT sytlesheets
Saxon\XQueryProcessor newXQueryProcessor()
Create an XQueryProcessor in the PHP environment. An XQueryProcessor is used to compile and execute XQuery queries
Saxon\XPathProcesssor newXPathProcessor()
Create an XPathProcessor in the PHP environment. An XPathProcessor is used to compile and execute XPath expressions
Saxon\SchemaValidator newSchemaValidator()
Create a SchemaValidator in the PHP environment. A SchemaValidator provides capabilities to load and cache XML schema definitions. You can also valdiate source documents with egistered XML schema definitions
string version()
Report the Java Saxon version
void registerPHPFunctions(string $library)
Enables the ability to use PHP functions as XSLT functions. Accepts as parameter the full path of the Saxon/C PHP Extension library. This is needed to do the callbacks

Saxon\XsltProcessor class

PHP API
void transformFileToFile(string $sourceFileName, string $stylesheetFileName, string outputfileName)
Perform a one shot transformation. The result is stored in the supplied outputfile name.
string transformFileToString(string $sourceFileName, string $stylesheetFileName)
Perform a one shot transformation. The result is returned as a string. If there are failures then a null is returned
XdmValue transformFileToValue(string $fileName)
Perform a one shot transformation. The result is returned as an XdmValue
void transformToFile()
Perform the transformation based upon cached stylesheet and source document.
string transformToString()
XdmValue transformToValue()
Perform the transformation based upon cached stylesheet and any source document. Result returned as an XdmValue object. If there are failures then a null is returned
void compileFromFile(string $fileName)
Compile a stylesheet suplied as by file name
void compileFromString(string $str)
Compile a stylesheet received as a string.
void compileFromFileAndSave(string $xslFileName, string $sefFileName)
compile a stylesheet received as a file and save to an exported file (SEF). (Saxon-EE/C required).
void compileFromStringAndSave(string $str, string $sefFileName)
compile a stylesheet received as a string and save to an exported file (SEF). (Saxon-EE/C required).
void compileFromValue(XdmNode $node)
Compile a stylesheet received as an XdmNode.
void setOutputFile(string $fileName)
Set the output file name of where the transformation result is sent
void setSourceFromXdmValue(XdmValue $value)
The source used for a query or stylesheet. Requires an XdmValue object
void setSourceFromFile(string $filename)
The source used for query or stylesheet. Requires a file name as string
void setParameter(string $name, XdmValue $value)
Set the parameters required for XSLT stylesheet
void setProperty(string $name, string $value)
Set properties for the stylesheet.
void clearParameters()
Clear parameter values set
void clearProperties()
Clear property values set
void exceptionClear()
Clear any exception thrown
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

Saxon\XQueryProcessor class

PHP API
XdmValue runQueryToValue()
compile and evaluate the query. Result returned as an XdmValue object. If there are failures then a null is returned
string runQueryToString()
compile and evaluate the query. Result returned as string. If there are failures then a null is returned
void runQueryToFile(string $outfilename)
compile and evaluate the query. Save the result to file
void setQueryContent(string $str)
query supplied as a string
void setQueryItem(XdmItem $item)
**
void setQueryFile($string $filename)
query supplied as a file
void setContextItemFromFile(string $fileName)
Set the initial context item for the query. Supplied as filename
void setContextItem(Xdm $obj)
Set the initial context item for the query. Any one of the objects are accepted: XdmValue, XdmItem, XdmNode and XdmAtomicValue.
void setQueryBaseURI(string $uri)
Set the static base URI for a query expressions compiled using this XQuery Processor. The base URI is part of the static context, and is used to resolve any relative URIS appearing within a query
void declareNamespace(string $prefix, string $namespace)
Declare a namespace binding as part of the static context for XPath expressions compiled using this XQuery processor
void setParameter(string $name, XdmValue $value)
Set the parameters required for XQuery Processor
void setProperty(string $name, string $value)
Set properties for Query.
void clearParameters()
Clear parameter values set
void clearProperties()
Clear property values set
void exceptionClear()
Clear any exception thrown
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 query

Saxon\XPathProcessor class

PHP API
void setContextItem(string $fileName)
Set the context item from a XdmItem
void setContextFile(string $fileName)
Set the context item from file
boolean effectiveBooleanValue(string $xpathStr)
Evaluate the XPath expression, returning the effective boolean value of the result.
XdmValue evaluate(string $xpathStr)
Compile and evaluate an XPath expression, supplied as a character string. Result is an XdmValue
XdmItem evaluateSingle(string $xpathStr)
Compile and evaluate an XPath expression whose result is expected to be a single item, with a given context item. The expression is supplied as a character string.
void declareNamespace(string $prefix, string $namespace)
Declare a namespace binding as part of the static context for XPath expressions compiled using this XPathProcessor
void setBaseURI(string $uri)
Set the static base URI for XPath expressions compiled using this XQuery Processor. The base URI is part of the static context, and is used to resolve any relative URIS appearing within a query
void setParameter(string $name, XdmValue $value)
Set the parameters required for XQuery Processor
void setProperty(string $name, string $value)
Set properties for Query.
void clearParameters()
Clear parameter values set
void clearProperties()
Clear property values set
void exceptionClear()
Clear any exception thrown
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

Saxon\SchemaValidator class

PHP API
void setSourceNode(XdmNode $node)
The instance document to be validated. Supplied as an Xdm Node
void setOutputFile(string $fileName)
The instance document to be validated. Supplied file name is resolved and accessed
void registerSchemaFromFile(string $fileName)
Register the Schema which is given as file name.
void registerSchemaFromString(string $schemaStr)
Register the Schema which is given as a string representation.
void validate()
Validate an instance document supplied as a Source object. Assume source document has already been supplied through accessor methods
void validate(string $fileName)
Validate an instance document supplied as a Source object. $filename - The name of the file to be validated. $filename can be null
XdmNode validateToNode()
Validate an instance document supplied as a Source object with the validated document returned to the calling program. Assume source document has already been supplied through accessor methods
XdmNode validateToNode(string $fileName)
Validate an instance document supplied as a Source object with the validated document returned to the calling program. $filename - The name of the file to be validated. $filename can be null
XdmNode getValidationReport
Get the valdiation report produced after valdiating the soucre document. The reporting feature is switched on via setting the property on the SchemaValidator: validator.setProperty('report', 'true'). Return XdmNode
void setParameter(string $name, XdmValue $value)
Set the parameters required for XQuery Processor
void setProperty(string $name, string $value)
Set properties for Schema Validator.
void clearParameters()
Clear parameter values set
void clearProperties()
Clear property values set
void exceptionClear()
Clear any exception thrown
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 of the validator

Saxon\XdmValue class

PHP API
XdmItem getHead()
Get the first item in the sequence
XdmItem itemAt(int $index)
Get the n'th item in the value, counting from zero
int size()
Get the number of items in the sequence
addXdmItem(XdmItem $item)
Add item to the sequence at the end.

Saxon\XdmItem class

PHP API
string getStringValue()
Get the string value of the item. For a node, this gets the string value of the node. For an atomic value, it has the same effect as casting the value to a string. In all cases the result is the same as applying the XPath string() function.
boolean isNode()
Determine whether the item is a node value or not.
boolean isAtomic()
Determine whether the item is an atomic value or not.
XdmAtomicValue getAtomicValue()
Provided the item is an atomic value we return the XdmAtomicValue otherwise return null
XdmNode getNodeValue()
Provided the item is a node value we return the XdmNode otherwise return null

Saxon\XdmNode class

PHP API
string getStringValue()
Get the string value of the item. For a node, this gets the string value of the node.
int getNodeKind()
Get the kind of node
string getNodeName
et the name of the node, as a EQName
boolean isAtomic()
Determine whether the item is an atomic value or a node. This method will return FALSE as the item is not atomic
int getChildCount()
Get the count of child node at this current node
int getAttributeCount()
Get the count of attribute nodes at this node
XdmNode getChildNode(int index)
Get the n'th child node at this node. If the child node selected does not exist then return null
XdmNode getParent()
Get the parent of this node. If parent node does not exist then return null
XdmNode getAttributeNode(int $index)
Get the n'th attribute node at this node. If the attribute node selected does not exist then return null
string getAttributeValue(int $index)
Get the n'th attribute node value at this node. If the attribute node selected does not exist then return null

Saxon\XdmAtomicValue class

PHP API
string getStringValue
Get the string value of the item. For an atomic value, it has the same effect as casting the value to a string. In all cases the result is the same as applying the XPath string() function.
boolean getBooleanValue
Get the value converted to a boolean using the XPath casting rules
double getDoubleValue
Get the value converted to a double using the XPath casting rules. If the value is a string, the XSD 1.1 rules are used, which means that the string "+INF" is recognised
long getLongValue
Get the value converted to an integer using the XPath casting rules
boolean isAtomic
Determine whether the item is an atomic value or a node. Return TRUE if the item is an atomic value

PHP unit tests

In the Saxon/C download please see the PHP unit tests for XSLT, XQuery, XPath and Schema Validator. The PHP test files are contained in the 'samples/php' folder along with associated files. Namely: xsltExamples.php, xqueryExamples.php, xpathExamples.php, validatorExamples.php. These files contain many useful examples which will get you started.
Example code XSLT processing:

    <?php 
            $xmlfile = "xml/foo.xml";
            $xslFile = "xsl/foo.xsl";
        $proc = new Saxon\SaxonProcessor();
                $version = $proc->version();
                echo 'Saxon Processor version: '.$version;
        $xsltProc = $saxonProc->newXsltProcessor();
                $xsltProc->setSourceFromFile($xmlfile);
                $xsltProc->compileFromFile($xslFile);      
                $result = $xsltProc->transformToString();               
        if($result != null) {               
          echo 'exampleSimple1:
'; echo 'Output:'.$result; } else { echo "Result is null"; } $xsltProc->clearParameters(); $xsltProc->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:

    <?php 
            $xmlfile = "xml/foo.xml";
            $xslFile = "xsl/foo.xsl";
        $proc = new Saxon\SaxonProcessor();
        $xsltProc = $saxonProc->newXsltProcessor();
                $xsltProc->setSourceFromFile($xmlFile);
                $xsltProc->compileFromFile($xslFile);
                $result = $xsltProc->transformToString();
                if($result == NULL) {
                    $errCount = $xsltProc->getExceptionCount();
                    if($errCount > 0 ){ 
                        for($i = 0; $i < $errCount; $i++) {
                           $errCode = $xsltProc->getErrorCode(intval($i));
                           $errMessage = $xsltProc->getErrorMessage(intval($i));
                           echo 'Expected error: Code='.$errCode.' Message='.$errMessage;
                       }
                        $xsltProc->exceptionClear();    
                    }
                }                
                echo $result;
                $xsltProc->clearParameters();
        $xsltProc->clearProperties();
    ?>

Technical Information:

Saxon/C is built by cross compiling the Java code of Saxon 9.8 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.

Limitations:

The following limitations apply to the 1.1.2 release:
  • No support for the XdmFunction type in the Xdm data model

Feedback/Comments:

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