-
-
Save congzhangzh/30ecfd89fa9f0d4139c585869d2df81f to your computer and use it in GitHub Desktop.
Python XSLT Transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from StringIO import StringIO | |
from lxml import etree | |
xslt_root = etree.XML('''\ | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:template match="/"> | |
<foo><xsl:value-of select="/a/b/text()" /></foo> | |
</xsl:template> | |
</xsl:stylesheet>''') | |
transform = etree.XSLT(xslt_root) | |
f = StringIO('<a><b>Hello World!</b></a>') | |
doc = etree.parse(f) | |
result_tree = transform(doc) | |
root = etree.XML('<a><b>Text</b></a>') | |
result = transform(root) | |
xml = str(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment