Saturday 30 July 2011

Set the TransformerFactory system property to generate and use translets

   


import java.io.FileOutputStream;
import java.util.Properties;

import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
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 argv[]) throws Exception {
    Properties props = System.getProperties();
    props.put("javax.xml.transform.TransformerFactory",
        "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
    System.setProperties(props);
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Templates translet = tFactory.newTemplates(new StreamSource(
        "OrderProcessing.xslt"));

    Transformer transformer = translet.newTransformer();
    
    transformer.transform(new StreamSource("CustomerOrders.xml"),
        new StreamResult(new FileOutputStream("SortedOrders.html")));
   
    transformer.transform(new StreamSource("CustomerOrders1.xml"),
        new StreamResult(new FileOutputStream("SortedOrders1.html")));
   
  }
}

   
    
  

No comments:

Post a Comment