4 #include "TDocument.hh"
5 #include "CMathMLFactoryXSLT.hh"
6 #include "AMathMLConsumer.hh"
9 CMathMLFactoryXSLT::documentModified(TDocument& doc)
11 if (TNode dirty = doc.dirtyNode())
13 std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
15 dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
16 DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
17 DOM::Document res = style.apply(doc.document(), dirtyId);
19 //style.save(doc.document(), stdout);
20 //style.save(res, stdout);
23 DOM::Element root = res.get_documentElement();
25 assert(root.hasAttribute("xref"));
29 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
32 catch (DOM::DOMException& e)
34 cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl;
43 if (consumer) consumer->documentModified(result);
48 CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
52 if (e1.getAttribute("xref") == id)
54 DOM::Node parent = e1.get_parentNode();
56 parent.replaceChild(e2, e1);
61 DOM::Node p = e1.get_firstChild();
64 while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
66 if (subst(p, id, e2)) return true;
67 else p = p.get_nextSibling();