#include "dom.hh"
#include "TNode.hh"
+#include "ALogger.hh"
#include "TDocument.hh"
#include "CMathMLFactoryXSLT.hh"
#include "AMathMLConsumer.hh"
+#include <cassert>
CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s)
: AMathMLFactory(l), style(s)
DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
DOM::Document res = style.apply(doc.document(), dirtyId);
assert(res);
- style.save(doc.document(), stdout);
+ //style.save(doc.document(), stdout);
- DOM::Element root = res.get_documentElement();
- assert(root);
-
- if (result.get_documentElement().hasAttribute("xref"))
- {
- bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
- assert(ok);
+ if (DOM::Element root = res.get_documentElement())
+ {
+ if (result.get_documentElement().hasAttribute("xref"))
+ {
+ bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
+ assert(ok);
+ doc.clearDirty();
+ }
+ else
+ result.replaceChild(result.importNode(root, true), result.get_documentElement());
+ }
+ else
+ {
+ // Something wrong happened while applying the stylesheet.
+ DOM::Element root = result.get_documentElement();
+ DOM::Node p = root.get_firstChild();
+ while (p) {
+ DOM::Node next = p.get_nextSibling();
+ root.removeChild(p);
+ p = next;
+ }
+ logger.error("The stylesheet produced an empty document");
}
- else
- result.replaceChild(result.importNode(root, true), result.get_documentElement());
-
- style.save(result, stdout);
- doc.clearDirty();
+ //style.save(result, stdout);
}
bool