[XML-SIG] using xslt with python

Paul Tremblay phthenry at earthlink.net
Sat Jun 14 02:05:08 EDT 2003

On Thu, Jun 12, 2003 at 07:40:26PM -0400, Daniel Veillard wrote:
>   You can make it work on Windows, and Unix by making sure your have
> libxml2 and libxslt python bindings installed too and using them without
> doing an exec. See http://xmlsoft.org/python.html and 
> http://xmlsoft.org/XSLT/python.html .
>   BTW xsltproc is ported to Windows, I don't see why this code would
> not work...

The first link didn't prove helpful. It did lead me to the software, but
after a successful build and install, I could not use the script, even
when I followed the author's instructions.

The second link did the trick. Apparently, I already had the bindings
module installed:

stylesheet = '/home/paul/.rst_to_docbook/xslt_stylesheets/reStruct_field_names.xsl'
xml_doc = '/home/paul/.rst_to_docbook/debug/converted_to_args_info'
styledoc = libxml2.parseFile(stylesheet)
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile(xml_doc)
result = style.applyStylesheet(doc, None)
style.saveResultToFilename("/home/paul/foo.xml", result, 0)

# code runs successfully

How di the binding get in my site-packages? Are they installed with
PyXml? Or do you think Mandrake linux might have put them there?

Last, what is the advantage to using the above code as opposed to using:

file_handle = os.popen('xsltproc xsl_file, xml_file)


If you claim that xsltproc ports to Windows, it seems the os.popen
option would almost be simpler.

Both methods work on my linux box. I am striving for the method with the
most compatibility.




*Paul Tremblay         *
*phthenry at earthlink.net*

More information about the XML-SIG mailing list