Template language with XPath support for source code generation?

bruno at modulix onurb at xiludom.gro
Thu Jan 12 11:12:27 EST 2006

Stefan Behnel wrote:
> Hi!
> I need to generate source code (mainly Java) from a domain specific XML
> language, preferably from within a Python environment (since that's where the
> XML is generated).
> I tried using XSLT, but I found that I need a template system that supports
> Python interaction. I know, lxml's XSLT support is /somewhat/ getting there,
> but even with that, XSLT is so clumsy when it comes to code generation
> (looping constructs and if/else above all), that it would take me tons of XSLT
> code to write what I want.
> I've been looking through Python templating systems all over the place, but I
> just can't find one that supports XPath - which is by far the best thing to
> have when you generate stuff from XML. TAL might be able to get me part of the
> way (at least, it supports some kind of Path expressions, though only for
> object access), but the only available implementation is part of Zope and I
> can't make my code depend on Zope only for a template system.

Zope's implementation can be used freestanding AFAIK. There's also
SimpleTal that is totally independant from Zope.

> My problem is that I want to write as little Python code as possible to make
> the templates (almost) stand alone and thus readable without the backend code.
> I can transform the XML language to a more usable XML format beforehand, no
> problem, but I then need to access the result from the template - and that's
> almost impossible without XPath.
> Does anyone have an idea what I could use? Any hints are helpful.

Perhaps a TAL + elementTree combo could do ? (first parse the source XML
with elementTree, then pass the resulting tree as the context of the
ZPT/SimpleTal template)

My 2 cents

bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"

More information about the Python-list mailing list