[ZPT] Any news on Template Style Sheet Language?

Ian Bicking ianb at colorstudy.com
Mon Dec 6 13:03:31 EST 2004


Hamish Lawson wrote:
> Back in May 2002 Evan Simpson intimated that he was thinking about an 
> extension to ZPT called Template Style Sheet Language [1]. "Much like 
> CSS, this would allow you to write the equivalent of TAL statements 
> out-of-line, and apply them based on tag selectors." Was any progress made?
> 
> [1] http://mail.zope.org/pipermail/zpt/2002-May/003303.html

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.

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

Excusing the fact that the DOM API is less than elegent.  But then 
there's other portions that apply before normal substitution, like:

    .item-list {
      items = path-string(attrs/items);
      @if not(items) replace: structure "<b>No items</b>";
    }

Well, actually both could be done before normal substitution... somehow 
I just intuitively think of static substitution happening later in the 
process.  Still, there's a DOM feel, though because it works on ZPT code 
rather than ZPT output, it also has a macro-like feel.  E.g., this last 
rule might be like:

els = document.getElementsByClass('item-list')
for el in els:
     items = tal_eval(namespace, el.getAttribute('items'))
     if not items:
         new = document.createElement('b')
         new.appendChild(document.createTextNode('No items'))
         el.parentNode.replaceChild(new, el)
     else:
         el.namespace['items']

I don't think getElementsByClass exists, but that's a minor detail.  In 
this model, ZPT would have to evaluate the parsed DOM, and look for 
.namespace attributes (which would get folded into the namespace with 
limited scope).

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.

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the ZPT mailing list