5 #include "TDocument.hh"
6 #include "CMathMLFactoryXSLTDiff.hh"
7 #include "AMathMLConsumer.hh"
9 CMathMLFactoryXSLTDiff::CMathMLFactoryXSLTDiff(ALogger& l, const DOMX::XSLTStylesheet& s)
10 : AMathMLFactory(l), style(s)
16 CMathMLFactoryXSLTDiff::reset()
18 DOM::DOMImplementation di;
20 result = di.createDocument(MATHML_NS_URI, "m:math", dt);
24 CMathMLFactoryXSLTDiff::documentModified(TDocument& doc)
26 if (TNode dirty = doc.dirtyNode())
28 std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
29 if (false && result.get_documentElement().hasAttribute("xref"))
30 dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
31 DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
32 DOM::Document res = style.apply(doc.document(), dirtyId);
34 //cout << "*** THE DIRTY FRAGMENT HAS ID = " << std::string(dirty["id"]) << endl;
35 //style.save(doc.document(), stdout);
36 cout << "*** THE CURRENT DOCUMENT:" << endl;
37 if (result) style.save(result, stdout);
38 cout << "*** THE NEW DOCUMENT:" << endl;
39 style.save(res, stdout);
40 cout << "*** THE DIFF:" << endl;
41 DOMX::Diff diff = DOMX::Diff::diff(result, res);
42 style.save(diff.document(), stdout);
45 DOM::Element root = res.get_documentElement();
47 assert(root.hasAttribute("xref"));
48 if (result.get_documentElement().hasAttribute("xref"))
50 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
56 //style.save(result, stdout);
63 CMathMLFactoryXSLTDiff::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
67 if (e1.getAttribute("xref") == id)
69 DOMX::Diff diff = DOMX::Diff::diff(e1, e2);
70 style.save(diff.document(), stdout);
76 DOM::Node p = e1.get_firstChild();
79 while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
81 if (subst(p, id, e2)) return true;
82 else p = p.get_nextSibling();