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: JAXPTransletOneTransformation.java,v 1.2 2009/12/10 03:18:41 matthewoliver Exp $
21
import java.io.FileNotFoundException;
22
import java.io.FileOutputStream;
23
import java.io.IOException;
25
import java.util.Properties;
27
import javax.xml.parsers.ParserConfigurationException;
28
import javax.xml.transform.Transformer;
29
import javax.xml.transform.TransformerConfigurationException;
30
import javax.xml.transform.TransformerException;
31
import javax.xml.transform.TransformerFactory;
32
import javax.xml.transform.stream.StreamResult;
33
import javax.xml.transform.stream.StreamSource;
35
import org.xml.sax.SAXException;
39
* Using the TrAX/JAXP 1.1 interface to compile and run a translet. The translet
40
* extends the abstract Transformer class and is used to perform a single
41
* transformation. If you want to use the translet to perform multiple
42
* transformations, see JAXPTransletMultipleTransformations.java.
44
* @author Donald Leslie
46
public class JAXPTransletOneTransformation
48
public static void main(String argv[])
49
throws TransformerException, TransformerConfigurationException, IOException, SAXException,
50
ParserConfigurationException, FileNotFoundException
52
// Set the TransformerFactory system property to generate and use a translet.
53
// Note: To make this sample more flexible, load properties from a properties file.
54
// The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
55
String key = "javax.xml.transform.TransformerFactory";
56
String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
57
Properties props = System.getProperties();
58
props.put(key, value);
59
System.setProperties(props);
61
String xslInURI = "todo.xsl";
62
String xmlInURI = "todo.xml";
63
String htmlOutURI = "todo.html";
66
// Instantiate the TransformerFactory, and use it along with a SteamSource
67
// XSL stylesheet to create a Transformer.
68
TransformerFactory tFactory = TransformerFactory.newInstance();
69
Transformer transformer = tFactory.newTransformer(new StreamSource(xslInURI));
70
// Perform the transformation from a StreamSource to a StreamResult;
71
transformer.transform(new StreamSource(xmlInURI),
72
new StreamResult(new FileOutputStream(htmlOutURI)));
73
System.out.println("Produced todo.html");
77
System.out.println(e.toString());