4 #include "TDocument.hh"
5 #include "CMathMLFactoryXSLT.hh"
6 #include "AMathMLConsumer.hh"
8 CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s)
9 : AMathMLFactory(l), style(s)
15 CMathMLFactoryXSLT::reset()
17 DOM::DOMImplementation di;
19 result = di.createDocument(MATHML_NS_URI, "m:math", dt);
23 CMathMLFactoryXSLT::documentModified(TDocument& doc)
25 if (TNode dirty = doc.dirtyNode())
27 std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
28 if (result.get_documentElement().hasAttribute("xref"))
29 dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
30 DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
31 DOM::Document res = style.apply(doc.document(), dirtyId);
33 style.save(doc.document(), stdout);
35 DOM::Element root = res.get_documentElement();
37 assert(root.hasAttribute("xref"));
39 if (result.get_documentElement().hasAttribute("xref"))
41 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
45 result.replaceChild(result.importNode(root, true), result.get_documentElement());
47 style.save(result, stdout);
54 CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
58 if (e1.getAttribute("xref") == id)
60 DOM::Node parent = e1.get_parentNode();
62 parent.replaceChild(e2, e1);
67 DOM::Node p = e1.get_firstChild();
70 while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
72 if (subst(p, id, e2)) return true;
73 else p = p.get_nextSibling();