XSL transform with Python

V

Vegard Bakke

Hi!

All I want to do is transforming an XML into another XML using an XSLT
stylesheet.

From what I have found on the web/usenet there are several xml/xsl
libraries/wrapper, all in various stages of alpha/beta/stalled
releases. (Sablotron, Sab-pyth, PySablot, libxml2, libxslt are some of
those I found.)

The script will be running in a production environment and must
therefore be stable above all. Alphas and Betas are not that welcome.

Can anyone give me a pointer to what module to use, what is stable,
and what is and be stay standard for Python?


Regards,
Vegard

Don't reply to the address above, It's a spam trap and won't be read
 
I

Irmen de Jong

Vegard said:
Hi!

All I want to do is transforming an XML into another XML using an XSLT
stylesheet. [...]

Can anyone give me a pointer to what module to use, what is stable,
and what is and be stay standard for Python?

Theres no "THE" xslt library for Python, as far as I know.
I've used Pyana in the past (http://pyana.sourceforge.net/) with
good results, and it uses the Apache Xalan XSLT processor,
which I hold in high regard (wathever that's worth).

--Irmen
 
B

Brad Clements

Vegard Bakke said:
Hi!

All I want to do is transforming an XML into another XML using an XSLT
stylesheet.

libraries/wrapper, all in various stages of alpha/beta/stalled
releases. (Sablotron, Sab-pyth, PySablot, libxml2, libxslt are some of
those I found.)

The script will be running in a production environment and must
therefore be stable above all. Alphas and Betas are not that welcome.

Can anyone give me a pointer to what module to use, what is stable,
and what is and be stay standard for Python?


I use libxml2 and libxslt in production.

Simple code like this:

stylesheetArgs = {} # optional transform args
styleDoc = libxml2.parseDoc(docText) # <xml ...xsl:stylesheet >
style = libxslt.parseStylesheetDoc(styleDoc)

doc = libxml2.parseDoc(srcXML) # <xml input file>
result = style.applyStylesheet(doc,stylesheetArgs)
res = style.saveResultToString(result)
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
return res

It's plenty fast, and you can re-use compiled stylesheets (that's not
demonstrated above)
 
V

Vegard Bakke

Irmen de Jong said:
Theres no "THE" xslt library for Python, as far as I know.

Will there ever be one? Any of the existing packages that will be
taken up as part of the standard distribution of Python? Doesn't look
like XSLT is going to disappear in the first few years.

Cheers,
Vegard

Don't reply to the address above, It's a spam trap and won't be read
 
U

Uche Ogbuji

Hi!

All I want to do is transforming an XML into another XML using an XSLT
stylesheet.

From what I have found on the web/usenet there are several xml/xsl
libraries/wrapper, all in various stages of alpha/beta/stalled
releases. (Sablotron, Sab-pyth, PySablot, libxml2, libxslt are some of
those I found.)

The script will be running in a production environment and must
therefore be stable above all. Alphas and Betas are not that welcome.

Can anyone give me a pointer to what module to use, what is stable,
and what is and be stay standard for Python?

Don't forget 4Suite, which supports EXSLT and a lot of other
extensions, and has a very clean Python extension mechanism.

http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/python-xslt

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com

A hands-on introduction to ISO Schematron -
http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Wrestling HTML (using Python) -
http://www.xml.com/pub/a/2004/09/08/pyxml.html
Enterprise data goes high fashion -
http://www.adtmag.com/article.asp?id=10061
Principles of XML design: Considering container elements -
http://www-106.ibm.com/developerworks/xml/library/x-contain.html
Hacking XML Hacks - http://www-106.ibm.com/developerworks/xml/library/x-think26.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/
 
U

Uche Ogbuji

Brad Clements said:
I use libxml2 and libxslt in production.

Simple code like this:

stylesheetArgs = {} # optional transform args
styleDoc = libxml2.parseDoc(docText) # <xml ...xsl:stylesheet >
style = libxslt.parseStylesheetDoc(styleDoc)

doc = libxml2.parseDoc(srcXML) # <xml input file>
result = style.applyStylesheet(doc,stylesheetArgs)
res = style.saveResultToString(result)
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
return res

It's plenty fast, and you can re-use compiled stylesheets (that's not
demonstrated above)

You can easily do the same with 4XSLT.

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com

A hands-on introduction to ISO Schematron -
http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Wrestling HTML (using Python) -
http://www.xml.com/pub/a/2004/09/08/pyxml.html
Enterprise data goes high fashion -
http://www.adtmag.com/article.asp?id=10061
Principles of XML design: Considering container elements -
http://www-106.ibm.com/developerworks/xml/library/x-contain.html
Hacking XML Hacks - http://www-106.ibm.com/developerworks/xml/library/x-think26.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/
 
B

Brad Clements

You can easily do the same with 4XSLT.

I'm sure you can.

Though, when I started with libxml2, my target was a 66mhz 68K with uClinux
and 4 meg of ram. I think 4XSLT was too big and/or too slow in that
environment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top