[ZPT] Stylesheet Language

Shane Hathaway shane@zope.com
Mon, 13 May 2002 16:00:21 -0400


Evan Simpson wrote:
> Thanks to Casey Duncan, I'm now thinking hard about an extension to ZPT 
> that I'm tentatively calling Template Style Sheet Language (pronounced 
> "Tassle").  Much like CSS, this would allow you to write the equivalent 
> of TAL statements out-of-line, and apply them based on tag selectors.
> 
> Stylesheet sytax is much more forgiving than attribute syntax, so some 
> of the more awkward aspects of TAL could be abandoned.  For instance, we 
> can use "=" instead of "define", and we can have multiple instances of 
> the same kind of statement applied in whatever order we specify.  String 
> expressions could simply be quoted strings, and explicit expression 
> types could become pseudo-functions such as "python(<expr>)". A major 
> advantage would be the ability to attach generic code to tags based on 
> pattern matching.  This also eliminates the need to add new tags in 
> order to control scope and order of operations.
> 
> Here's a complex example with made-up syntax:
> 
> <style type="text/tssl">
>   @begin { base = template/portal_url; }
>   .item-list {
>     items = path-string(attrs/items);
>     @if not(items) replace: structure "<b>No items</b>";
>   }
>   .item-list > * {
>       repeat: item items;
>       i = repeat/item/number;
>       [name] = "item-$1";
>   }
>   img.portal { [src] = "$base/${attrs/src}"; }
>   form.auto {
>     recname = attrs/name;
>     recpath = "$recname | options/$recname | nothing";
>     rec = path_string(recpath);
>   }
>   form.auto input, select, textarea {
>     name = attrs/name;
>     [name] = "$recname.$name:record";
>     value = path_string("rec/$name | nothing");
>   }
>   form.auto input[type=text] {
>     [value] = value;
>   }
>   form.auto textarea {
>     content: value;
>   }
>   form.auto option {
>     optvalue = attrs/value;
>     [selected] = python(value == optvalue);
>   }
> </style>

I like the concept.  It could make a lot of things simpler.  But... 
really, to me, not knowing CSS nor Perl extensively, the syntax used in 
the example above looks like CSS, Python, and Perl smashed together in a 
train wreck.  ;-)  Imagine mixing in some generated HTML, JavaScript, 
comments, and Python code blocks.  It would be very unwieldy.

Maybe we can discuss the requirements first?  It sounds like what we 
want is server-side, stylesheet-like tag processing.  That's what XSLT 
is good for, though a lot of us believe XSLT is too complicated to fit 
the same uses ZPT has.

OTOH, perhaps your example is a lot like CSS.  In that case, CSS has 
come to resemble Perl. :-)

Shane