MessageWarner Problem
Added by Anonymous about 16 years ago
Legacy ID: #5243235 Legacy Poster: Jon Kenyon (jonkenyon)
Hello All. I am writing some Java code to use xsl to transform some xml files. I am using Java 1.5 and Saxon 9.1.0.1 Under certain circumstances, my XSLT will call <xsl:message terminate="yes">Invalid date</xsl:message> I have implemented an ErrorListener and set the MessageEmitter to a MessageWarner and this setup allows me to trap and retrieve the xsl:message contents and act accordingly. However, if circumstances dictate that the transform never calls <xsl:message>, then I get the following exception :- 2008-09-08 12:10:43,692 [Thread-0] ERROR (leTranslator) - IllegalStateException during parsing java.lang.IllegalStateException: Emitter must have either a Writer or a StreamResult to write to at net.sf.saxon.event.Emitter.makeWriter(Emitter.java:130) at net.sf.saxon.event.XMLEmitter.openDocument(XMLEmitter.java:120) at net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:257) at net.sf.saxon.Controller.transformDocument(Controller.java:1849) at net.sf.saxon.Controller.transform(Controller.java:1621) at com.dtint.webdatamigration.FileTranslator.process(FileTranslator.java:193) at com.dtint.webdatamigration.DirectoryProcessor.processFile(DirectoryProcessor.java:445) at com.dtint.webdatamigration.DirectoryProcessor.processDirectory(DirectoryProcessor.java:386) at com.dtint.webdatamigration.DirectoryProcessor.run(DirectoryProcessor.java:286) at java.lang.Thread.run(Thread.java:595) My workaround is to ensure that my xsl always calls <xsl:message> at least once, and it can be with terminate="no", but I'm concerned that either I'm setting up the ErrorListener and MessageEmitter incorrectly, or that I've found a bug. Here is the java that sets up the transform:- transformer.setErrorListener(new ErrorListener() { public void error(TransformerException exception) throws TransformerException { setLastMessage(exception.getMessage()); } public void fatalError(TransformerException exception) throws TransformerException { setLastMessage(exception.getMessage()); } public void warning(TransformerException exception) throws TransformerException { setLastMessage(exception.getMessage()); } }); ((Controller) transformer).setMessageEmitter(new MessageWarner()); transformer.transform(source, result); Anyone any ideas?
Replies (1)
RE: MessageWarner Problem - Added by Anonymous about 16 years ago
Legacy ID: #5243336 Legacy Poster: Michael Kay (mhkay)
Thanks for reporting this. As a workaround, please do MessageWarner mw = new MessageWarner(); mw.setWriter(new StringWriter()); ((Controller) transformer).setMessageEmitter(mw); Michael Kay Saxonica
Please register to reply