I'm using the Xalan SimpleTransform servlet to transform an XML file
into another XML file. It appears to be working as far as creating the
new file, but all it writes is the header data. The rest is blank and
the file appears to be open because I can't delete it without restarting
JRun.
I'm using Xalan 2.1.0 and the SimpleTransform code is below. We
modified it slightly so we could call it from another servlet.
// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
// Imported java classes
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Use the TraX interface to perform a transformation in the simplest
manner possible
* (3 statements).
*/
public class SimpleTransform2
{
public static void main(String args[])
{
}
public void transform(String xmlFile, String xslFile, String outFile)
throws TransformerException, TransformerConfigurationException,
FileNotFoundException, IOException
{
System.out.println("Entering transform");
// Use the static TransformerFactory.newInstance() method to
instantiate
// a TransformerFactory. The javax.xml.transform.TransformerFactory
// system property setting determines the actual class to instantiate
--
// org.apache.xalan.transformer.TransformerImpl.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Use the TransformerFactory to instantiate a Transformer that will
work with
// the stylesheet you specify. This method call also processes the
stylesheet
// into a compiled Templates object.
Transformer transformer = tFactory.newTransformer(new
StreamSource(xslFile));
// Use the Transformer to apply the associated Templates object to an
XML document
// (foo.xml) and write the output to a file (foo.out).
transformer.transform(new StreamSource(xmlFile), new StreamResult(new
FileOutputStream(outFile)));
//System.out.println("************* The result is in " + outFile +
"*************");
}
}
This is all that prints out:
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET xmlns:fo="http://www.w3.org/1999/XSL/Format"/>
I'd appreciate any suggestions of what else I can try to fix this.
Thank you.
Karen Fox
The MITRE Corporation
[EMAIL PROTECTED]begin:vcard
n:Fox;Karen
tel;fax:719-572-8477
tel;work:719-572-8368
x-mozilla-html:FALSE
org:The MITRE Corporation;D540
adr:;;1150 Academy Park Loop, Suite 212;Colorado Springs;CO;80910;US
version:2.1
email;internet:[EMAIL PROTECTED]
title:Technical Project Asst III
fn:Karen Fox
end:vcard
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]