how to smartly rewrite a python script that used to use XSLT?
I have an old python app that used to use XSLT to transform some XML data (two types of xml files with their respective xslt ones) to produce html output.
I'd like to port this app to appengine, but, sadly, appengine's python version doesn't support xslt.
Is there an easy way to rewrite my code without manually parsing and checking for given tags in the xml inputs?
in other words, do you have any idea of a generic way to do this?
Thanks and sorry for my poor en开发者_如何转开发glish!
Unfortunately there is no working XSLT implementation in pure python. You may be able to adapt your python code to run on jython, which would give you access to java's XSLT implementation. This is described in this blog post.
You will have to decide if porting/testing your existing code to jython is a better option than writing your own case specific xml parser/transformer.
You can use lxml to do XSLT tranformations, AND lxml should work with older python versions (web site says it supports 2.3 through 3.2).
If your XSLTs aren't too hideous, it might not be terribly hard to port them to Python using ElementTree's iterparse function (http://effbot.org/zone/element-iterparse.htm, and see http://www.dalkescientific.com/writings/diary/archive/2006/11/06/iterparse_filter.html).
You'd have to rewrite your XSLT templates as Python functions that could be called during parsing as element "events" are encountered, and you might have to store some document state to allow certain kinds of xsl:template/@match patterns to be handled, but it probably wouldn't be too nasty.
精彩评论