Saxon/C
1.2.1
Saxon Processor library for C/C++, PHP and Python
|
#include <Xslt30Processor.h>
Public Member Functions | |
Xslt30Processor () | |
Default constructor. More... | |
Xslt30Processor (SaxonProcessor *proc, std::string cwd="") | |
Constructor with the SaxonProcessor supplied. More... | |
SaxonProcessor * | getSaxonProcessor () |
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) |
XdmValue * | getParameter (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) |
XdmValue * | getXslMessages () |
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... | |
XdmValue * | transformFileToValue (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... | |
XdmValue * | applyTemplatesReturningValue (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... | |
XdmValue * | callTemplateReturningValue (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... | |
XdmValue * | callFunctionReturningValue (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... | |
XdmValue * | transformToValue (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... | |
An Xslt30Processor
represents factory to compile, load and execute a stylesheet. It is possible to cache the context and the stylesheet in the Xslt30Processor
.
Xslt30Processor::Xslt30Processor | ( | ) |
Default constructor.
Creates a Saxon-HE product
Xslt30Processor::Xslt30Processor | ( | SaxonProcessor * | proc, |
std::string | cwd = "" |
||
) |
Constructor with the SaxonProcessor supplied.
proc | - Supplied pointer to the SaxonProcessor object cwd - The current working directory |
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.
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 |
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.
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 |
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.
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 |
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
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, |
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
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, |
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
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, |
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).
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, |
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).
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, |
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).
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, |
const char * Xslt30Processor::checkException | ( | ) |
Check for exception thrown.
void Xslt30Processor::clearParameters | ( | bool | deleteValues = false | ) |
Clear parameter values set.
Default behaviour (false) is to leave XdmValues in memory true then XdmValues are deleted
deleteValues. | Individual pointers to XdmValue objects have to be deleted in the calling program |
void Xslt30Processor::compileFromAssociatedFile | ( | const char * | sourceFile | ) |
Get the stylesheet associated.
The compiled stylesheet is cached and available for execution later.
sourceFile | - The file name of the XML document. |
void Xslt30Processor::compileFromFile | ( | const char * | stylesheet | ) |
compile a stylesheet file.
The compiled stylesheet is cached and available for execution later.
stylesheet | - The file name of the stylesheet document. |
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
xslFilename | - file name of the stylesheet |
filename | - the file to which the compiled package should be saved |
void Xslt30Processor::compileFromString | ( | const char * | stylesheet | ) |
compile a stylesheet received as a string.
The compiled stylesheet is cached and available for execution later.
stylesheet | as a lexical string representation |
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
stylesheet | as a lexical string representation |
filename | - the file to which the compiled package should be saved |
void Xslt30Processor::compileFromXdmNode | ( | XdmNode * | node | ) |
compile a stylesheet received as an XdmNode.
The compiled stylesheet is cached and available for execution later.
stylesheet | as a lexical string representation |
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.
stylesheet | as a lexical string representation |
filename | - the file to which the compiled package should be saved |
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.
bool Xslt30Processor::exceptionOccurred | ( | ) |
Checks for pending exceptions without creating a local reference to the exception object
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.
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.
XdmValue * Xslt30Processor::getParameter | ( | const char * | name | ) |
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'
std::map< std::string, std::string > & Xslt30Processor::getProperties | ( | ) |
Get all properties as a std::map.
const char * Xslt30Processor::getProperty | ( | const char * | name | ) |
Get a property value by name
name | - Specified paramater name to get |
|
inline |
Get the SaxonProcessor object.
XdmValue * Xslt30Processor::getXslMessages | ( | ) |
void Xslt30Processor::releaseStylesheet | ( | ) |
Internal method to release cached stylesheet.
void |
bool Xslt30Processor::removeParameter | ( | const char * | name | ) |
Remove a parameter (name, value) pair from a stylesheet
name | the name of the stylesheet parameter |
void Xslt30Processor::setcwd | ( | const char * | cwd | ) |
set the current working directory
cwd | - Current working directory |
void Xslt30Processor::setGlobalContextFromFile | ( | const char * | filename | ) |
Set the source from file for the transformation.
void Xslt30Processor::setGlobalContextItem | ( | XdmItem * | value | ) |
void Xslt30Processor::setInitialMatchSelection | ( | XdmValue * | selection | ) |
The initial value to which templates are to be applied (equivalent to the select
attribute of xsl:apply-templates
)
selection | - The value to which the templates are to be applied |
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
filename | - The file name to which the templates are to be applied |
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 | the parameters to be used for the initial template |
tunnel | true if these values are to be used for setting tunnel parameters; false if they are to be used for non-tunnel parameters |
void Xslt30Processor::setJustInTimeCompilation | ( | bool | jit | ) |
Say whether just-in-time compilation of template rules should be used.
jit | true 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.
void Xslt30Processor::setOutputFile | ( | const char * | outfile | ) |
Set the output file of where the transformation result is sent
void Xslt30Processor::setParameter | ( | const char * | name, |
XdmValue * | value, | ||
bool | _static = false |
||
) |
Set the value of a stylesheet parameter
name | the name of the stylesheet parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name" |
value | the value of the stylesheet parameter, or null to clear a previously set value |
_static | For 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. |
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
name | of the property |
value | of the property |
void Xslt30Processor::setResultAsRawValue | ( | bool | option | ) |
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.
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 |
const char * Xslt30Processor::transformFileToString | ( | const char * | sourcefile, |
const char * | stylesheetfile | ||
) |
Perform a one shot transformation.
The result is returned as a string
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 |
XdmValue * Xslt30Processor::transformFileToValue | ( | const char * | sourcefile, |
const char * | stylesheetfile | ||
) |
void Xslt30Processor::transformToFile | ( | XdmNode * | source | ) |
const char * Xslt30Processor::transformToString | ( | XdmNode * | source | ) |
Execute transformation to string. Properties supplied in advance.
Perform the transformation based upon what has been cached.
source | - source document suppplied as an XdmNode object |