- 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");