Meaningless Drivel is fun!
The moose likes XML and Related Technologies and the fly likes XSLT exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT exception handling" Watch "XSLT exception handling" New topic

XSLT exception handling

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
We test a particular constriant in our XSLT and throw a custom exception on failure:

<xsl:when test="......">
select="exception:throwException('Recording failed')"/>

Here exception is defined as:
The problem is that this kind of exception handling by-passes the java code.
In our Java client,we have the following:


TransformerFactory tFactory = TransformerFactory.newInstance();

transformer = tFactory.newTransformer(source);
StreamResult result = new StreamResult(); outputXmlResult = new;
transformer.transform(xmlsource, result);

return "Success";


catch(ValidationException ex) {
finally {
return "failure";


The exception thrown by XSLT does not get trapped by the error handler in the client.
How can XSLT be adapted to throw a 'catchable' exception.
I agree. Here's the link:
subject: XSLT exception handling
It's not a secret anymore!