]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc
* this is a large commit
[helm.git] / helm / DEVEL / mathml_editor / src / CMathMLFactoryXSLT.cc
index 244d3640b0f60fec1dc11d14cfa200d630b58366..2b714cb91f83d175f1757fb0c627a8f097d49c41 100644 (file)
@@ -5,42 +5,48 @@
 #include "CMathMLFactoryXSLT.hh"
 #include "AMathMLConsumer.hh"
 
+CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s)
+  : AMathMLFactory(l), style(s)
+{
+  reset();
+}
+
+void
+CMathMLFactoryXSLT::reset()
+{
+  DOM::DOMImplementation di;
+  DOM::DocumentType dt;
+  result = di.createDocument(MATHML_NS_URI, "m:math", dt);
+}
+
 void
 CMathMLFactoryXSLT::documentModified(TDocument& doc)
 {
   if (TNode dirty = doc.dirtyNode()) 
     {
       std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
-      if (result)
+      if (result.get_documentElement().hasAttribute("xref"))
        dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
                                         DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
       DOM::Document res = style.apply(doc.document(), dirtyId);
       assert(res);
-      //style.save(doc.document(), stdout);
-      //style.save(res, stdout);
-      if (result)
-       {
-         DOM::Element root = res.get_documentElement();
-         assert(root);
-         assert(root.hasAttribute("xref"));
+      style.save(doc.document(), stdout);
+
+      DOM::Element root = res.get_documentElement();
+      assert(root);
+      assert(root.hasAttribute("xref"));
 
-         try
-           {
-             bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
-             assert(ok);
-           }
-         catch (DOM::DOMException& e)
-           {
-             cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl;
-             assert(0);
-           }
+      if (result.get_documentElement().hasAttribute("xref"))
+       {
+         bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
+         assert(ok);
        }
       else
-       result = res;
+       result.replaceChild(result.importNode(root, true), result.get_documentElement());
+       
+      style.save(result, stdout);
 
       doc.clearDirty();
-
-      if (consumer) consumer->documentModified(result);
     }
 }