aspose file tools*
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
Author

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="......">
<xsl:value-of
select="exception:throwException('Recording failed')"/>
</xsl:when>

Here exception is defined as:
xmlns:exception="http://..../util.exception.ValidationExceptionThrower"
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();
java.io.ByteArrayOutputStream outputXmlResult = new
java.io.ByteArrayOutputStream();
result.setOutputStream(outputXmlResult);
transformer.transform(xmlsource, result);
setOutXml(outputXmlResult.toString());


return "Success";

}

catch(ValidationException ex) {
System.out.println("INSIDE VALIDATIONEXCEPTION");
......
}
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: http://aspose.com/file-tools
 
subject: XSLT exception handling
 
Similar Threads
xml tags writing
Newbie Question---Help?
XML FILE TO CSV FILE
An Unwanted Part of the XML Input File is Included in the XSL Transformation Result
Converting an application using xstl from struts to struts 2