[lxml-dev] setting xslt output encoding with lxml
Laurence Rowe
l at lrowe.co.uk
Sat Apr 4 22:34:57 CEST 2009
It seems that libxslt respects the last <xsl:output> tag found, so
just append your required version to the end of the stylesheet:
>>> xslt_doc = etree.XML('''<?xml version="1.0" ?>
... <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
... <xsl:output method="xml"/>
... <xsl:template match="/"><br /></xsl:template>
... </xsl:stylesheet>''')
>>> str(etree.XSLT(xslt_doc)(etree.XML('''<foo/>''')))
'<?xml version="1.0"?>\n<br/>\n'
>>> xslt_doc.append(etree.XML('''<xsl:output xmlns:xsl="http://www.w3.org/1999/XSL/Transform" method="html"/>'''))
>>> str(etree.XSLT(xslt_doc)(etree.XML('''<foo/>''')))
'<br>\n'
Laurence
2009/4/4 Stefan Behnel <stefan_ml at behnel.de>:
>
> Stefan Behnel wrote:
>> chris hoke wrote:
>>> To set the XSL output encoding I normally use <xsl:output encoding="..."/>
>>> in the stylesheet.
>>>
>>> At least in the Java based XSLT processors it is possible to set some
>>> attributes of xsl:output from the "outside" meaning when initializing or
>>> starting the transformation. So it is possible for example to overwrite any
>>> encoding specified in <xsl:output... with a different encoding.
>>
>> lxml.etree does not currently support this.
>
> I skimmed through the libxslt source and it looks like such a feature is
> not easily available. So the best way to do it is actually to copy and
> modify the stylesheet document as I explained.
>
> Stefan
> _______________________________________________
> lxml-dev mailing list
> lxml-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/lxml-dev
>
More information about the lxml-dev
mailing list