2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: SimpleTransform.java,v 1.2 2009/12/10 03:18:50 matthewoliver Exp $
22
import java.io.FileNotFoundException;
23
import java.io.FileOutputStream;
24
import java.io.IOException;
26
import javax.xml.transform.Transformer;
27
import javax.xml.transform.TransformerConfigurationException;
28
import javax.xml.transform.TransformerException;
29
import javax.xml.transform.TransformerFactory;
30
import javax.xml.transform.stream.StreamResult;
31
import javax.xml.transform.stream.StreamSource;
34
* Use the TraX interface to perform a transformation in the simplest manner possible
37
public class SimpleTransform
39
public static void main(String[] args)
40
throws TransformerException, TransformerConfigurationException,
41
FileNotFoundException, IOException
43
// Use the static TransformerFactory.newInstance() method to instantiate
44
// a TransformerFactory. The javax.xml.transform.TransformerFactory
45
// system property setting determines the actual class to instantiate --
46
// org.apache.xalan.transformer.TransformerImpl.
47
TransformerFactory tFactory = TransformerFactory.newInstance();
49
// Use the TransformerFactory to instantiate a Transformer that will work with
50
// the stylesheet you specify. This method call also processes the stylesheet
51
// into a compiled Templates object.
52
Transformer transformer = tFactory.newTransformer(new StreamSource("birds.xsl"));
54
// Use the Transformer to apply the associated Templates object to an XML document
55
// (foo.xml) and write the output to a file (foo.out).
56
transformer.transform(new StreamSource("birds.xml"), new StreamResult(new FileOutputStream("birds.out")));
58
System.out.println("************* The result is in birds.out *************");