Adressing the Repoze-list here, since Chameleon is currently kept in
this repository.

For those not in the know (certainly before I read the
documentation[1], I was one of them), Genshi has a feature called
"match templates" which lets you first render a template, then apply a
second template to elements matched by an XPath-expression.

If this sounds a bit strange, it's because it is––but it's useful
because it can be used to sculpt HTML in a way similar to Deliverance
and/or XSLT. At any rate, it's a Genshi feature and we do support it
in ``chameleon.genshi``. Problem is, ``lxml`` is required for this to
function––what's more, this solution is suboptimal in terms of
performance (which is the raison d'etre for Chameleon in the first

There are two scenarios:

1) Match templates are defined and used on elements appearing in the
same template;
2) Match templates are brought in through an XInclude, dynamically, at

Assuming we know how to match elements using XPath, the first scenario
is reasonably easy; the difficult being only that the XPath ``select``
method (corresponding to the matched elements) must be made available.

The second scenario is more difficult, because these includes aren't
predictable at compile-time; as such, we have to match elements as we
render and apply the templates. As mentioned, this is currently solved
by post-processing the output using ``lxml`` and applying match
templates using callback-methods. It's not horrific, but it's also
convoluted and slow–––and slightly buggy.

However, I think there's a way out of the deadlock. If we compile the
template specifically for each XPath-expression (on-demand, of
course), we can match the elements at compile-time and have a
situation similar to (1).

This leaves us with the task of porting/writing an XPath selection
routine; it needn't be complete I think (Genshi's surely isn't).


Repoze-dev mailing list

Reply via email to