SaxonC
11.6
Saxon Processor library for C/C++, PHP and Python
|
#include <XsltExecutable.h>
Public Member Functions | |
void | setcwd (const char *cwd) |
set the current working directory (cwd). This method also applies to the More... | |
void | setBaseOutputURI (const char *baseURI) |
Set the base output URI. More... | |
void | setGlobalContextItem (XdmItem *value) |
Set the source document from an XdmNode for the transformation. More... | |
void | setGlobalContextFromFile (const char *filename) |
XsltExecutable * | clone () |
Create a clone object of this XsltExecutable object. More... | |
void | setInitialMode (const char *modeName) |
Set the initial mode for the transformation. More... | |
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 | setResultAsRawValue (bool option) |
void | setParameter (const char *name, XdmValue *value) |
std::map< std::string, XdmValue * > & | getResultDocuments () |
XdmValue * | getParameter (const char *name) |
bool | removeParameter (const char *name) |
bool | removeProperty (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) |
char ** | createCharArray (int len) |
void | deleteXdmValueArray (XdmValue **arr, int len) |
Utility method for Python API - internal use only. More... | |
void | setSaveXslMessage (bool show, const char *filename=nullptr) |
This method gives users the option to switch on or off the xsl:message feature. More... | |
void | setCaptureResultDocuments (bool flag, bool rawResults=false) |
Enable the capture of the result-document output into an std:map. This overrides the default mechanism. More... | |
void | exportStylesheet (const char *filename) |
Produce a representation of the compiled stylesheet. More... | |
void | transformFileToFile (const char *sourcefile, const char *outputfile) |
Perform a one shot transformation. More... | |
const char * | transformFileToString (const char *sourcefile) |
Perform a one shot transformation. More... | |
XdmValue * | transformFileToValue (const char *sourcefile) |
void | applyTemplatesReturningFile (const char *outfile) |
Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file. More... | |
const char * | applyTemplatesReturningString () |
Invoke the compiled stylesheet by applying templates to a supplied input sequence, Saving the results as serialized string. More... | |
XdmValue * | applyTemplatesReturningValue () |
Invoke the compiled stylesheet by applying templates to a supplied input sequence, Saving the results as an XdmValue. More... | |
void | callTemplateReturningFile (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 *templateName=nullptr) |
Invoke a transformation by calling a named template and return result as a string. More... | |
XdmValue * | callTemplateReturningValue (const char *templateName=nullptr) |
Invoke a transformation by calling a named template and return result as an XdmValue. More... | |
void | callFunctionReturningFile (const char *functionName, XdmValue **arguments, int argument_length, const char *outfile) |
Call a public user-defined function in the already compiled stylesheet. More... | |
const char * | callFunctionReturningString (const char *functionName, XdmValue **arguments, int argument_length) |
Call a public user-defined function in the compiled stylesheet. More... | |
XdmValue * | callFunctionReturningValue (const char *functionName, XdmValue **arguments, int argument_length) |
Call a public user-defined function in the already compiled stylesheet. More... | |
const char * | transformToString (XdmNode *source=nullptr) |
Execute transformation to string. Properties supplied in advance. More... | |
XdmValue * | transformToValue (XdmNode *source=nullptr) |
Execute transformation to Xdm Value. Properties supplied in advance. More... | |
void | transformToFile (XdmNode *source=nullptr) |
Execute transformation to file. Properties supplied in advance. More... | |
bool | exceptionOccurred () |
SaxonApiException * | getException () |
Check for exception thrown and return the SaxonApiException object. More... | |
const char * | getErrorMessage () |
Get the error message if there are any error. More... | |
void | exceptionClear () |
Clear any exception thrown. | |
Friends | |
class | Xslt30Processor |
An XsltExecutable
represents the compiled form of a stylesheet.
An XsltExecutable is created by using one of the compile
methods on the Xslt30Processor class.
void XsltExecutable::applyTemplatesReturningFile | ( | 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.
outfile | - The file name where results will be stored |
const char * XsltExecutable::applyTemplatesReturningString | ( | ) |
Invoke the compiled 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.
XdmValue * XsltExecutable::applyTemplatesReturningValue | ( | ) |
Invoke the compiled 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.
void XsltExecutable::callFunctionReturningFile | ( | const char * | functionName, |
XdmValue ** | arguments, | ||
int | argument_length, | ||
const char * | outfile | ||
) |
Call a public user-defined function in the already compiled stylesheet.
Here we wrap the result in an XML document, and sending this document to a specified file
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 |
outfile | - The file name where results will be stored, |
const char * XsltExecutable::callFunctionReturningString | ( | const char * | functionName, |
XdmValue ** | arguments, | ||
int | argument_length | ||
) |
Call a public user-defined function in the compiled stylesheet.
Here we wrap the result in an XML document, and serialized this document to string value
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 |
XdmValue * XsltExecutable::callFunctionReturningValue | ( | const char * | functionName, |
XdmValue ** | arguments, | ||
int | argument_length | ||
) |
Call a public user-defined function in the already compiled stylesheet.
Here we wrap the result in an XML document, and return the document as an XdmValue
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 Count of arguments objects in the array |
void XsltExecutable::callTemplateReturningFile | ( | 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).
templateName | - The name of the initial template. This must match the name of a public named template in the stylesheet. If the value is nullptr, the clark name for xsl:initial-template is used. |
outfile | - The file name where results will be stored, |
const char * XsltExecutable::callTemplateReturningString | ( | const char * | templateName = nullptr | ) |
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).
templateName | - the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is nullptr, the clark name for xsl:initial-template is used. |
XdmValue * XsltExecutable::callTemplateReturningValue | ( | const char * | templateName = nullptr | ) |
Invoke a transformation by calling a named template and return result as an XdmValue.
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).
templateName | - the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is nullptr, the clark name for xsl:initial-template is used. |
void XsltExecutable::clearParameters | ( | bool | deleteValues = false | ) |
Clear parameter values set.
Default behaviour (false) is to leave XdmValues in memory. Individual pointers to XdmValue objects have to be deleted in the calling program.
deleteValues | - if true then XdmValues are deleted |
XsltExecutable * XsltExecutable::clone | ( | ) |
Create a clone object of this XsltExecutable object.
|
inline |
Utility method for working with SaxonC on Python
|
inline |
Utility method for working with SaxonC on Python
|
inline |
bool XsltExecutable::exceptionOccurred | ( | ) |
Checks for pending exceptions without creating a local reference to the exception object
void XsltExecutable::exportStylesheet | ( | const char * | filename | ) |
Produce a representation of the compiled stylesheet.
The representation of the compiled stylesheet is in an XML form, suitable for distribution and reloading. If the configuration under which the export takes place is suitably licensed, then license information will be included in the export file allowing execution of the stylesheet without any additional license.
The detailed form of the output representation is not documented.
filename | - the destination for the XML document containing the diagnostic representation of the compiled stylesheet. The stream will be closed when writing has finished. |
const char * XsltExecutable::getErrorMessage | ( | ) |
Get the error message if there are any error.
A transformation may have a number of errors reported against it.
SaxonApiException * XsltExecutable::getException | ( | ) |
Check for exception thrown and return the SaxonApiException object.
XdmValue * XsltExecutable::getParameter | ( | const char * | name | ) |
std::map< std::string, XdmValue * > & XsltExecutable::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 > & XsltExecutable::getProperties | ( | ) |
Get all properties as a std::map.
const char * XsltExecutable::getProperty | ( | const char * | name | ) |
Get a property value by name
name | - Specified paramater name to get |
std::map< std::string, XdmValue * > & XsltExecutable::getResultDocuments | ( | ) |
Return the result-documents resulting from the execution of the stylesheet. Null is returned if the user has not enabled this feature via the method setCaptureResultDocuments()
bool XsltExecutable::removeParameter | ( | const char * | name | ) |
Remove a parameter (name, value) pair from a stylesheet
name | the name of the stylesheet parameter |
bool XsltExecutable::removeProperty | ( | const char * | name | ) |
Remove a property (name, value) pair from the executable
name | the name of the property to be removed |
void XsltExecutable::setBaseOutputURI | ( | const char * | baseURI | ) |
Set the base output URI.
The base output URI is used for resolving relative URIs in the href
attribute of the xsl:result-document
instruction; it is accessible to XSLT stylesheet code using the XPath current-output-uri() function
baseURI | - the base output URI |
void XsltExecutable::setCaptureResultDocuments | ( | bool | flag, |
bool | rawResults = false |
||
) |
Enable the capture of the result-document output into an std:map. This overrides the default mechanism.
If this option is enabled, then any document created using xsl:result-document is saved (as an XdmNode) in an std::map object where it is accessible using the URI as a key. After the execution of the transformation a call on the getResultDocuments()
method is required to get access to the result-documents in the map.
flag | - true causes secondary result documents from the transformation to be saved in a map; false disables this option. |
rawResults | - true enables the handling of raw destination for resultsDocuments. If not supplied this can also be set on the setResultAsRawValue method. The setResultAsRawValue method has higher priority to this flag |
void XsltExecutable::setcwd | ( | const char * | cwd | ) |
set the current working directory (cwd). This method also applies to the
The cwd is used to set the base URI is part of the static context, and is used to resolve any relative URIs appearing within XSLT.
cwd | - Current working directory |
void XsltExecutable::setGlobalContextFromFile | ( | const char * | filename | ) |
Set the source from file for the transformation.
void XsltExecutable::setGlobalContextItem | ( | XdmItem * | value | ) |
void XsltExecutable::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 XsltExecutable::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 XsltExecutable::setInitialMode | ( | const char * | modeName | ) |
Set the initial mode for the transformation.
modeName | the EQName of the initial mode. Two special values are recognized, in the reserved XSLT namespace: xsl:unnamed to indicate the mode with no name, and xsl:default to indicate the mode defined in the stylesheet header as the default mode. The value null also indicates the default mode (which defaults to the unnamed mode, but can be set differently in an XSLT 3.0 stylesheet). |
void XsltExecutable::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 XsltExecutable::setOutputFile | ( | const char * | outfile | ) |
Set the output file of where the transformation result is sent
void XsltExecutable::setParameter | ( | const char * | name, |
XdmValue * | value | ||
) |
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 nullptr to clear a previously set value |
void XsltExecutable::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
name | of the property |
value | of the property |
void XsltExecutable::setResultAsRawValue | ( | bool | option | ) |
void XsltExecutable::setSaveXslMessage | ( | bool | show, |
const char * | filename = nullptr |
||
) |
This method gives users the option to switch on or off the xsl:message
feature.
It is also possible to send the xsl:message
outputs to file given by file name.
show | - boolean to indicate if xsl:message should be outputted. Default is on. |
filename | - If the filename argument is present then the xsl:message output is appended to the given filename with location cwd+filename |
void XsltExecutable::transformFileToFile | ( | const char * | sourcefile, |
const char * | outputfile | ||
) |
Perform a one shot transformation.
The result is stored in the supplied outputfile.
sourcefile | - The file name of the source document |
outputfile | - The file name where results will be stored |
const char * XsltExecutable::transformFileToString | ( | const char * | sourcefile | ) |
Perform a one shot transformation.
The result is returned as a string
sourcefile | - The file name of the source document |
XdmValue * XsltExecutable::transformFileToValue | ( | const char * | sourcefile | ) |
void XsltExecutable::transformToFile | ( | XdmNode * | source = nullptr | ) |
Execute transformation to file. Properties supplied in advance.
Perform the transformation based upon a compiled stylesheet and source document. Assume the output file has been set in advance
source | - source document supplied as an XdmNode object. nullptr accepted if source document has been set already. |
const char * XsltExecutable::transformToString | ( | XdmNode * | source = nullptr | ) |
Execute transformation to string. Properties supplied in advance.
Perform the transformation based upon what has been cached.
source | - source document supplied as an XdmNode object. nullptr accepted if source document has been set already. |