KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > UseStylesheetPI


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */

16 /*
17  * $Id: UseStylesheetPI.java,v 1.8 2004/02/17 19:09:59 minchau Exp $
18  */

19
20 import javax.xml.transform.Source JavaDoc;
21 import javax.xml.transform.Transformer JavaDoc;
22 import javax.xml.transform.TransformerConfigurationException JavaDoc;
23 import javax.xml.transform.TransformerException JavaDoc;
24 import javax.xml.transform.TransformerFactory JavaDoc;
25 import javax.xml.transform.stream.StreamResult JavaDoc;
26 import javax.xml.transform.stream.StreamSource JavaDoc;
27
28 public class UseStylesheetPI
29 {
30   public static void main(String JavaDoc[] args)
31       throws TransformerException JavaDoc, TransformerConfigurationException JavaDoc
32     {
33       String JavaDoc media= null , title = null, charset = null;
34       try
35       {
36         TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
37       Source JavaDoc stylesheet = tFactory.getAssociatedStylesheet
38         (new StreamSource JavaDoc("fooX.xml"),media, title, charset);
39       
40       Transformer JavaDoc transformer = tFactory.newTransformer(stylesheet);
41         
42            transformer.transform(new StreamSource JavaDoc("fooX.xml"),
43                              new StreamResult JavaDoc(new java.io.FileOutputStream JavaDoc("foo.out")));
44        
45       System.out.println("************* The result is in foo.out *************");
46        
47       }
48       catch (Exception JavaDoc e)
49       {
50         e.printStackTrace();
51       }
52   }
53 }
54
Popular Tags