Python 3.x Python3和xml/xslt库

Python 3.x Python3和xml/xslt库,python-3.x,libxml2,libxslt,Python 3.x,Libxml2,Libxslt,在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

在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)
    ...
Python3.2中的等价物是什么


我这样问是因为在python3.2中似乎没有lnxml和libxslt。我听说过lxml——这是libxml2+libxslt的直接等价物,还是它有不同的调用模式(需要重写代码)

使用以下方法模拟代码:

lxml
列出了对Python 3.2的支持


所以结果应该是一样的。它使用Cython从同一个源代码生成同时在Python2.x和3.x上工作的C扩展。

我认为libxml2/xslt库现在通过
/configure
脚本参数
--使用Python=${PATH\u to\u Python3\u BINARY}
提供Python3绑定,例如
/usr/bin/Python3
from lxml import etree

# ...    
styledoc = etree.parse(my_xslt_file)
transform = etree.XSLT(styledoc)
doc = etree.fromstring(siri_response_data)
result = transform(doc)
# ...