在python2.6中,我这样做是为了实现xsl转换。
import libxml2
import libxslt
...
styledoc = libxml2.parseFile(my_xslt_file)
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseDoc(siri_response_data)
result = style.applyStylesheet(doc, None)
...
Python 3.2中的等价物是什么?
我之所以这样问,是因为在python3.2中似乎没有提供lnxml和libxslt。我听说过lxml -这是libxml2 + libxslt的直接等价物,还是有不同的调用模式(需要重写代码)?
发布于 2012-01-23 14:44:56
使用lxml模拟您的代码
from lxml import etree
# ...
styledoc = etree.parse(my_xslt_file)
transform = etree.XSLT(styledoc)
doc = etree.fromstring(siri_response_data)
result = transform(doc)
# ...
lxml
列出了对Python3.2的支持
lxml
uses libxml2/libxslt
under the hood,因此结果应该是相同的。它使用Cython从相同的源码example生成可以在Python2.x和3.x上运行的C扩展。
https://stackoverflow.com/questions/8971173
复制相似问题