[ZPT] Any news on Template Style Sheet Language?

Evan Simpson evan at 4-am.com
Mon Dec 6 13:48:19 EST 2004


Ian Bicking wrote:
> Interesting, I hadn't seen that before.  I'm not sure if it's playing
>  the role of an XSLT-type transformation, or... what exactly.  I feel
>  like it should fit into some already-existing templating style, but
> I can't determine exactly what.

I doubt it fits.  TERSE allows you to express the sorts of tag-scoped
operations that TAL supports, but using CSS-style pattern matching.  It
is slightly similar in function to XSLT, but only slightly.

> Part of what confuses me about it is that it seems to apply both
> before normal ZPT substitution, and after.  There's something
> DOM-like about it, for these seem similar:
> 
> img#portal { [src] = "$base/${attrs/src}"; }
> 
> and:
> 
> document.getElementById('portal').setAttribute( 'src', '%s/%s' %
> (base, attrs.src))

Here's the semantic model that I use: First, the document is searched
for matches to TERSE rules.  Next, the rules are "attached" to the
matched nodes, mixing them in a deterministic way with TAL statements 
found on the same node. Finally, the template is rendered in the same 
fashion as a TAL-only ZPT, except that there are additional statements 
to execute along the way.

It takes a bit of getting used to, but the model is *quite* different
from manipulate-the-DOM approaches.

> This leads to the question -- which is a more accessible way to
> approach these modifications, from Python or form a stylesheet?  I
> think there are valid reasons for these kinds of transformations.
> The pluses and minuses are the same as for any domain-specific
> language, I think; because you are working before ZPT comes into
> play, these transformations really implement a kind of language, for
> better or worse.

One large practical advantage that the ruleset approach has over DOM
manipulation is this: you can combine a template and a ruleset into a 
"compiled" representation (TAL-like bytecode) that can then be rendered 
effeciently with different data sets.  Typical DOM code, on the other 
hand, must repeatedly search and transform the document's tree each time 
that it is run.

I also believe that rulesets are more "granular" than DOM code.  It is 
straightforward to add or modify rules in a ruleset, or to combine 
independently created rulesets.

Cheers,

Evan @ 4-am


More information about the ZPT mailing list