packagetest;importjava.io.File;importjava.io.IOException;importjavax.xml.transform.Result;importjavax.xml.transform.Source;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerConfigurationException;importjavax.xml.transform.TransformerException;importjavax.xml.transform.TransformerFactory;importjavax.xml.transform.stream.StreamResult;importjavax.xml.transform.stream.StreamSource;importorg.junit.Test;public classTrain {
@Testpublic voidtest()throwsIOException {
String xmlFileName= "d:/test/xml.xml";
String xslFileName= "d:/test/xsl.xsl";
String htmlFileName= "d:/test/html.html";
Train.Transform(xmlFileName, xslFileName, htmlFileName);
}public static voidTransform(String xmlFileName, String xslFileName,
String htmlFileName) {try{
TransformerFactory tFac=TransformerFactory.newInstance();
Source xslSource= newStreamSource(xslFileName);
Transformer t=tFac.newTransformer(xslSource);
File xmlFile= newFile(xmlFileName);
File htmlFile= newFile(htmlFileName);
Source source= newStreamSource(xmlFile);
Result result= newStreamResult(htmlFile);
System.out.println(result.toString());
t.transform(source, result);
}catch(TransformerConfigurationException e) {
e.printStackTrace();
}catch(TransformerException e) {
e.printStackTrace();
}
}
}