X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FCMathMLFactoryXSLT.cc;h=07eb4b3540e19ff1d9ffca835b273aabc46746a3;hb=b38de2d3fa8bbe346c59c18bbeb889f29e493f63;hp=efc672c024cff05b4290bd73348a66a5d21de4ea;hpb=c112706f347e08e7f345131fbc4c3aa0e9ecc7b5;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc index efc672c02..07eb4b354 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc @@ -25,9 +25,11 @@ #include "dom.hh" #include "TNode.hh" +#include "ALogger.hh" #include "TDocument.hh" #include "CMathMLFactoryXSLT.hh" #include "AMathMLConsumer.hh" +#include CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s) : AMathMLFactory(l), style(s) @@ -47,22 +49,33 @@ CMathMLFactoryXSLT::documentModified(TDocument& doc) DOM::GdomeString("'" + std::string(dirty["id"]) + "'"))); DOM::Document res = style.apply(doc.document(), dirtyId); assert(res); - style.save(doc.document(), stdout); + //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(); + //style.save(result, stdout); } bool