XSL transform with Python

Uche Ogbuji uche at ogbuji.net
Fri Oct 8 20:40:22 CEST 2004


"Brad Clements" <bkc at Murkworks.com> wrote in message news:<mailman.4456.1097101225.5135.python-list at python.org>...
> "Vegard Bakke" <vegard at mail.com> wrote in message
> news:33a013af.0410060646.3a821dc7 at posting.google.com...
> > 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?
> >
> 
> 
> 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/



More information about the Python-list mailing list