1 /* Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
2 * 2003, Paolo Marinelli <pmarinel@cs.unibo.it>.
4 * This file is part of EdiTeX, an editor of mathematical
5 * expressions based on TeX syntax
7 * EdiTeX is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * EdiTeX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with EdiTeX; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * For details, see the EdiTeX World-Wide-Web page,
22 * http://helm.cs.unibo.it/editex, or send a mail to
23 * <luca.padovani@cs.unibo.it>
28 #include "TDocument.hh"
29 #include "CMathMLFactoryXSLT.hh"
30 #include "AMathMLConsumer.hh"
32 CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s)
33 : AMathMLFactory(l), style(s)
35 DOM::DOMImplementation di;
37 result = di.createDocument(MATHML_NS_URI, "m:math", dt);
41 CMathMLFactoryXSLT::documentModified(TDocument& doc)
43 std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
44 if (TNode dirty = doc.dirtyNode())
45 if (result.get_documentElement().hasAttribute("xref"))
46 dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
47 DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
48 DOM::Document res = style.apply(doc.document(), dirtyId);
50 style.save(doc.document(), stdout);
52 DOM::Element root = res.get_documentElement();
55 if (result.get_documentElement().hasAttribute("xref"))
57 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
61 result.replaceChild(result.importNode(root, true), result.get_documentElement());
63 style.save(result, stdout);
69 CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
73 if (e1.getAttribute("xref") == id)
75 DOM::Node parent = e1.get_parentNode();
77 parent.replaceChild(e2, e1);
82 DOM::Node p = e1.get_firstChild();
85 while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
87 if (subst(p, id, e2)) return true;
88 else p = p.get_nextSibling();