The idea that xsl:message output should be sent to the MessageListener was something that was introduced to JAXP at a rather late stage (one of many regrettable occasions where the spec was changed unilaterally to match the Xalan implementation), and I decided not to implement this change as a default behaviour, because it would have been disruptive to existing applications.
 
In Saxon, xsl:message output is directed to a Receiver, which you can nominate to the Transformer:
 
((net.sf.saxon.Controller)transformer).setMessageEmitter(....)
 
If you want to follow the JAXP model of sending the output to the ErrorListener, you can nominate a Receiver that does this:
 
((net.sf.saxon.Controller)transformer).setMessageEmitter(new net.sf.saxon.event.MessageWarner())
 
However, for your purposes, I would suggest writing your own Receiver (you can use the code of MessageWarner as a template) that writes the message directly to your logging service rather than going via the ErrorListener. That way messages won't be confused with real errors.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

 


From: Glenn Pearson [mailto:gpearson@documite.com]
Sent: 22 February 2010 21:26
To: saxon-help@lists.sourceforge.net
Subject: [saxon] cannot get ErrorListener to work

I’m trying to get messages (xsl:message output), along with any XSLT errors, to get redirected to a logger instead of going to stdout or stderr.  I’ve created an ErrorListener and set it, but nothing seems to work.  Here’s a code snippet that I’m using.  My ErrorListener (CPAMessageListener) class is simple and straightforward, and works fine when tested alone.

 

        CPAMessageListener listen = new CPAMessageListener();

        ErrorListener newListen;

        // Create a transform factory instance.

        TransformerFactory tfactory = TransformerFactory.newInstance();

        tfactory.setErrorListener(listen);

        // Create a transformer for the stylesheet.

        Transformer transformer =

            tfactory.newTransformer(new StreamSource(p_xsltStylesheet));

        // Create the output stream

        StreamResult outResult = new StreamResult(p_xmlOutput);

        // Transform the source XML to System.out.

        transformer.setErrorListener(listen);

        transformer.transform(new StreamSource(p_xmlSource),

                              outResult);

 

My CPAMessageListener class implements the ErrorListener methods and nothing more.  It’s methods (warning, error and fatalError) never get called during the transform.

 

Any ideas what I’m doing wrong?

--- Glenn Pearson