You are here

XSLT Transform to TXT, with LXML

Maybe this should be obvious, but it wasn't to me. I've got an XML document and an XSLT stylesheet. But that stylesheet just produces text, not XML; it is essentially a template for an e-mail. So I was extending OIE's transformAction for performing XSLT transforms that produce other than XML... but the documentation is a bit thin and every example is XML results. The trick is pretty simple, just


and make sure [of course] that you have

<xsl:output method="txt" encoding="utf-8" omit-xml-declaration="yes"/>

declared in the template. So it should be as simple as:

def do_action(self):
    source = etree.parse(self._rfile)
    xslt = etree.fromstring(self._xslt)
    transform = etree.XSLT(xslt)
    result = transform(source)

in order to transform to just about anything.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer