How to debug lxml.etree.XSLTParseError: invalid expression error

I am trying to find out why lxml cannot parse an XSL document, which consists of a "root" document with various xml:include s. I get an error message:

 Traceback (most recent call last): File "s.py", line 10, in <module> xslt = ET.XSLT(ET.parse(d)) File "xslt.pxi", line 409, in lxml.etree.XSLT.__init__ (src/lxml/lxml.etree.c:151978) lxml.etree.XSLTParseError: Invalid expression 

This tells me where the lxml source is in error, but is there a way to get more through lxml about where in xsl the error is, or should I use a different method? I am trying to provide a service that accepts XSL documents, so I do not have access to the XML editor for manual debugging. What I would like to do is give feedback on why the transformation failed.

+5
source share
1 answer

Looking at the properties of the exceptions, I see that it has error_log, but for an xpath error (for example), the log contains only information about where the xpath error is located, so this is not particularly useful. For the use case, which I will talk about if arbitrary users submitting XSLT have no button approach. Instead, it would probably be easiest to use a combination of schema validation and user logic to figure out where the error is and why it is an error to send back to the user.

-1
source

Source: https://habr.com/ru/post/1206018/


All Articles