2
* Copyright 2001-2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
* $Id: JAXPTransletMultipleTransformations.java,v 1.10 2004/02/17 19:13:22 minchau Exp $
19
import java.io.FileNotFoundException;
20
import java.io.FileOutputStream;
22
import java.util.Properties;
24
import javax.xml.transform.Templates;
25
import javax.xml.transform.Transformer;
26
import javax.xml.transform.TransformerException;
27
import javax.xml.transform.TransformerFactory;
28
import javax.xml.transform.stream.StreamResult;
29
import javax.xml.transform.stream.StreamSource;
33
* Using the TrAX/JAXP 1.1 interface to compile a translet and use it
34
* to perform multiple transformations. The translet implements
35
* the Templates interface. If you want to use the translet to perform a
36
* single transformation, see JAXPTransletOneTransformation.java.
39
* @author Donald Leslie
41
public class JAXPTransletMultipleTransformations
43
static void doTransform(Templates translet, String xmlInURI, String htmlOutURI)
44
throws TransformerException, FileNotFoundException
46
// For each transformation, instantiate a new Transformer, and perform
47
// the transformation from a StreamSource to a StreamResult;
48
Transformer transformer = translet.newTransformer();
49
transformer.transform( new StreamSource(xmlInURI),
50
new StreamResult(new FileOutputStream(htmlOutURI)));
53
public static void main(String argv[])
55
// Set the TransformerFactory system property to generate and use translets.
56
// Note: To make this sample more flexible, load properties from a properties file.
57
// The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
58
String key = "javax.xml.transform.TransformerFactory";
59
String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
60
Properties props = System.getProperties();
61
props.put(key, value);
63
System.setProperties(props);
65
String xslInURI = "todo.xsl";
69
// Instantiate the TransformerFactory, and use it along with a SteamSource
70
// XSL stylesheet to create a translet as a Templates object.
71
TransformerFactory tFactory = TransformerFactory.newInstance();
72
Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
74
// Perform each transformation
75
doTransform(translet, "todo.xml", "todo.html");
76
System.out.println("Produced todo.html");
78
doTransform(translet, "todotoo.xml", "todotoo.html");
79
System.out.println("Produced todotoo.html");
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: JAXPTransletMultipleTransformations.java 470245 2006-11-02 06:34:33Z minchau $
21
import java.io.FileNotFoundException;
22
import java.io.FileOutputStream;
24
import java.util.Properties;
26
import javax.xml.transform.Templates;
27
import javax.xml.transform.Transformer;
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;
35
* Using the TrAX/JAXP 1.1 interface to compile a translet and use it
36
* to perform multiple transformations. The translet implements
37
* the Templates interface. If you want to use the translet to perform a
38
* single transformation, see JAXPTransletOneTransformation.java.
41
* @author Donald Leslie
43
public class JAXPTransletMultipleTransformations
45
static void doTransform(Templates translet, String xmlInURI, String htmlOutURI)
46
throws TransformerException, FileNotFoundException
48
// For each transformation, instantiate a new Transformer, and perform
49
// the transformation from a StreamSource to a StreamResult;
50
Transformer transformer = translet.newTransformer();
51
transformer.transform( new StreamSource(xmlInURI),
52
new StreamResult(new FileOutputStream(htmlOutURI)));
55
public static void main(String argv[])
57
// Set the TransformerFactory system property to generate and use translets.
58
// Note: To make this sample more flexible, load properties from a properties file.
59
// The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
60
String key = "javax.xml.transform.TransformerFactory";
61
String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
62
Properties props = System.getProperties();
63
props.put(key, value);
65
System.setProperties(props);
67
String xslInURI = "todo.xsl";
71
// Instantiate the TransformerFactory, and use it along with a SteamSource
72
// XSL stylesheet to create a translet as a Templates object.
73
TransformerFactory tFactory = TransformerFactory.newInstance();
74
Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
76
// Perform each transformation
77
doTransform(translet, "todo.xml", "todo.html");
78
System.out.println("Produced todo.html");
80
doTransform(translet, "todotoo.xml", "todotoo.html");
81
System.out.println("Produced todotoo.html");