UPDATE: This post and this patch are no longer needed. A new version of XML::LibXSLT fixes the error reporting and some other issues. Below is the original post for purely historical reasons.
XML::LibXSLT is a perl module, written and maintaned by Matt Sergeant. The module provides access to the fine Gnome project’s XSLT library libxslt. XML::LibXSLT versions up to and including 1.58 have one serious deficiency though: they provide rudimentary reporting of XPath and XSLT processing errors.
This patch tries to fix this deficiency and makes XML::LibXSLT die in case of error with a full error message, often multiple lines. The generated message will be similar to the one xsltproc tool would produce.
Get the patch
Download: xml-libxslterror-reporting-patch.txt
A summary of the patch changes follows.
I figured some important errors, like invalid XPath expression errors were generated in libxml2 library and handled by XML::LibXML module. XML::LibXML module installs its own error handler for libxml2 errors and this handler croak()s immediatly in case of error. But that handling isn’t appropriate for LibXSLT, because we can’t really trap it. Or we can trap it, but in that case it is the libxslt library that should trap it and continue it’s processing (to construct a full error message), which it surely wouldn’t do.
So I suggest to temporarily set global xmlGenericErrorFunc variable to our own handler (but then reset it back after each transform or parsestyle operation).
Also in this patch I put LibXSLT_error_handler() function to use. The function was there already before me, but wasn’t used for some reason.
And, finally, I slightly change some wording in the error message phrases of XML::LibXSLT itself. (Remove that depressing Error applying stylesheet: (get error out of libxslt)
message…)
* * *
Work on this patch was sponsored by the BuildSite company.
Hi Ivan!
Do you have a working URL for the patch you’ve provided? :)
Thanks!
Thanks, William. Fixed now.