1 package com.flexiblewebsolutions.xml.util; 2 3 import java.io.BufferedOutputStream; 4 import java.io.File; 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream; 7 8 import javax.xml.transform.Transformer; 9 import javax.xml.transform.TransformerException; 10 import javax.xml.transform.stream.StreamResult; 11 import javax.xml.transform.stream.StreamSource; 12 13 /*** 14 * Utilities for using XSL to transform XML into HTML. 15 * 16 * @author Donavon Buss 17 * 18 */ 19 public class XSLUtils 20 { 21 /*** 22 * Convert an xml file to html using XSL. 23 * 24 * @param pXSL Transformer which contains XSL information 25 * @param pXMLPath - Path to xml file to be parsed 26 * @param pOutFile - Destination location for output file 27 */ 28 public void transform( Transformer pXSL, String pXMLPath, File pOutFile ) 29 { 30 31 BufferedOutputStream buffWrite = null; 32 33 try 34 { 35 buffWrite = new BufferedOutputStream( new FileOutputStream( 36 pOutFile ) ); 37 pXSL.transform( new StreamSource( new File( pXMLPath ) ), 38 new StreamResult( buffWrite ) ); 39 } 40 catch( FileNotFoundException e ) 41 { 42 e.printStackTrace(); 43 } 44 catch( TransformerException e ) 45 { 46 e.printStackTrace(); 47 } 48 finally 49 { 50 try 51 { 52 buffWrite.close(); 53 } 54 catch( Exception e ) 55 { 56 57 } 58 } 59 } 60 }