]> matita.cs.unibo.it Git - helm.git/commitdiff
When the stylesheet from TML to MathML generated a document without a root
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Mon, 28 Apr 2003 17:16:46 +0000 (17:16 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Mon, 28 Apr 2003 17:16:46 +0000 (17:16 +0000)
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).

helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc

index efc672c024cff05b4290bd73348a66a5d21de4ea..e5cac369f890060c31ef8ac4dcfab6cff30f3282 100644 (file)
@@ -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