The following shows the sample program:
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.*;
public class SampleXSLT{
public static void main(String[] args){
try{
File file = new File(args[0]);
//read XML file
Source source = new StreamSource(file);
Result result = new StreamResult(System.out);
TransformerFactory factory =
TransformerFactory.newInstance();
//convert to HTML file
Source style = factory.getAssociatedStylesheet(source,
null, null, null);
Transformer transformer = factory.newTransformer(style);
transformer.transform(source, result);
}catch(TransformerConfigurationException e){
e.printStackTrace();
}catch(TransformerException e){
e.printStackTrace();
}
}
}