Saxon/C  1.2.1
Saxon Processor library for C/C++, PHP and Python
Public Member Functions | List of all members
Xslt30Processor Class Reference

#include <Xslt30Processor.h>

Public Member Functions

 Xslt30Processor ()
 Default constructor. More...
 
 Xslt30Processor (SaxonProcessor *proc, std::string cwd="")
 Constructor with the SaxonProcessor supplied. More...
 
SaxonProcessorgetSaxonProcessor ()
 Get the SaxonProcessor object. More...
 
void setcwd (const char *cwd)
 set the current working directory More...
 
void setGlobalContextItem (XdmItem *value)
 Set the source document from an XdmNode for the transformation. More...
 
void setGlobalContextFromFile (const char *filename)
 
void setInitialMatchSelection (XdmValue *selection)
 The initial value to which templates are to be applied (equivalent to the select attribute of xsl:apply-templates) More...
 
void setInitialMatchSelectionAsFile (const char *filename)
 The initial filename to which templates are to be applied (equivalent to the select attribute of xsl:apply-templates). More...
 
void setOutputFile (const char *outfile)
 
void setJustInTimeCompilation (bool jit)
 
void setResultAsRawValue (bool option)
 
void setParameter (const char *name, XdmValue *value, bool _static=false)
 
XdmValuegetParameter (const char *name)
 
bool removeParameter (const char *name)
 
void setProperty (const char *name, const char *value)
 
void setInitialTemplateParameters (std::map< std::string, XdmValue *> parameters, bool tunnel)
 
const char * getProperty (const char *name)
 
std::map< std::string, XdmValue * > & getParameters ()
 Get all parameters as a std::map. More...
 
std::map< std::string, std::string > & getProperties ()
 Get all properties as a std::map. More...
 
void clearParameters (bool deleteValues=false)
 Clear parameter values set. More...
 
void clearProperties ()
 Clear property values set.
 
XdmValue ** createXdmValueArray (int len)
 
void deleteXdmValueArray (XdmValue **arr, int len)
 
XdmValuegetXslMessages ()
 
void transformFileToFile (const char *sourcefile, const char *stylesheetfile, const char *outputfile)
 Perform a one shot transformation. More...
 
const char * transformFileToString (const char *sourcefile, const char *stylesheetfile)
 Perform a one shot transformation. More...
 
XdmValuetransformFileToValue (const char *sourcefile, const char *stylesheetfile)
 
void compileFromFile (const char *stylesheet)
 compile a stylesheet file. More...
 
void compileFromString (const char *stylesheet)
 compile a stylesheet received as a string. More...
 
void compileFromAssociatedFile (const char *sourceFile)
 Get the stylesheet associated. More...
 
void compileFromStringAndSave (const char *stylesheet, const char *filename)
 compile a stylesheet received as a string and save to an exported file (SEF). More...
 
void compileFromFileAndSave (const char *xslFilename, const char *filename)
 compile a stylesheet received as a file and save to an exported file (SEF). More...
 
void compileFromXdmNodeAndSave (XdmNode *node, const char *filename)
 compile a stylesheet received as an XdmNode. More...
 
void compileFromXdmNode (XdmNode *node)
 compile a stylesheet received as an XdmNode. More...
 
void applyTemplatesReturningFile (const char *stylesheetFilename, const char *outfile)
 Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file. More...
 
const char * applyTemplatesReturningString (const char *stylesheetFilename=NULL)
 Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as serialized string. More...
 
XdmValueapplyTemplatesReturningValue (const char *stylesheetFilename=NULL)
 Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as an XdmValue. More...
 
void callTemplateReturningFile (const char *stylesheetFilename, const char *templateName, const char *outfile)
 Invoke a transformation by calling a named template and save result to file. More...
 
const char * callTemplateReturningString (const char *stylesheetFilename, const char *templateName)
 Invoke a transformation by calling a named template and return result as a string. More...
 
XdmValuecallTemplateReturningValue (const char *stylesheetFilename, const char *templateName)
 Invoke a transformation by calling a named template and return result as a string. More...
 
void callFunctionReturningFile (const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length, const char *outfile)
 Call a public user-defined function in the stylesheet. More...
 
const char * callFunctionReturningString (const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length)
 Call a public user-defined function in the stylesheet. More...
 
XdmValuecallFunctionReturningValue (const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length)
 Call a public user-defined function in the stylesheet. More...
 
void addPackages (const char **fileNames, int length)
 File names to XsltPackages stored on filestore are added to a set of packages.
 
void clearPackages ()
 
void releaseStylesheet ()
 Internal method to release cached stylesheet. More...
 
const char * transformToString (XdmNode *source)
 Execute transformation to string. Properties supplied in advance. More...
 
XdmValuetransformToValue (XdmNode *source)
 Execute transformation to Xdm Value. Properties supplied in advance. More...
 
void transformToFile (XdmNode *source)
 Execute transformation to file. Properties supplied in advance. More...
 
bool exceptionOccurred ()
 
const char * checkException ()
 Check for exception thrown. More...
 
void exceptionClear ()
 Clear any exception thrown.
 
int exceptionCount ()
 Get number of errors reported during execution or evaluate of stylesheet. More...
 
const char * getErrorMessage (int i)
 Get the ith error message if there are any error. More...
 
const char * getErrorCode (int i)
 Get the ith error code if there are any error. More...
 

Detailed Description

An Xslt30Processor represents factory to compile, load and execute a stylesheet. It is possible to cache the context and the stylesheet in the Xslt30Processor.

Constructor & Destructor Documentation

◆ Xslt30Processor() [1/2]

Xslt30Processor::Xslt30Processor ( )

Default constructor.

Creates a Saxon-HE product

◆ Xslt30Processor() [2/2]

Xslt30Processor::Xslt30Processor ( SaxonProcessor proc,
std::string  cwd = "" 
)

Constructor with the SaxonProcessor supplied.

Parameters
proc- Supplied pointer to the SaxonProcessor object cwd - The current working directory

Member Function Documentation

◆ applyTemplatesReturningFile()

void Xslt30Processor::applyTemplatesReturningFile ( const char *  stylesheetFilename,
const char *  outfile 
)

Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file.

The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile. The result is stored in the supplied output file.

Parameters
stylesheetFile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
outputfile- The file name where results will be stored

◆ applyTemplatesReturningString()

const char * Xslt30Processor::applyTemplatesReturningString ( const char *  stylesheetFilename = NULL)

Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as serialized string.

The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile.

Parameters
stylesheetFile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile

◆ applyTemplatesReturningValue()

XdmValue * Xslt30Processor::applyTemplatesReturningValue ( const char *  stylesheetFilename = NULL)

Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as an XdmValue.

The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile.

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile

◆ callFunctionReturningFile()

void Xslt30Processor::callFunctionReturningFile ( const char *  stylesheetFilename,
const char *  functionName,
XdmValue **  arguments,
int  argument_length,
const char *  outfile 
)

Call a public user-defined function in the stylesheet.

Here we wrap the result in an XML document, and sending this document to a specified file

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
functionName- The name of the function to be called
arguments- Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These will be converted if necessary to the type as defined in the function signature, using the function conversion rules.
argument_length- the Coutn of arguments objects in the array
outputfile- The file name where results will be stored,

◆ callFunctionReturningString()

const char * Xslt30Processor::callFunctionReturningString ( const char *  stylesheetFilename,
const char *  functionName,
XdmValue **  arguments,
int  argument_length 
)

Call a public user-defined function in the stylesheet.

Here we wrap the result in an XML document, and serialized this document to string value

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
functionName- The name of the function to be called
arguments- Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These will be converted if necessary to the type as defined in the function signature, using the function conversion rules.
argument_length- the Coutn of arguments objects in the array
outputfile- The file name where results will be stored,

◆ callFunctionReturningValue()

XdmValue * Xslt30Processor::callFunctionReturningValue ( const char *  stylesheetFilename,
const char *  functionName,
XdmValue **  arguments,
int  argument_length 
)

Call a public user-defined function in the stylesheet.

Here we wrap the result in an XML document, and return the document as an XdmValue

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
functionName- The name of the function to be called
arguments- Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These will be converted if necessary to the type as defined in the function signature, using the function conversion rules.
argument_length- the Coutn of arguments objects in the array
outputfile- The file name where results will be stored,

◆ callTemplateReturningFile()

void Xslt30Processor::callTemplateReturningFile ( const char *  stylesheetFilename,
const char *  templateName,
const char *  outfile 
)

Invoke a transformation by calling a named template and save result to file.

The results of calling the template are wrapped in a document node, which is then sent to the specified file destination. If setInitialTemplateParameters(std::Map, boolean) has been called, then the parameters supplied are made available to the called template (no error occurs if parameters are supplied that are not used).

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
templateName- The name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
outputfile- The file name where results will be stored,

◆ callTemplateReturningString()

const char * Xslt30Processor::callTemplateReturningString ( const char *  stylesheetFilename,
const char *  templateName 
)

Invoke a transformation by calling a named template and return result as a string.

The results of calling the template are wrapped in a document node, which is then serialized as a string. If setInitialTemplateParameters(std::Map, boolean) has been called, then the parameters supplied are made available to the called template (no error occurs if parameters are supplied that are not used).

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
templateName- the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
outputfile- The file name where results will be stored,

◆ callTemplateReturningValue()

XdmValue * Xslt30Processor::callTemplateReturningValue ( const char *  stylesheetFilename,
const char *  templateName 
)

Invoke a transformation by calling a named template and return result as a string.

The results of calling the template are wrapped in a document node, which is then returned as an XdmValue. If setInitialTemplateParameters(std::Map, boolean) has been called, then the parameters supplied are made available to the called template (no error occurs if parameters are supplied that are not used).

Parameters
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
templateName- the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
outputfile- The file name where results will be stored,

◆ checkException()

const char * Xslt30Processor::checkException ( )

Check for exception thrown.

Returns
cha*. Returns the exception message if thrown otherwise return NULL

◆ clearParameters()

void Xslt30Processor::clearParameters ( bool  deleteValues = false)

Clear parameter values set.

Default behaviour (false) is to leave XdmValues in memory true then XdmValues are deleted

Parameters
deleteValues.Individual pointers to XdmValue objects have to be deleted in the calling program

◆ compileFromAssociatedFile()

void Xslt30Processor::compileFromAssociatedFile ( const char *  sourceFile)

Get the stylesheet associated.

The compiled stylesheet is cached and available for execution later.

Parameters
sourceFile- The file name of the XML document.

◆ compileFromFile()

void Xslt30Processor::compileFromFile ( const char *  stylesheet)

compile a stylesheet file.

The compiled stylesheet is cached and available for execution later.

Parameters
stylesheet- The file name of the stylesheet document.

◆ compileFromFileAndSave()

void Xslt30Processor::compileFromFileAndSave ( const char *  xslFilename,
const char *  filename 
)

compile a stylesheet received as a file and save to an exported file (SEF).

The compiled stylesheet is saved as SEF to file store

Parameters
xslFilename- file name of the stylesheet
filename- the file to which the compiled package should be saved

◆ compileFromString()

void Xslt30Processor::compileFromString ( const char *  stylesheet)

compile a stylesheet received as a string.

The compiled stylesheet is cached and available for execution later.

Parameters
stylesheetas a lexical string representation

◆ compileFromStringAndSave()

void Xslt30Processor::compileFromStringAndSave ( const char *  stylesheet,
const char *  filename 
)

compile a stylesheet received as a string and save to an exported file (SEF).

The compiled stylesheet is saved as SEF to file store

Parameters
stylesheetas a lexical string representation
filename- the file to which the compiled package should be saved

◆ compileFromXdmNode()

void Xslt30Processor::compileFromXdmNode ( XdmNode node)

compile a stylesheet received as an XdmNode.

The compiled stylesheet is cached and available for execution later.

Parameters
stylesheetas a lexical string representation

◆ compileFromXdmNodeAndSave()

void Xslt30Processor::compileFromXdmNodeAndSave ( XdmNode node,
const char *  filename 
)

compile a stylesheet received as an XdmNode.

The compiled stylesheet is cached and available for execution later.

Parameters
stylesheetas a lexical string representation
filename- the file to which the compiled package should be saved

◆ exceptionCount()

int Xslt30Processor::exceptionCount ( )

Get number of errors reported during execution or evaluate of stylesheet.

A transformation may have a number of errors reported against it.

Returns
int - Count of the exceptions recorded against the transformation

◆ exceptionOccurred()

bool Xslt30Processor::exceptionOccurred ( )

Checks for pending exceptions without creating a local reference to the exception object

Returns
bool - true when there is a pending exception; otherwise return false

◆ getErrorCode()

const char * Xslt30Processor::getErrorCode ( int  i)

Get the ith error code if there are any error.

A transformation may have a number of errors reported against it.

Returns
char* - The error code of the i'th exception. The error code are related to the specific specification

◆ getErrorMessage()

const char * Xslt30Processor::getErrorMessage ( int  i)

Get the ith error message if there are any error.

A transformation may have a number of errors reported against it.

Returns
char* - The message of the i'th exception

◆ getParameter()

XdmValue * Xslt30Processor::getParameter ( const char *  name)

Get a parameter value by name

Parameters
name- Specified paramater name to get
Returns
XdmValue

◆ getParameters()

std::map< std::string, XdmValue * > & Xslt30Processor::getParameters ( )

Get all parameters as a std::map.

Please note that the key name has been prefixed with 'param:', for example 'param:name'

Returns
std:map with key as string name mapped to XdmValue.

◆ getProperties()

std::map< std::string, std::string > & Xslt30Processor::getProperties ( )

Get all properties as a std::map.

Returns
std:map with key as string name mapped to string values.

◆ getProperty()

const char * Xslt30Processor::getProperty ( const char *  name)

Get a property value by name

Parameters
name- Specified paramater name to get
Returns
string - Get string of the property as char pointer array

◆ getSaxonProcessor()

SaxonProcessor* Xslt30Processor::getSaxonProcessor ( )
inline

Get the SaxonProcessor object.

Returns
SaxonProcessor - Pointer to the object

◆ getXslMessages()

XdmValue * Xslt30Processor::getXslMessages ( )

Get the messages written using the xsl:message instruction

Returns
XdmValue - Messages returned as an XdmValue.

◆ releaseStylesheet()

void Xslt30Processor::releaseStylesheet ( )

Internal method to release cached stylesheet.

Parameters
void

◆ removeParameter()

bool Xslt30Processor::removeParameter ( const char *  name)

Remove a parameter (name, value) pair from a stylesheet

Parameters
namethe name of the stylesheet parameter
Returns
bool - outcome of the romoval

◆ setcwd()

void Xslt30Processor::setcwd ( const char *  cwd)

set the current working directory

Parameters
cwd- Current working directory

◆ setGlobalContextFromFile()

void Xslt30Processor::setGlobalContextFromFile ( const char *  filename)

Set the source from file for the transformation.

◆ setGlobalContextItem()

void Xslt30Processor::setGlobalContextItem ( XdmItem value)

Set the source document from an XdmNode for the transformation.

Parameters
value- The source to the stylesheet as a pointer to the XdmNode object.

◆ setInitialMatchSelection()

void Xslt30Processor::setInitialMatchSelection ( XdmValue selection)

The initial value to which templates are to be applied (equivalent to the select attribute of xsl:apply-templates)

Parameters
selection- The value to which the templates are to be applied

◆ setInitialMatchSelectionAsFile()

void Xslt30Processor::setInitialMatchSelectionAsFile ( const char *  filename)

The initial filename to which templates are to be applied (equivalent to the select attribute of xsl:apply-templates).

The file is parsed internall

Parameters
filename- The file name to which the templates are to be applied

◆ setInitialTemplateParameters()

void Xslt30Processor::setInitialTemplateParameters ( std::map< std::string, XdmValue *>  parameters,
bool  tunnel 
)

Set parameters to be passed to the initial template. These are used whether the transformation is invoked by applying templates to an initial source item, or by invoking a named template. The parameters in question are the xsl:param elements appearing as children of the xsl:template element.

The parameters are supplied in the form of a map; the key is a QName given as a string which must match the name of the parameter; the associated value is an XdmValue containing the value to be used for the parameter. If the initial template defines any required parameters, the map must include a corresponding value. If the initial template defines any parameters that are not present in the map, the default value is used. If the map contains any parameters that are not defined in the initial template, these values are silently ignored.

The supplied values are converted to the required type using the function conversion rules. If conversion is not possible, a run-time error occurs (not now, but later, when the transformation is actually run).

The XsltTransformer retains a reference to the supplied map, so parameters can be added or changed until the point where the transformation is run.

The XSLT 3.0 specification makes provision for supplying parameters to the initial template, as well as global stylesheet parameters. Although there is no similar provision in the XSLT 1.0 or 2.0 specifications, this method works for all stylesheets, regardless whether XSLT 3.0 is enabled or not.

Parameters
parametersthe parameters to be used for the initial template
tunneltrue if these values are to be used for setting tunnel parameters; false if they are to be used for non-tunnel parameters

◆ setJustInTimeCompilation()

void Xslt30Processor::setJustInTimeCompilation ( bool  jit)

Say whether just-in-time compilation of template rules should be used.

Parameters
jittrue if just-in-time compilation is to be enabled. With this option enabled, static analysis of a template rule is deferred until the first time that the template is matched. This can improve performance when many template rules are rarely used during the course of a particular transformation; however, it means that static errors in the stylesheet will not necessarily cause the compile(Source) method to throw an exception (errors in code that is actually executed will still be notified to the registered ErrorListener or ErrorList, but this may happen after the compile(Source) method returns). This option is enabled by default in Saxon-EE, and is not available in Saxon-HE or Saxon-PE.

Recommendation: disable this option unless you are confident that the stylesheet you are compiling is error-free.

◆ setOutputFile()

void Xslt30Processor::setOutputFile ( const char *  outfile)

Set the output file of where the transformation result is sent

◆ setParameter()

void Xslt30Processor::setParameter ( const char *  name,
XdmValue value,
bool  _static = false 
)

Set the value of a stylesheet parameter

Parameters
namethe name of the stylesheet parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
valuethe value of the stylesheet parameter, or null to clear a previously set value
_staticFor static (compile-time) parameters we set this flag to true, which means the parameter is must be set on the XsltCompiler object, prior to stylesheet compilation. The default is false. Non-static parameters may also be provided.

◆ setProperty()

void Xslt30Processor::setProperty ( const char *  name,
const char *  value 
)

Set a property specific to the processor in use. XsltProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml") 'o':outfile name, 'it': initial template, 'im': initial mode, 's': source as file name 'm': switch on message listener for xsl:message instructions (TODO: this feature should be event based), 'item'| 'node' : source supplied as an XdmNode object

Parameters
nameof the property
valueof the property

◆ setResultAsRawValue()

void Xslt30Processor::setResultAsRawValue ( bool  option)

Set true if the return type of callTemplate, applyTemplates and transform methods is to return XdmValue, otherwise return XdmNode object with root Document node

Parameters
optiontrue if return raw result, i.e. XdmValue, otherwise return XdmNode

◆ transformFileToFile()

void Xslt30Processor::transformFileToFile ( const char *  sourcefile,
const char *  stylesheetfile,
const char *  outputfile 
)

Perform a one shot transformation.

The result is stored in the supplied outputfile.

Parameters
sourcefile- The file name of the source document
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
outputfile- The file name where results will be stored

◆ transformFileToString()

const char * Xslt30Processor::transformFileToString ( const char *  sourcefile,
const char *  stylesheetfile 
)

Perform a one shot transformation.

The result is returned as a string

Parameters
sourcefile- The file name of the source document
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
Returns
char array - result of the transformation

◆ transformFileToValue()

XdmValue * Xslt30Processor::transformFileToValue ( const char *  sourcefile,
const char *  stylesheetfile 
)

Perform a one shot transformation. The result is returned as an XdmValue

Parameters
sourcefile- The file name of the source document
stylesheetfile- The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
Returns
XdmValue - result of the transformation

◆ transformToFile()

void Xslt30Processor::transformToFile ( XdmNode source)

Execute transformation to file. Properties supplied in advance.

Perform the transformation based upon cached stylesheet and source document. Assume the outputfile has been set in advance

Parameters
source- source document suppplied as an XdmNode object
Returns
as an XdmValue.

◆ transformToString()

const char * Xslt30Processor::transformToString ( XdmNode source)

Execute transformation to string. Properties supplied in advance.

Perform the transformation based upon what has been cached.

Parameters
source- source document suppplied as an XdmNode object
Returns
char*. Pointer to Array of chars. Result returned as a string.

◆ transformToValue()

XdmValue * Xslt30Processor::transformToValue ( XdmNode source)

Execute transformation to Xdm Value. Properties supplied in advance.

Perform the transformation based upon cached stylesheet and any source document.

Parameters
source- source document suppplied as an XdmNode object
Returns
as an XdmValue.

The documentation for this class was generated from the following files: