1

I use XSLT 2.0 file for converting ISOSTS XML document into HTML.

My code:

from lxml.etree import parse, XSLT

xslt = parse('/path/to/isosts2html_standalone.xsl')

# fixme: it works, but standard xsl fails!
# xslt = 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>''')

self._transformer = XSLT(xslt)  # <- FAILS !!!

dom = parse(file)
new_dom = self._transformer(dom)
return tostring(new_dom, pretty_print=True)

I have next error:

File "src/lxml/xslt.pxi", line 406, in lxml.etree.XSLT.init (src/lxml/etree.c:185192) lxml.etree.XSLTParseError: Start of literal

Or next error using isosts2html.xsl from archive:

File "src/lxml/xslt.pxi", line 406, in lxml.etree.XSLT.init (src/lxml/etree.c:185192) lxml.etree.XSLTParseError: Invalid expression

Does lxml support XSLT 2.0 and how to solve problem?

Nick
  • 9,735
  • 7
  • 59
  • 89
  • 2
    lxml uses libxslt which is an XSLT 1.0 processor so you can't use it to run XSLT 2.0 stylesheets (using any features that are not available in XSLT and XPath 1.0). So you would need to run XSLT 2 outside of Python by using Saxon 9 (available for the Java and .NET platform) or Saxon-C and have your Python program call Saxon. – Martin Honnen Oct 17 '17 at 08:51
  • @Martin Honnen, thanks! I think it is good solution for me. – Nick Oct 17 '17 at 09:01
  • Does this answer your question? [Plone - XSLTApplyError: xsltValueOf: text copy failed](https://stackoverflow.com/questions/6644695/plone-xsltapplyerror-xsltvalueof-text-copy-failed) – dank8 Feb 20 '23 at 14:06
  • please include the error information provided by lxml.etree.XMLSchema('').error_log See: lxml.de/xpathxslt.html#errors-and-messages – dank8 Feb 21 '23 at 01:44
  • 1
    @dank8 Question was asked about 5 years ago, I have no logs now. There were no problems with XSLT 1, but with XSLT 2 only. In that project I used Saxon and it worked well. – Nick Feb 21 '23 at 07:32

0 Answers0