Project

Profile

Help

Support #2443

closed

xsl:message output

Added by Miguel Algorri over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
JAXP Java API
Sprint/Milestone:
-
Start date:
2015-08-21
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Hello,

A friend asked me for help to output the xsl:message on a transformation with saxon in java. After reading a lot of posts on the internet I thought i could make it work like this:

                                        // Fetch the source file's content and the template to transform with.
					Source xmlSource = new StreamSource(IBFDHelper.getInputStreamByNodeRef(contentService, source));
					Source xslSource = new StreamSource(xslt);

					// Open a writer to the file.
					ContentWriter docWriter = contentService.getWriter(target, ContentModel.PROP_CONTENT, true);
					docWriter.setMimetype(targetMimetype);
					OutputStream os = new BufferedOutputStream(docWriter.getContentOutputStream());
					Result xmlResult = new StreamResult(os);

					// Set-up the transformer.
					TransformerFactory fact = TransformerFactory.newInstance();
					fact.setURIResolver(uriResolver);
					Transformer transformer = fact.newTransformer(xslSource);
					transformer.setErrorListener(errorHandler);
					((net.sf.saxon.Controller)transformer).setMessageEmitter(new net.sf.saxon.serialize.MessageWarner());

                                        transformer.transform(xmlSource, xmlResult);

However, for some reason, when the code gets to the line "((net.sf.saxon.Controller)transformer).setMessageEmitter(new net.sf.saxon.serialize.MessageWarner());" it doesn't continue naturally, the next line of code that gets executed is the first line in the finally, it doesn't even execute the generic Exception catch.

The saxon version used is 9.1 if I'm not wrong.

Actions #1

Updated by Michael Kay over 8 years ago

Given that 9.1 is rather a long time ago, I don't think we're going to be able to offer much help on this without some kind of diagnostics. There must be an exception and the possibility of a stack trace.

Actions #2

Updated by Miguel Algorri over 8 years ago

That's exactly the problem I have. I'm trying to catch an Exception but It doesn't seem to catch anything. I've never seen anything like that before. Guess I will have to ask if I can update the API to a newer version although the system is quite old. Thanks!

Actions #3

Updated by Michael Kay over 8 years ago

If you are catching all Exceptions, that leaves the possibility that the code is failing with an Error (i.e. a Throwable that is not an Exception). I would normally expect to see a stack trace on that but I guess there are ways of suppressing it.

Actions #4

Updated by Miguel Algorri over 8 years ago

Alright, now I tried catching Throwable objects and this is what I got:

java.lang.NoClassDefFoundError: net/sf/saxon/serialize/MessageWarner

However it doesn't have a stack trace. The jar is in the classpath so that's not the reason why it appeared, any ideas?

Actions #5

Updated by Michael Kay over 8 years ago

This means that the version of Saxon on your classpath at run-time doesn't match the version that you compiled your application against. Specifically, it means that the class MessageWarner was there when you compiled the application, but is not there when you run it.

Actions #6

Updated by Miguel Algorri over 8 years ago

  • % Done changed from 0 to 100

That fixed it! Thanks so much Michael. I really appreciate the quick and useful responses.

Actions #7

Updated by Michael Kay over 8 years ago

  • Status changed from New to Closed

Please register to edit this issue

Also available in: Atom PDF