我将对XML应用XSLT
from lxml import etree
XSL= âââ
<xsl:stylesheet version=â1.0" xmlns:xsl=âhttp://www.w3.org/1999/XSL/Transform"
xmlns:people="http://people.example.com">
<xsl:template match=â@*|node()â>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy>
</xsl:template>
<xsl:template match=âpeople:name/text()â>
<xsl:text>Sir </xsl:text>
<xsl:value-of select=â.â />
</xsl:template>
</xsl:stylesheet>
âââ
# load input
dom = etree.parse(â/path/to/my.xmlâ)
# load XSLT
transform = etree.XSLT(etree.fromstring(XSL))
# apply XSLT on loaded dom
str(transform(dom))