cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pier Fumagalli <p...@betaversion.org>
Subject Re: [RFI] Garbage
Date Thu, 19 Jun 2003 14:25:18 GMT
"Peter Royal" <proyal@apache.org> wrote:

> On Wednesday, June 18, 2003, at 05:53  PM, Pier Fumagalli wrote:
>> Unless I'm not mistaken, the above example template is _NOT_ a well
>> formed
>> XML document! :-) :-)
> 
> Of course! I guess it was more of a, "why (nearly) re-invent the
> wheel".. But obviously it was to escape the XML syntax :)

Well, there are several advantages in not using XML as the storage datatype
for templates. The first objective I am trying to achieve is a simpler and
light-weight syntax.

Of course the Jelly people thought about it, given that in their documents
availabe at <http://jakarta.apache.org/commons/jelly/overview.html> they
write (quote):

> "Jelly could have a  surface syntax  that looks similar to Velocity. i.e.
> someone could make a parser of Jelly that had a look-and-feel of Velocity for
> common directives and expressions."

Now, what do I mean by "simpler" sintax? Imagine, for example a "foreach"
statement:

In XML (or better XSLT, but at the end of the day it'll have to apply to any
possible template which is based on XML) it looks quite ugly, to my
standards:

<ul>
  <xsl:foreach select="parameters">
    <li><xsl:value-of select="@name"/>: <xsl:value-of select="@value"/></li>
  </xsl:foreach>
</ul>

If you've ever used (and liked) velocity, for instance, you'd write
something MUCH simpler, and in garbage (which is basically Velocity with
Xpath), the same exact construct will become something like:

<ul>
  #foreach {parameters}
    <li>#{@name}: #{@value}</li>
  #end
</ul>

Sorry if I like the latter :-)

Now, if you see an if/else-if/else statement, XSLT looks like:

<div>
  <xsl:choose>
    <xsl:when test="parameter/@name = 'primary'">
      <span class="red"><xsl:value-of select="parameter/@name"/>: </span>
    </xsl:when>
    <xsl:when test="parameter/@name = 'secondary'">
      <span class="green"><xsl:value-of select="parameter/@name"/>: </span>
    </xsl:when>
    <xsl:when test="parameter/@name = 'tertiary'">
      <span class="green"><xsl:value-of select="parameter/@name"/>: </span>
    </xsl:when>
    <xsl:otherwise>
      <span><xsl:value-of select="parameter/@name"/>: </span>
    <xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="parameter/@value"/>
</div>

This is IMVHO a huge pain if compared with the following:

<div>
  #if {parameter/@name = "primary"}
    <span class="red">
  #elif {parameter/@name = "secondary"}
    <span class="green">
  #elif {parameter/@name = "tertiary"}
    <span class="green">
  #else
    <span>
  #end
  #{@name}:</span> #{@value}
</div>

Ok, ok, I could have written the above as:

<div>
  <span>
    <xsl:choose>
      <xsl:when test="parameter/@name = 'primary'">
        <xsl:attribute name="class">red</xsl:attribute>
      </xsl:when>
      <xsl:when test="parameter/@name = 'secondary'">
        <xsl:attribute name="class">green</xsl:attribute>
      </xsl:when>
      <xsl:when test="parameter/@name = 'tertiary'">
        <xsl:attribute name="class">blue</xsl:attribute>
      </xsl:when>
    </xsl:choose>
    <xsl:value-of select="parameter/@name"/>:
  </span>
  <xsl:value-of select="parameter/@value"/>
</div>

(which I don't know if it's easier, I just have to maybe set the class in a
span depending on the name of a parameter)... But still, this is way too
complicated for me (maybe not to write, but to read).

Also, the use of "<xsl:attribute ...>" will not allow us to start processing
the "<span>" element until that is closed, as the "<xsl:attribute>" might be
right at the end (and if that span contains something like 2 megs of data,
well, you see where I'm going to...

And on, and on, and on...

Now, why Velocity ain't good for Cocoon IMVHO? It's stream based, and it's
expression library is not something that will help me to introduce my
graphic team to all the rest of the wonders of Cocoon.

Basically, yes, I reinvented the wheel... I took two of the different
approaches used in the Cocoon PetStore for the view (JXPath and Velocity,
which I liked better), added few bits of what Stefano said in his "[RT] the
quest for the perfect template language", consulted XQuery, but Scott is a
very bad driver and uses to many curly braces (and I go nuts), shakered,
added salt and pepper, built and climbed a tree, parsed the garden with
JavaCC, and puff... Here comes out the trash...

    Pier


Mime
View raw message