Discussion:
XSLT to Python script conversion?
Matej Cepl
2012-02-13 11:20:28 UTC
Permalink
Hi,

I am getting more and more discouraged from using XSLT for a
transformation from one XML scheme to another one. Does anybody could
share any experience with porting moderately complicated XSLT stylesheet
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl)
into a Python script using ElementTree's interparse or perhaps xml.sax?

Any tools for this? Speed differences (currently I am using xsltproc)?
Any thoughts?

Thank you,

Mat?j
Stefan Behnel
2012-02-13 13:34:08 UTC
Permalink
I am getting more and more discouraged from using XSLT for a transformation
from one XML scheme to another one.
Could you explain what it is that discourages you about it? That would
allow us to come up with better alternatives for your specific problem.
Does anybody could share any experience
with porting moderately complicated XSLT stylesheet
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl)
into a Python script using ElementTree's interparse or perhaps xml.sax?
Any tools for this? Speed differences (currently I am using xsltproc)? Any
thoughts?
You could try switching to lxml. It would at least allow you to do a part
of the processing in Python and only use XSLT when it seems more
appropriate and/or easier.

Stefan
Mike C. Fletcher
2012-02-13 16:28:49 UTC
Permalink
Post by Matej Cepl
Hi,
I am getting more and more discouraged from using XSLT for a
transformation from one XML scheme to another one. Does anybody could
share any experience with porting moderately complicated XSLT
stylesheet
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl)
into a Python script using ElementTree's interparse or perhaps xml.sax?
Any tools for this? Speed differences (currently I am using xsltproc)?
Any thoughts?
Thank you,
Mat?j
I wound up rewriting the Docbook to XSL transformation for PyOpenGL's
docs in Python using lxml.etree and Kid (now reworked to use Genshi).
However, that was a fairly direct translation, it has only a handful of
strategies for transforming nodes from docbook to xhtml. That said, it
took our processing time down from
so-long-I-just-didn't-want-to-work-on-the-docs down to
regenerate-whenever-I-make-a-trivial-change.

http://bazaar.launchpad.net/~mcfletch/pyopengl/directdocs/files
<http://bazaar.launchpad.net/%7Emcfletch/pyopengl/directdocs/files>

Is the repository where the project lives. It *also* does a lot of
other processing, but the generate.py, model.py and
templates/section.kid files are all you need to look at to understand
the docbook processing.

HTH,
Mike
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
Tim Arnold
2012-02-15 17:48:13 UTC
Permalink
Post by Matej Cepl
Hi,
I am getting more and more discouraged from using XSLT for a
transformation from one XML scheme to another one. Does anybody could
share any experience with porting moderately complicated XSLT stylesheet
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl)
into a Python script using ElementTree's interparse or perhaps xml.sax?
Any tools for this? Speed differences (currently I am using xsltproc)?
Any thoughts?
Thank you,
Mat?j
Just a note to encourage you to stick with XSLT. I also use lxml for
creating and postprocessing my DocBook documents and it is great. But I
use the DocBook XSL stylesheets to convert to html; if you're like me,
you got discouraged at the strangeness of the XSLT language.

I'm no expert with it by any means, but I'm amazed at some of the things
it does. It is a great tool to add to your programming toolbox.

Also, I used xsltproc for a while but bogged down in processing time.
Now I use SAXON which is much faster for my documents.

Good luck,
--Tim
Matej Cepl
2012-02-16 17:17:13 UTC
Permalink
Post by Tim Arnold
Just a note to encourage you to stick with XSLT. I also use lxml for
creating and postprocessing my DocBook documents and it is great. But I
use the DocBook XSL stylesheets to convert to html; if you're like me,
you got discouraged at the strangeness of the XSLT language.
No, the strangness is not that bad (well, it is bad ... almost anything
feels bad comparing to Python, to be honest, but not the reason I would
give up; after all I spent couple of years with Javascript).

The terrible debugging is one thing, and even worse, I just still cannot
get over rules around spaces: whitespace just jumps at me randomly in
random places and is erased in others.

Mat?j
Ross Ridge
2012-02-17 20:37:57 UTC
Permalink
Post by Matej Cepl
No, the strangness is not that bad (well, it is bad ... almost anything
feels bad comparing to Python, to be honest, but not the reason I would
give up; after all I spent couple of years with Javascript).
The XSLT language is one of the worst misuses of XML, which puts it way
beyond bad.
Post by Matej Cepl
The terrible debugging is one thing, and even worse, I just still cannot
get over rules around spaces: whitespace just jumps at me randomly in
random places and is erased in others.
I use explicit <xsl:text> nodes exclusively to avoid this problem.

Ross Ridge
--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rridge at csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
Stefan Behnel
2012-02-17 20:53:48 UTC
Permalink
Post by Ross Ridge
Post by Matej Cepl
No, the strangness is not that bad (well, it is bad ... almost anything
feels bad comparing to Python, to be honest, but not the reason I would
give up; after all I spent couple of years with Javascript).
The XSLT language is one of the worst misuses of XML, which puts it way
beyond bad.
Clearly a matter of opinion.

Stefan
Ross Ridge
2012-02-17 21:11:17 UTC
Permalink
Post by Ross Ridge
The XSLT language is one of the worst misuses of XML, which puts it way
beyond bad.
Clearly a matter of opinion.
No. There's no excuse for using XML as the syntax of a language like
XLST.

Ross Ridge
--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rridge at csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
Loading...