Skip to main content

Tip: XSL transformations to and from a SAX stream

Integrate XSL transformations into your SAX applications

Return to article.


Listing 1. A TrAX transformation

import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;

public class TransformDOM extends Object {
   public static void main (String args[]) throws Exception
   {
    String XMLFileName = "mySource.xml";
    String OutputFileName = "myResult.xml";
    String StyleFileName = "myStyle.xsl";
         
    Source source = new StreamSource(XMLFileName);
    Result result = new StreamResult(OutputFileName);
    Source style = new StreamSource(StyleFileName);

    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer trans = transFactory.newTransformer(style);

    trans.transform(source, result);

   }
}

Return to article.