Compiled XSLT stylesheet support in Kawa

The Kawa framework includes some support for XSLT. XSL (Extensible StyleSheet Language) Tranformations. XSLT is a popular language for transforming (including selecting and re-organizing) XML documents. The Kawa implementation treats an XSLT stylesheet as a program in the XSLT programming language, in the same way that other Kawa-supported languages (Scheme, XQuery, Emacs Lisp, and Common Lisp) are handled. Thus an XSLT stylesheets gets translated to Java bytecodes before execution, either on-the-fly, or saved to (one or more) .class files.


The current implementation is little more than a proof-of-concept. However, the following is an example of a working stylesheet:

<xsl:stylesheet xmlns:xsl="">
<xsl:template match="users">
<table border="1">

<xsl:template match="user_tuple">

<xsl:template match="userid">

<xsl:template match="name">

<xsl:template match="rating">

Assuming this is a file named MakeTable.xsl, and you have installed Kawa as the command/script kawa, you can compile the stylesheet using this command:

kawa --xslt --main -C MakeTable.xsl
This creates the compiled file MakeTable.class. This is a Java application, with a main method.

Now suppose you have a data file users.xml:

    <name>Tom Jones</name>
    <name>Mary Doe</name>

If you run this:

java MakeTable users.xml
you will get the resulting HTML code:
U01 Tom Jones B
U02 Mary Doe A


The following XSLT elements are handled:

Only the default no-attribute case is supported. The mode attribute is implemented but untested.
The select attribute is handled and evaluated, but this has not been tested well.
The match attribute can only be a simple element name. The name attribute is handled.
Is handled, but the expression in the test attribute is probably not evaluated in the correct context.

Namespace handling has not been tested.

Trying out Kawa-XSLT

You need to get and install Kawa, as described in the
Kawa manual.
Per Bothner
Last modified: Thu Jun 13 18:10:08 PDT 2002