lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] help with orphan-control in xsl-fo


From: Vadim Zeitlin
Subject: Re: [lmi] help with orphan-control in xsl-fo
Date: Wed, 20 Jul 2016 17:45:53 +0200

On Wed, 20 Jul 2016 14:30:08 +0000 Greg Chicares <address@hidden> wrote:

GC> But I see another anomaly: with current libxslt, xsltwrapp says only:
GC>   runtime error: file C:/opt/lmi/lmi-MID-20160729Z/reg_d_individual.xsl
GC>   line 598 element param
GC> without the extra line
GC>   Unexpected XSLT element 'param'
GC> that we see with xsltproc. That extra line is desirable; is there a way
GC> to have it included in the exception that libxslt throws?

 Libxslt does return the error to us, the trouble is that it actually
returns 6 of them (for 3 different errors) but xsltwrapp by default throws
an exception whenever the first one is processed, so the rest of them are
lost. In the light of this example, I do wonder if this is the right thing
to do and, in fact, I think it isn't and that xsltwrapp should throw an
exception with the combined error message by default -- and let people who
need individual errors define their own error handler classes.

 But luckily xsltwrapp is already flexible enough to let us do it ourselves
and with the following patch:
---------------------------------- >8 --------------------------------------
diff --git a/ledger_xml_io.cpp b/ledger_xml_io.cpp
index 60970e5..3124de4 100644
--- a/ledger_xml_io.cpp
+++ b/ledger_xml_io.cpp
@@ -1005,7 +1005,13 @@ void Ledger::write_xsl_fo(std::ostream& os) const
         scaled_ledger.write(d.root_node());
 
         xslt::stylesheet z(xsl_filepath(scaled_ledger).string().c_str());
-        os << z.apply(d.document());
+        xml::document result;
+        xml::error_messages errors;
+        if(!z.apply(d.document(), result, errors))
+            {
+            throw xml::exception(errors.print());
+            }
+        os << result;
         }
     catch(...)
         {
---------------------------------- >8 --------------------------------------

 I get a message box with more complete error information:

        ---------------------------
        Error
        ---------------------------
        error: runtime error: file reg_d_individual.xsl line 600 element param
        error: Unexpected XSLT element 'param'.
        error: runtime error: file reg_d_individual.xsl line 601 element param
        error: Unexpected XSLT element 'param'.
        error: runtime error: file reg_d_individual.xsl line 603 element if
        error: Variable 'displaycontractlanguage' has not been declared.
        ---------------------------
        OK   
        ---------------------------

 Notice that I had to switch to apply() overload taking "result" because
the overload taking a custom error handler but not the result document
currently crashes when the new document isn't created because of errors.
This is definitely a bug in xsltwrapp and I'll submit a fix for it, if
you're ready to update to the latest version of xsltwrapp including this
fix, the patch above could be even more minimal and so something like

        xml::error_messages errors;
        os << z.apply(d.document(), errors);
        if(errors.has_errors())
            {
            throw xml::exception(errors.print());
            }

but personally I don't think it's worth it as the code above is IMHO more
clear.

 Regards,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]