Set the TransformerFactory system property to generate and use translets : Transform « XML « Java






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")));
   
  }
}

   
    
    
    
    
  








Related examples in the same category

1.XML transformation
2.A Program That Performs XML Transformations
3.XSLT I18N
4.Use the transform.TransformerFactory plugability in the JAXP API
5.Processing XML Documents Partially
6.Transforming DOM Node to HTML with JAXP
7.Transformer with parameters
8.Create an XML file and attach an XSL
9.Applying XSLT Stylesheets
10.Catch TransformerException
11.Formatting an XML file using Transformer
12.Transforming an XML File with XSL into a DOM Document
13.XML input, output and transform utilities
14.XSL transformations: It applies a transformation to a set of employee recordsXSL transformations: It applies a transformation to a set of employee records
15.How to write an XML file. It saves a file describing a modern drawing in SVG format.
16.Applies a stylesheet to a given xml document.
17.Applies a stylesheet (that receives parameters) to a given xml document.
18.Apply some indentiation to some XML.