Use the transform.TransformerFactory plugability in the JAXP API
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class MainClass {
public static void main(String[] args) throws TransformerException,
TransformerConfigurationException, FileNotFoundException, IOException {
if (args.length != 3) {
System.out.println("Usage: java jaxpTransform inXML inXSLT outFile");
System.exit(0);
}
FileOutputStream outstream = new FileOutputStream(args[2]);
TransformerFactory tfactory = TransformerFactory.newInstance();
StreamSource insource = new StreamSource(args[0]);
StreamSource inxsl = new StreamSource(args[1]);
StreamResult sresult = new StreamResult(outstream);
Transformer transformer = tfactory.newTransformer(inxsl);
transformer.transform(insource, sresult);
}
}
Related examples in the same category