Skip to main content

Customizing the Error Handling

Customizing the Error Handling

When an error occurs, either XSLT processor (Xalan or Saxon) executes the error() method of the current error handler, sending a message as an argument to that method. Similarly, when a fatal error or warning occurs, the XSLT processor executes the fatalError() or warning() method, as appropriate.

For all three of these methods, the default behavior is to write the message to the current device.

To customize the error handling, you do the following:

  1. For either the Xalan or the Saxon processor, create a subclass of %XML.XSLT.ErrorHandlerOpens in a new tab. In this subclass, implement the error(), fatalError(), and warning() methods as needed.

    Each of these methods accepts a single argument, a string that contains the message sent by the XSLT processor.

    These methods do not return values.

  2. Then:

    • To use this error handler when compiling a stylesheet, create an instance of your subclass and use it in the argument list when you compile the stylesheet. See Creating a Compiled Stylesheet.

    • To use this error handler when performing an XSLT transform, create an instance of your subclass and use it in the argument list of the transform method you use. See Performing an XSLT Transform.

FeedbackOpens in a new tab