[Tutor] lost
Erik Price
erikprice@mac.com
Sun, 17 Mar 2002 17:26:07 -0500
On Sunday, March 17, 2002, at 04:24 PM, Gregor Lingl wrote:
> Maybe this new book (especially chaper 6)
> could be helpful to you:
>
> http://www.oreilly.com/catalog/pythonxml/toc.html
>
> Gregor
I'm kind of a dunce... I had forgotten that I have this book,
backburnered and waiting for me to finish "Python Web Programming". I
can summarize some of the main points from Chapter 6 ("Transforming XML
with XSLT"):
This chapter of the book starts with a short introduction to the theory
behind XSLT, which you can get at W3C (linked to earlier in this
thread). It then goes on to show two different ways that you can take
an XML document and transform it into HTML using an XSLT style sheet,
the first way being with "simplified stylesheets" (which is a very
limited but easy way to get your XML data into an [X]HTML document), and
the second using "standalone stylesheets" (which are the traditional use
of XSLT stylesheets, wherein you create XSL templates to handle the
various XML elements that you may have used -- this is a more flexible
way to go, especially if your data is not very homogenous).
The next few pages of the chapter are a more in-depth look at the
functions available in XSLT, and how templates are best constructed.
Following this are two detailed examples of using XSLT with Python: the
first actually refers back to an example from an earlier chapter in the
book (which focuses on SAX) and demonstrates how XSLT handles certain
jobs much better than just using a straightup SAX program (specifically,
transforming an XML document into a different XML document). The second
example discusses embedding 4XSLT (an open source XSLT parser
implemented in Python with C extensions) into python CGI scripts for
on-the-fly transformation upon HTTP request.
As far as XSLT processors go, the book explains that you can use any one
you like, but recommends 4XSLT since it's open source and uses Python.
If you need speed, I think Sablotron is supposed to be good, but might
be tricky to connect. Also, if you just want to experiment with XSLT
right this minute, MSIE6 (5 on Macs) has a built-in XSLT processor. As
long as you construct the XSLT stylesheet correctly and link to the
style sheet from the XML document, it should render correctly (I've
tried it in IE and Mozilla 0.9.8).
Erik