1 16 19 import java.io.FileNotFoundException ; 20 import java.io.FileOutputStream ; 21 22 import java.util.Properties ; 23 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 ; 30 31 32 41 public class JAXPTransletMultipleTransformations 42 { 43 static void doTransform(Templates translet, String xmlInURI, String htmlOutURI) 44 throws TransformerException , FileNotFoundException 45 { 46 Transformer transformer = translet.newTransformer(); 49 transformer.transform( new StreamSource (xmlInURI), 50 new StreamResult (new FileOutputStream (htmlOutURI))); 51 } 52 53 public static void main(String argv[]) 54 { 55 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); 62 63 System.setProperties(props); 64 65 String xslInURI = "todo.xsl"; 66 67 try 68 { 69 TransformerFactory tFactory = TransformerFactory.newInstance(); 72 Templates translet = tFactory.newTemplates(new StreamSource (xslInURI)); 73 74 doTransform(translet, "todo.xml", "todo.html"); 76 System.out.println("Produced todo.html"); 77 78 doTransform(translet, "todotoo.xml", "todotoo.html"); 79 System.out.println("Produced todotoo.html"); 80 } 81 catch (Exception e) 82 { 83 e.printStackTrace(); 84 } 85 } 86 } 87 | Popular Tags |