I have the following code to transform the xml file to html file.This is accessed by many threads.The transform method just appends the content every time.That is the first threads content is retained in all subsequent thread's html files.
public class CreateHTML
{
TransformerFactory tFactory;
Source xslDoc;
Source xmlDoc;
OutputStream htmlFile;
public CreateHTML(String xslDocFileName,String xmlDocFileName,String outputFileName) throws FileNotFoundException
{
xslDoc=new StreamSource(xslDocFileName);
xmlDoc=new StreamSource(xmlDocFileName);
htmlFile=new FileOutputStream(outputFileName);
}
public synchronized void createOutputFile() throws Exception
{
try
{
tFactory=TransformerFactory.newInstance();
tFactory.setAttribute("indent-number",new Integer(2));
Transformer transformer = tFactory.newTransformer(xslDoc);
transformer.setOutputProperty(OutputKeys.INDENT,"yes");
transformer.transform(xmlDoc, new StreamResult(htmlFile));
}
catch (TransformerException ex)
{
Logger.getLogger(CreateHTML.class.getName()).log(Level.SEVERE, null, ex);
throw ex;
}
}
}