Side bar Listing. DoTransform sample class
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class DoTransform {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage : java DoTransform (xsl filename) (xml filename)");
return;
}
// Create a transformer factory instance.
TransformerFactory tfactory = TransformerFactory.newInstance();
// Create a transformer for the style sheet.
Transformer transformer = tfactory.newTransformer(new StreamSource(args[0]));
// Transform the source XML to System.out.
transformer.transform( new StreamSource(args[1]), new StreamResult(System.out));
}
}
|