From 5a369548a2f04fb59b5cbb94526325aae9bf415a Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Mon, 28 Apr 2003 17:16:46 +0000 Subject: [PATCH] When the stylesheet from TML to MathML generated a document without a root an assertion failed. The new implementation creates an empty document (with only a m:math root element) and prints an error message (using the logger). --- .../mathml_editor/src/CMathMLFactoryXSLT.cc | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc index efc672c02..e5cac369f 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc @@ -25,6 +25,7 @@ #include "dom.hh" #include "TNode.hh" +#include "ALogger.hh" #include "TDocument.hh" #include "CMathMLFactoryXSLT.hh" #include "AMathMLConsumer.hh" @@ -49,20 +50,31 @@ CMathMLFactoryXSLT::documentModified(TDocument& doc) assert(res); style.save(doc.document(), stdout); - DOM::Element root = res.get_documentElement(); - assert(root); - - if (result.get_documentElement().hasAttribute("xref")) - { - bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); - assert(ok); + if (DOM::Element root = res.get_documentElement()) + { + if (result.get_documentElement().hasAttribute("xref")) + { + bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); + assert(ok); + doc.clearDirty(); + } + else + result.replaceChild(result.importNode(root, true), result.get_documentElement()); + } + else + { + // Something wrong happened while applying the stylesheet. + DOM::Element root = result.get_documentElement(); + DOM::Node p = root.get_firstChild(); + while (p) { + DOM::Node next = p.get_nextSibling(); + root.removeChild(p); + p = next; + } + logger.error("The stylesheet produced an empty document"); } - else - result.replaceChild(result.importNode(root, true), result.get_documentElement()); style.save(result, stdout); - - doc.clearDirty(); } bool -- 2.39.2