Using XSLTVM

XSLT Virtual Machine is the software implementation of a "CPU" designed to run compiled XSLT code. A concept of virtual machine assumes a compiler compiling XSLT stylesheets to a sequence of byte codes or machine instructions for the "XSLT CPU". The byte-code program is a platform-independent sequence of 2-byte units. It can be stored, cached and run on different XSLTVM. The XSLTVM uses the bytecode programs to transform instance XML documents. This approach clearly separates compile (design)-time from run-time computations and specifies a uniform way of exchanging data between instructions.

XmlXvmCompileBuffer()

Compile an XSLT stylesheet from buffer into bytecode. Compiler flags could be one or more of the following:

XMLXVM_DEBUG forces compiler to include debug information into the bytecode

XMLXVM_STRIPSPACE is equivalent to <xsl:strip-space elements="*"/>.

The generated bytecode resides in a compiler buffer which is freed when next stylesheet is compiled or when compiler object is deleted. Hence, if the bytecode is to be reused it should be copied into another location.

XmlXvmCompileDom()

Compile an XSLT stylesheet from DOM into bytecode. Compiler flags could be one or more of the following:

XMLXVM_DEBUG forces compiler to include debug information into the bytecode

XMLXVM_STRIPSPACE is equivalent to <xsl:strip-space elements="*"/>.

The generated bytecode resides in a compiler buffer which is freed when next stylesheet is compiled or when compiler object is deleted. Hence, if the bytecode is to be reused it should be copied into another location.

XmlXvmCompileFile()

Compile XSLT stylesheet from file into bytecode. Compiler flags could be one or more of the following:

XMLXVM_DEBUG forces compiler to include debug information into the bytecode

XMLXVM_STRIPSPACE is equivalent to <xsl:strip-space elements="*"/>.

The generated bytecode resides in a compiler buffer which is freed when next stylesheet is compiled or when compiler object is deleted. Hence, if the bytecode is to be reused it should be copied into another location.

XmlXvmCompileURI()

Compile XSLT stylesheet from URI into bytecode. Compiler flags could be one or more of the following:

XMLXVM_DEBUG forces compiler to include debug information into the bytecode

XMLXVM_STRIPSPACE is equivalent to <xsl:strip-space elements="*"/>.

The generated bytecode resides in a compiler buffer which is freed when next stylesheet is compiled or when compiler object is deleted. Hence, if the bytecode is to be reused it should be copied into another location.

XmlXvmCreate()

Create an XSLT virtual machine. Zero or more of the following XSLTVM properties could be set by using this API:

"VMStack", size sets the size[Kbyte] of the main VM stack; default size is 4K.

"NodeStack", size sets the size[Kbyte] of the node-stack; default size is 16K.

"StringStack", size sets the size[Kbyte] of the string-stack; default size is 64K.

If the stack size is not specified the default size is used. The explicit stack size setting is needed when XSLTVM terminates with "Stack Overflow" message or when smaller memory footprints are required.

XmlXvmResetParams()

XmlXvmSetBaseURI()

Sets the base URI for the XSLTVM. The baseuri is used by VM to the compose the path XML documents to be loaded for transformation using document or XmlXvmTransformFile.

Syntax

xmlerr XmlXvmSetBaseURI(
xmlxvm *vm,
oratext *baseuri);

Parameter

In/Out

Description

vm

IN

VM object

baseuri

IN

VM base URI for reading and writing documents

Returns

(xmlerr) error code.

XmlXvmSetBytecodeBuffer()

Set the compiled bytecode from buffer. Any previously set bytecode is replaced. An XML transformation can't be performed if the stylesheet bytecode is not set. The VM doesn't copy the bytecode into internal buffer, hence the it shouldn't be freed before VM finishes using it.

XmlXvmSetDebugFunc()

The user callback function is invoked by VM every time the execution reaches a new line in the XSLT stylesheet. The VM passes to the user the stylesheet file name, the line number, the current context nodes-set and the current node index in the node-set. IMPORTANT - the stylesheet has to be compiled with flag XMLXVM_DEBUG.

XmlXvmSetOutputDom()

Sets the XSLTVM to output DOM. If xmldocnode==NULL, then the result DOM tree belongs to the VM object and is deleted when a new transformation is performed or when the VM object is deleted. If the result DOM tree is to be used for longer period of time then an xmldocnode has to be created and set to the VM object.

Syntax

xmlerr XmlXvmSetOutputDom(
xmlxvm *vm,
xmldocnode *doc);

Parameter

In/Out

Description

vm

IN

VM object

doc

IN

empty document

Returns

(xmlerr) error code

XmlXvmSetOutputEncoding()

Sets the encoding for the XSLTVM stream output. If the input (data) encoding is different from the one set by this APIs then encoding conversion is performed. This APIs overrides the encoding set in the XSLT stylesheet (if any).

Syntax

xmlerr XmlXvmSetOutputEncoding(
xmlxvm *vm,
oratext *encoding);

Parameter

In/Out

Description

vm

IN

VM object

encoding

IN

output encoding

Returns

(xmlerr) error code.

XmlXvmSetOutputSax()

Set XSLTVM to output SAX. If the SAX callback interface object is provided the VM outputs the result document in a form of SAX events using the user specified callback functions.

XmlXvmSetOutputStream()

Set the XSLTVM output to a user-defined stream. The default XSLTVM output is a stream. This APIs overrides the default stream with user specified APIs for writing.

Syntax

xmlerr XmlXvmSetOutputStream(
xmlxvm *vm,
xmlostream *ostream);

Parameter

In/Out

Description

vm

IN

VM object

ostream

IN

stream object

Returns

(xmlerr) error code.

XmlXvmSetTextParam()

Set the stylesheet top-level text parameter. The parameter value set in the XSLT stylesheet is overwritten. Since the top-level parameters are reset with stylesheet values after each transformation, this APIs has to be called again.