aspose file tools
The moose likes XML and Related Technologies and the fly likes Error transforming using TransformerHandler 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 "Error transforming using TransformerHandler" Watch "Error transforming using TransformerHandler" New topic

Error transforming using TransformerHandler

Sankar Tanguturi

Joined: Feb 18, 2003
Posts: 17

I am not sure if this is the right forum. But since my problem involves using TransformerHandlers, I am posting it here.
I am trying to port a web application that from Oracle9iAS to Websphere 5.0. I am getting a problem on Websphere, when I try to get a TransformerHandler from TransformerFactory and using TransformerHandler as a ContentHandler to fire SAX events. The transformation does not happen and I get an empty XML declaration in the output. I verified that if I do not specify the templates while getting the TransformerHandler, it is doing an identity transformation correctly. Also there are templates within my XSL to handle the XML tags.
Here is the outline of my code :
if( templates == null )
templates = TransformerFactory.newInstanc().newTemplates
(new StreamSource(new File("xml_to_fo.xsl")));
TransformerHandler hd = tf.newTransformerHandler
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty( OutputKeys.INDENT,"no" );
hd.setResult( new StreamResult(new File(OUTPUT_FILENAME) );
..... // Code to add XML nodes to the document
I tried 2 different approaches to troubleshoot this:
1) On Oracle9IAS I was using an older version on xalan. I thought that the problem may due to a bug in the xalan that ships with Websphere. So I changed the Application class loading mode to 'Parent Last' from 'Parent First' so that Websphere would pick my version of the xalan classes(under web-inf/classes/lib). That did not help. In both cases, when I printed the loader info, I got as class loader and sun.misc.Launcher$AppClassLoader@55021395 as parent loader.
2) Next I wrote a stand alone java program to test the transformation process with the xalan.jar version from websphere and the version I had from Oracle9iAS. I found that with both versions of the jar, transformation happened correctly. I think this probably means that there is something wrong in the Websphere environment that is causing the problem. The stand alone program code is shown below :
TransformerFactory tf = TransformerFactory.newInstance();
Templates templates = tf.newTemplates(new StreamSource("xml_to_fo.xsl"));
TransformerHandler hd = ((SAXTransformerFactory)tf).newTransformerHandler
(templates );
Transformer transformer = hd.getTransformer();
transformer.transform(new StreamSource(new File("source.xml")), new StreamResult(System.out));
Any help in fixing the problem is appreciated.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12889
You don't show any exception handling - are you sure that none are being thrown? For instance by the transform() call?
Sankar Tanguturi

Joined: Feb 18, 2003
Posts: 17
I did not show the exception handling, but it exists . What I showed is an extract from a larger program.
I agree. Here's the link:
subject: Error transforming using TransformerHandler