XML+Logs to Latex. XSLT?

Mike Meyer mwm-keyword-python.b4bdba at mired.org
Thu Jan 10 23:17:43 CET 2008

On Thu, 10 Jan 2008 22:32:50 +0100 Fredrik Lundh <fredrik at pythonware.com> wrote:

> > Yes. For sure. I though XSLT was something like XML not other
> > "language" and that Python will have any library that uses XSLT to do
> > transformation...
> XSLT is definitely a language (it's turing complete, after all), but 
> that there are of course several Python bindings to XSLT libraries; 
> here's one:

XSLT is definitely something like XML - because an XSLT file is an XML
file. But it represents a program, and hence is a programming
language.  It is unlike most other programming languages you will have
encountered. XSLT may well be the most popular thing like XSLT, but
Prolog is probably the language you've heard of that's closest to it.
If you want to transform your XML into different-shaped XML or flat
text, XSLT should be high on the list of tools to check out.

>      http://codespeak.net/lxml/

Very much recommended.

> But please don't use SAX if you can avoid it; it's hard to work with, 
> and not very efficient.  I'd recommend ElementTree, which is a light- 
> weight DOM library, that's part of the standard library:
>      http://effbot.org/zone/element-index.htm

While I love the ElementTree API, the standard library implementation
is missing tools that I find invaluable in working with XML.

No schema support, for instance. The effort of maintaining a schema is
repaid multiple times if you take advantage of it. If your application
validates the XML on input, you *know* that when you translate a
required attribute value to an the, the attribute will be there, and
the it's value will repersent an int. And using a schema-aware editor
is pretty much the only sane way for a human being to edit XML.

The XPath implementation is also limited. Having written a little
XSLT, not having pretty much all of XPath available for pulling values
is painful.

And of course, XSLT support, as there are things that XSLT is good

Others I'm not so sure about. External entities seem to be unsupported
by ElementTree. XInclude? More?

>  > Is this the way you will do it?
> As the author of ElementTree, I'm a bit biased, but I'd definitely do it 
> in Python ;-)

Ditto - well, except I'm not the author of ElementTree. If all you
want to do is read the XML into a tree of python strings, then the
ElementTree implementation is an excellent API for doing so, and being
in the standard library means you should already have it. If you want
to leverage XML to make your job as easy as possible, then I'd
recommend using the aforementioned lxml instead. It provides the same
ElementTree API on top of the popular libxml2 and libxslt libraries
(your Unix-like system probably comes with them pre-installed), and
hence gives you access to all the XML tools they provide - like the
ones I mentioned above.

Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

More information about the Python-list mailing list