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)
11 DOM::DOMImplementation di;
13 result = di.createDocument(MATHML_NS_URI, "m:math", dt);
17 CMathMLFactoryXSLT::documentModified(TDocument& doc)
19 cout << "passo di qui" << endl;
20 std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
21 if (TNode dirty = doc.dirtyNode())
22 if (result.get_documentElement().hasAttribute("xref"))
23 dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
24 DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
25 DOM::Document res = style.apply(doc.document(), dirtyId);
27 style.save(doc.document(), stdout);
29 DOM::Element root = res.get_documentElement();
32 if (result.get_documentElement().hasAttribute("xref"))
34 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
38 result.replaceChild(result.importNode(root, true), result.get_documentElement());
40 style.save(result, stdout);
46 CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
50 if (e1.getAttribute("xref") == id)
52 DOM::Node parent = e1.get_parentNode();
54 parent.replaceChild(e2, e1);
59 DOM::Node p = e1.get_firstChild();
62 while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
64 if (subst(p, id, e2)) return true;
65 else p = p.get_nextSibling();