The idea that xsl:message output should be sent to the MessageListener  
Sorry, read ErrorListener
 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:
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.


Michael Kay


From: Glenn Pearson []
Sent: 22 February 2010 21:26
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();


        // 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.transform(new StreamSource(p_xmlSource),



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