I know this should be something that has probably been discussed to death here but I beg your collective patience.  Question: How do I find the line number (and more details) of a thrown TransformerConfigurationException so I can get to the bottom of a "Failed to compile stylesheet. 1 error detected. " error?  Given...

            try {
                TransformerFactory factory = TransformerFactory.newInstance();

                ErrorListener factoryListener = new LoggingErrorListener();
                factory.setErrorListener(factoryListener);               
                factory.setAttribute(FeatureKeys.LINE_NUMBERING, Boolean.TRUE);

                sd = new File(path);
                x = factory.newTemplates(new StreamSource(sd));
                cache.put(path, x);
                cacheTS.put(path, Long.toString(sd.lastModified()));
            } catch( TransformerConfigurationException te ) {
                log.logActivity("ERROR","transform :: tryCache :: TransformerConfigurationException :: "+te.getMessageAndLocation());
            } catch( TransformerException te ) {
                log.logActivity("ERROR","transform :: tryCache :: TransformerException :: "+te.getMessageAndLocation());
            } // try..catch

I finally found out the bit where SAXON will not put line number in TransformerExceptions because there could be more than one - an ErrorListener can handle that.  So...

public class LoggingErrorListener implements ErrorListener {

    protected EventLog log = null;
 
    //-----------------------------------------------------------

    public void warning(TransformerException exception) {
        log.logActivity("WARN", "transform :: LoggingErrorListener :: "+exception.getMessage());
    } // method..warning

    //-----------------------------------------------------------

    public void error(TransformerException exception) throws TransformerException {
        log.logActivity("SEVERE", "transform :: LoggingErrorListener :: "+exception.getMessage());
        throw exception;
    } // method..error

  //-----------------------------------------------------------
 
    public void fatalError(TransformerException exception) throws TransformerException {
        log.logActivity("FATAL", "transform :: LoggingErrorListener :: "+exception.getMessage());
        throw exception;
    } // method..fatalError
    
    //-----------------------------------------------------------

    public void LoggingErrorListener() {
        PropertyContainer nmyProperties = new PropertyContainer();
        this.log = new EventLog(nmyProperties.configProperty("logPath"),nmyProperties.configProperty("logFilenamePrefix"));
    } // constructor..LoggingErrorListener

    //-----------------------------------------------------------

} // class..LoggingErrorListener

My LoggingErrorListener is made use of; a TransformerConfigurationException in my case does occur and the fatalError method is called.  However, NOW I have an exception occurring because of the exception.getMessage() call.

After numerous web searches and SourceForge searches, I am turning up not much for canned examples of how to do this.  I've also found that archived maillist messages at SourceForge appear to be slowly purged.  Messages with a subject line that hint at "this might be what I'm looking for!" aren't there anymore.

Is there anywhere on the web that gives a good example of using ErrorListeners for the benefit of getting details on compilation errors (line numbers and the like)?

I am using SAXON 8.5.1 under Java 1.5.
--

Jeffrey Schrab - Internet Application Developer
GS Design • 6665 N. Sidney Place • Milwaukee, WI 53209
P: 414.228.9666 • F: 414.228.9652 • E: jschrab@gsdesign.com