#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);
}
}