Skip to content
/ lxml Public

Fix xslt error parsing so filename and line numbers show.#206

Merged
scoder merged 1 commit intolxml:masterfrom
SemanticsOS:lambdafu/xslterror
Sep 16, 2016
Merged

Fix xslt error parsing so filename and line numbers show.#206
scoder merged 1 commit intolxml:masterfrom
SemanticsOS:lambdafu/xslterror

Conversation

@lambdafu
Copy link
Contributor

This is worth a 🤦 ...

Before:

<string>:0:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltStylePreCompute: unknown xsl:foo
<string>:0:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltParseStylesheetTop: unknown foo element

After:

errtest.xml:3:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltStylePreCompute: unknown xsl:foo
errtest.xml:3:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltParseStylesheetTop: unknown foo element

We can't do better, as the second line in the two errors embellishes the first line and does not duplicate the file/line info.

Example:

from io import BytesIO
from lxml import etree
style = etree.parse("errtest.xml")
try:
    etree.XSLT(style)
except etree.XSLTParseError as e:
    print e.error_log

@lambdafu
Copy link
Contributor Author

Oh, here is the xslt:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:foo />
</xsl:stylesheet>

It's really the same from the test case that's already there (but which only checks for presence of ERROR:XSLT).

@scoder
Copy link
Member

scoder commented Sep 16, 2016

Ah, beautiful. Thanks!

@scoder scoder merged commit 9113dc1 into lxml:master Sep 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants