The XSLT Virtual Machine
New in Oracle Database 10g is an XSLT Virtual Machine (XSLTVM) available for C and C++. It is the software implementation of a CPU designed to run compiled XSLT code. To do this, XSL stylesheets need to be compiled into the code the XSLTVM understands. Therefore, an XSL compiler is also included that is compliant with the XSLT 1.0 standard. This compilation can occur at runtime or can be stored for runtime retrieval. Thus, transformations are performed more quickly with higher throughput, as the stylesheet not only doesn’t need to be parsed, but the templates are applied with an index lookup instead of an XML operation.
Using the XSLTVM involves a bit different processing model and APIs. The following is a code listing of this process:
/* Create or re-use an XML meta context object. /
xctx = XmlCreate(&err,...);
/* Create or re-use an XSLT Compiler object. /
comp = XmlXvmCreateComp(xctx);
/* Compile an XSL stylesheet and store/cash the result bytecode. /
code = XmlXvmCompileFile(comp, xslFile, baseuri, flags, &err);
/* Create or reuse an XSLTVM object. The
explicit stack size setting is needed
when XSLTVM terminates with "... Stack Overflow" message or when smaller
memory footprints are required (see XmlXvmCreate). /
vm = XmlXvmCreate(xctx, "StringStack", 32, "NodeStack", 24);
/* Set a stylesheet bytecode to the XSLTVM object. */
len = XmlXvmGetBytecodeLength(code, &err);
err = XmlXvmSetBytecodeBuffer(vm, code, len);
/* Transform an instance XML document. */
err = XmlXvmTransformFile(vm, xmlFile, baseuri);
/* Clean up. */
XmlXvmDestroy(vm);
XmlXvmDestroyComp(comp);
XmlDestroy(xctx);
We discuss the XSLTVM in more detail in Chapter 21, in which we use it in an application.