I'd like to have the Transformer treat warnings as Errors and throw an TransformerException with the contents of my xsl:message tag. Can the Transformer be configured to do this?
If an error occurs in my style sheet I have the following line
<xsl:message terminate="yes">My Error Message</xsl:message>
When I transform this an error message prints to Standard.err:
file:///foo/bar/style.xsl; Line 36; Column -1; My Error Message
My Java class catches a TransformerException
javax.xml.transform.TransformerException: Stylesheet directed termination. It does not seem to contain a root cause or exception with a message of "My Error Message" like I would expect.
I can write an ErrorListener that catches the warning. But I'm not sure how I stop processing and report this error to my code. Is there a standard way to do this?
void transform(Document document, File styleSheet, File outFile) throws TransformerException {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = null;
StreamSource styleSource = new StreamSource(styleSheet);
transformer = tFactory.newTransformer(styleSource);
JDOMSource in = new JDOMSource(document);
StreamResult result = new StreamResult(outFile);
transformer.transform(in, result);
}
