Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error transforming using TransformerHandler

 
Sankar Tanguturi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
(templates);
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty( OutputKeys.INDENT,"no" );
hd.setResult( new StreamResult(new File(OUTPUT_FILENAME) );
hd.startDocument();
..... // Code to add XML nodes to the document
hd.endDocument();
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 com.ibm.ws.bootstrap.ExtClassLoader@56fd9395 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.
Thanks,
Sankar
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't show any exception handling - are you sure that none are being thrown? For instance by the transform() call?
Bill
 
Sankar Tanguturi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not show the exception handling, but it exists . What I showed is an extract from a larger program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic