cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <>
Subject STX could seriously replace XSLT on the server side
Date Tue, 04 Mar 2003 10:35:38 GMT
If you don't know what STX is, just take a look here:

and then read here

There is one feature of STX that I really like: more precise 
<apply-templates/> semantics.

STX is designed to be incremental and event-based. It fits *perfectly* 
in Cocoon's view of the world. *Much* better than XSLT. Xalan has to 
jump thru hoops to give us incremental operation (and dies under load 
because of the multiple thread problems). Any STX processor is probably 
capable of giving us *almost* the same XSLT functionality we use, but 
without all the resources used to implement nicely on the server side a 
technology that was designed to run on the client-side onto a DOM.

Just look at the example STX transformation sheet (calling it stylesheet 
is now totally wrong, IMO) in the tutorial:

<?xml version="1.0"?>
     <stx:transform version="1.0"

note the 'tag' "transform"! no useless reference to 'style' since we are 
doing tree transformations and that hasn't anything to do with style, often.


       <stx:variable name="sum" select="0" />

       <stx:template match="order-list">

STX doesn't reinvent the wheel: reuses elements and attributes where it 
makes sense to do it.

                 <th colspan="5">Order Summary</th>
                 <td>Unit Price</td>
                 <td>Item Total</td>
               <stx:process-children />

Here is the difference: while apply-templates is utterly declerative, 
but requires great contextualization by the processing, 
<process-children> is more procedural, but not really different from 
<apply-templates match=""/> that is normally used to restrict template 

                 <td colspan="4">TOTAL:</td>
                <td><b><stx:value-of select="$sum" /></b></td>

       <stx:variable name="name" />
       <stx:variable name="quantity" />
       <stx:variable name="price" />

       <stx:template match="order">
         <stx:assign name="quantity" select="1" />

I like this new semantics, much clearer than XSLT where variable is used 
for both declaration and instantiation.

         <stx:process-children />
         <stx:assign name="sum"
           select="$sum + $quantity * $price" />
           <td><stx:value-of select="position()" /></td>
           <td><b><stx:value-of select="$name" /></b></td>
           <td><stx:value-of select="$quantity" /></td>
           <td><stx:value-of select="$price" /></td>
             select="$quantity * $price" /></td>

       <stx:template match="name">
         <stx:assign name="name" select="." />

       <stx:template match="quantity">
         <stx:assign name="quantity" select="." />

       <stx:template match="price">
         <stx:assign name="price" select="." />


Look at it: pure SAX, no memory, out-of-the-box incremental operation, 
and, I bet, faster than any equivalent XSLT stylesheet.

Just use the right tool for the right job and for server-side simple 
transformations, STX might be well worth it, expecially on pipelines 
where several stages of XSLT create loading problems.

Note that there is a JAXP-compatible java implementation of an STX 
processor on

It might just work with our TraxTransformer right out of the box (don't 
have time to try it today), but if somebody wants to run it and do some 
comparison benchmarking between XSLT, I'll be *very* happy to hear about it!

Stefano Mazzocchi                               <>
    Pluralitas non est ponenda sine necessitate [William of Ockham]

View raw message