![]() |
XML and XSL from servers to cell-phones | Table of contents | Indexes | Informix &,amp, XML | ![]() |
|||
XSLTVM - an XSLT Virtual Machine |
| Novoselsky, Anguel |
| Anguel Novoselsky |
| Member of Technical Staff IV |
California ![]() Netfish Technologies, Inc. ![]() Santa Clara ![]() USA ![]() | Netfish Technologies, Inc.,
2350 Mission College Blvd., Suite 650 Santa Clara California USA 95054 Phone: +1 408 350 9500 email: anovosesky@netfish.com |
| Biography |
| Karun, K |
| K Karun |
| Project Lead |
California ![]() Oracle Corporation ![]() Redwood Shores ![]() | Oracle Corporation,
500 Oracle Parkway Redwood Shores California 94065 Phone: 1-650-560-9874 Fax: 1-650-506-7203 email: kkarun@us.oracle.com |
| Biography |
| Abstract |
Introduction |
XSL ![]() | XSL is a language for expressing stylesheets. It consists of two parts: a language for transforming XML documents, and an XML vocabulary for specifying formatting semantics. In this paper we discuss the part for transforming XML documents. A transformation expressed in XSLT describes rules for transforming a source tree into a result tree. The transformation is achieved by associating patterns with templates. A pattern is matched against elements in the source tree. A template is instantiated to create part of the result tree. |
| XSLTVM | AnXSLTVM is an abstract computing machine. Like a real computing machine, it has an instruction set and manipulates various memory areas at run time. It is reasonably common to implement a programming language using a virtual machine; the best-known virtual machine may be the P-Code machine of UCSD Pascal. The described XSLTVM is an attempt to define an stack oriented VM with low-level set of instructions as a virtual model for XSLT processing. However, the virtual machine does not assume any particular implementation technology, host hardware, or host operating system. It could be a software implementation of a "CPU" designed to run compiled XSLT code. A concept of virtual machine assumes a compiler compiling XSLT stylesheets to sequence of byte codes of machine instructions for "XSLT CPU". |
Architecture of XSLTVM |
| VM stack | The XSLT Virtual Machine has a stack based architecture. TheVM stack (is analogous to the stack of a conventional language: it holds local variables and partial results, and plays a part in template invocation and return. Also, most of XSLTVM machine instructions take their operands values from the top of the VM stack and replace them with the result. Stack cell contents types are: |
Compiling for XSLTVM |
| The XSLTVM works with the compiled set of instructions generated by a XSLT compiler. In this section, we discuss formats of a typical XSLT instructions. |
Instruction description |
| With only few exceptions XSLTVM instructions have the following formats: |
opcode, mode, operand1 [, operand2 ] |
| Depending on the mode the operands could be one of following: |
Expression and template compilation |
| First example illustrates the compilation of an XPath expression including steps and filter sub-expressions. |
/sales/domestic[position()=1 and @attr="value"] |
| is translated to: |
CHILD #sales // constant pool index CHILD #domestic // constant pool index STORE i // store current node set as a // loop index JMP LOOP0011 LOOP0001: INCR i LOOP0011: FOR_EACH i, ENDL0001 // instruction pool index LOAD_S i // loads current node CALL_FUNC #position COMP #1 JNE LOOP0001 LOAD_S i LOAD_ATTR #attr COMP #value JNE LOOP0001 ADD_NODE i // add 'i' to result node set JMP LOOP0001 ENDL0001: |
| Next example illustrates how the previous XPath expression is used in template body: |
<xsl:template match="doc">
<xsl:param name="file">table.html</xsl:param>
<table href="{$file}">
<xsl:apply-templates select="/sales/domestic[position() =1
and @attr = "value"] />
<xsl:with-param name="file">
file.xsd
</xsl:with-param>
</table>
</xsl:template>
|
| is compiled to: |
T0022: TEMPLATE PARAM #file, #table.html MK_STAG #mytable //creates <table> MK_ATTR #href //current fragment is //<table href=" "> MK_ATTRVAL file ADD_NODE _current //creates node set for XPath .. //expression, evaluate XPath .. //and as a result, the current .. //node set is on the top STORE j //store the XPath node set JMP LOOP0012 LOOP0002: INCR j LOOP0012: FOR_EACH j,ENDL0002 MATCH j //match with pattern pool //matched template descriptor //is pushed ALLOC_FRAME j //allocates new template frame PARAM #file,#table.xsd //stores param value at offset CALL_TEMP _desc //jumps to template index from //descriptor JMP LOOP0002 ENDL0002: MK_ETAG #table //creates </table> RETURN |
Design goals |
Future work |
| We also plan to add support for XMLSchema datatypes and archetypes, and provide extensibility mechanism in XSLT virtual machine to make callout to other programming or scripting languages. |
| Bibliography |
|
|
|
|
|
![]() |
XML and XSL from servers to cell-phones | Table of contents | Indexes | Informix &,amp, XML | ![]() | |||