cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
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:

http://stx.sourceforge.net/documents/

and then read here

http://www.xml.com/pub/a/2003/02/26/stx.html

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 xml.com 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.

       xmlns:stx="http://stx.sourceforge.net/2002/ns"
       xmlns="http://www.w3.org/1999/xhtml">

       <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.

         <html>
          <body>
             <table>
               <tr>
                 <th colspan="5">Order Summary</th>
               </tr>
               <tr>
                 <td>Line</td>
                 <td>Item</td>
                 <td>Quantity</td>
                 <td>Unit Price</td>
                 <td>Item Total</td>
               </tr>
               <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 
submatching.

               <tr>
                 <td colspan="4">TOTAL:</td>
                <td><b><stx:value-of select="$sum" /></b></td>
               </tr>
             </table>
           </body>
         </html>
       </stx:template>

       <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" />
         <tr>
           <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>
           <td><stx:value-of
             select="$quantity * $price" /></td>
         </tr>
       </stx:template>

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

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

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

     </stx:transform>

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

   http://joost.sourceforge.net

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                               <stefano@apache.org>
    Pluralitas non est ponenda sine necessitate [William of Ockham]
--------------------------------------------------------------------



Mime
View raw message