Here's a sketch of how to do it to help you get started, mostly untested, but based on importing the following sample XHTML:
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MathML in XHTML</title>
</head>
<body>
<p>
Follows:
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mn>1</mn>
<msqrt>
<mn>2</mn>
</msqrt>
</mfrac>
</math>
</p>
</body>
</html>
In XHTMLImporterImpl, at approx line 1383, add and flesh out the following block of code:
Using java Syntax Highlighting
} else if (e.
getNodeName().
equals("math")) {
// handle me
System.
out.
println("TODO: Handle mathml \n\r" + XmlUtils.
w3CDomNodeToString(e
) );
// Prepare to transform Element e
Templates xslt
= null; // your mathml2omml.xslt
// Use constructor which takes Unmarshaller, rather than JAXBContext,
// so we can set JaxbValidationEventHandler
JAXBContext jc
= Context.
jc;
Unmarshaller u
;
try {
u
= jc.
createUnmarshaller();
u.
setEventHandler(new org.
docx4j.
jaxb.
JaxbValidationEventHandler());
jakarta.
xml.
bind.
util.
JAXBResult result
= new jakarta.
xml.
bind.
util.
JAXBResult(u
);
XmlUtils.
transform(new DOMSource
(e
), xslt,
null, result
);
// What happened?
Object o
= result.
getResult();
// Attach it to the document
this.
contentContextStack.
peek().
getContent().
add(); // or addAll
} catch (JAXBException e1
) {
e1.
printStackTrace();
}
return;
Parsed in 0.017 seconds, using
GeSHi 1.0.8.4