Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python XSLT Transformation
from StringIO import StringIO
from lxml import etree
xslt_root = etree.XML('''\
<xsl:stylesheet version="1.0"
<xsl:template match="/">
<foo><xsl:value-of select="/a/b/text()" /></foo>
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