Template language with XPath support for source code generation?
kent37 at tds.net
kent37 at tds.net
Fri Jan 13 09:01:17 EST 2006
Stefan Behnel wrote:
> 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.
I have done a lot of text file generation in Jython and Java using
dom4j as the data model and Velocity as the template engine. It's a
very powerful combination.
dom4j elements have XPath accessors so you can say for example
myElement.selectNodes('some/xpath'). Velocity supports introspection on
its data so in a template I can say
#foreach $item ($parent.selectNodes("some/xpath"))
(my syntax may be a little off, this is from memory)
ISTM you should be able to do the same thing from CPython with a dom
model that has XPath accessors and a template engine that supports
calling methods on its data. I think lxml and Cheetah, among others,
would work this way.
Kent
More information about the Python-list
mailing list