XML+Logs to Latex. XSLT?

Fredrik Lundh fredrik at pythonware.com
Thu Jan 10 16:32:50 EST 2008


Florencio Cano 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:

     http://codespeak.net/lxml/

> - First process the XML document with Python (sax?) and do the first
> Latex document.
> - Second process each log with Python and insert the information in
> the Latex document created in first step.

You can do it in several steps, or you could generate the Latex file in 
one step, by first loading the XML structure into a Python data 
structure, and then loading (and possibly writing out the formatted 
version of) one log file after another.

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

If the log files are really large, use the iterparse API:

    http://effbot.org/zone/element-iterparse.htm#incremental-parsing

> Do you think this approach is the best? Fastest, clearest, more
> maintenable?

Depends on who's going to maintain it, of course.  I suspect a Haskell 
programmer would prefer if it was written in Haskell...

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

</F>




More information about the Python-list mailing list