【发布时间】:2014-08-07 15:18:49
【问题描述】:
f尝试使用 XSLT 过滤 xml 输入,我在运行以下代码时遇到问题。我认为定义的 XSLT 存在问题。我想在 XSLT 中定义一个规则以丢弃输入 xml 中的“Foo”元素。这就是我的代码的样子:
from lxml import etree
from io import StringIO
def testFilter():
xslt_root = etree.XML('''\
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Foo"/>
</xsl:stylesheet>
''')
transform = etree.XSLT(xslt_root)
f = StringIO(unicode('<?xml version="1.0"?><ComponentData><DataSet name="one"> <Foo fooValue="2014"/></DataSet><DataSet name="two"><Foo fooValue="2015"/></DataSet></ComponentData>
'))
doc = etree.parse(f)
result_tree = transform(doc)
print(str(result_tree))
if __name__=='__main__':
testFilter()
【问题讨论】:
-
你为什么从
TimeStamp变成Foo?无论如何,想法保持不变,请在下面查看我的答案。 -
只是一个名字,可以是任何东西,没关系。