Re: XML+Logs to Latex. XSLT?



On Thu, 10 Jan 2008 22:32:50 +0100 Fredrik Lundh <fredrik@xxxxxxxxxxxxxx> 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
for.

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
--
Mike Meyer <mwm@xxxxxxxxx> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
.



Relevant Pages

  • Subject: ANN: 4Suite XML 1.0b2
    ... 4Suite XML - XML, XPath, XSLT, related technologies and support ... 4Suite RDF - RDF processing libraries and stand-alone DBMS ...
    (comp.lang.python.announce)
  • Re: Why is OO popular?
    ... Do your homework and you'll know that XML is *not* a programming ... language. ... XSLT is a document content access and content modification syntax. ...
    (comp.object)
  • Re: Forth as "a better XML"
    ... XML parsers. ... The first problem is that Forth is too powerful in the sense that you can construct completely arbitrary data structures in memory. ... When you create a data structure in a language such as Perl, Python, Ruby, Lua, and so on, there are a set of primitive data structures that you use to build up more complicated structures. ... And that leads to the second problem-- there is in general a reluctance in the Forth community toward libraries. ...
    (comp.lang.forth)
  • Re: Python job opening at GPO in Washington, DC
    ... Traditionally it's been SGML, currently in transition to XML, with an ... considered as the new page description language, and XSLT will be the ...
    (comp.lang.python)
  • Re: Select MaxDate from xml
    ... How can I select node from xml where the value is the max? ... XSLT 1.0 notoriously did not have one, ... constrained to use XSLT 1.0 without libraries. ... In any case, it is not a good idea to store dates with alpha months, ...
    (microsoft.public.dotnet.xml)