1 14 15 package webEditor.util; 16 17 import java.io.*; 18 import org.w3c.dom.*; 19 import org.xml.sax.SAXException ; 20 import org.apache.xalan.xslt.XSLTProcessorFactory; 21 import org.apache.xalan.xslt.XSLTInputSource; 22 import org.apache.xalan.xslt.XSLTResultTarget; 23 import org.apache.xalan.xslt.XSLTProcessor; 24 25 26 31 public class xsl_transform 32 { 33 public xsl_transform () 34 { 35 } 36 37 45 public String process (String input, String templateName) 46 throws java.io.IOException , 47 java.net.MalformedURLException 48 49 { 50 StringReader readerInput = new StringReader (input); 51 XSLTInputSource XSLinput = new XSLTInputSource (readerInput); 52 53 StringWriter outBuffer = new StringWriter(); 54 XSLTResultTarget XSLoutput = new XSLTResultTarget(outBuffer); 55 try { 56 XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); 57 processor.process(XSLinput, new XSLTInputSource(templateName), 58 XSLoutput); 59 } catch (Exception e) { 60 e.printStackTrace(); 61 } 62 String result = XSLoutput.getCharacterStream().toString(); 63 return (result); 65 } 66 67 74 public String processDOM (Document input, String templateName) 75 throws java.io.IOException , 76 java.net.MalformedURLException 77 78 { 79 XSLTInputSource XSLinput = new XSLTInputSource (input); 80 81 StringWriter outBuffer = new StringWriter(); 82 XSLTResultTarget XSLoutput = new XSLTResultTarget(outBuffer); 83 try { 84 XSLTProcessor processor = XSLTProcessorFactory.getProcessor 86 (new org.apache.xalan.xpath.xdom.XercesLiaison()); 87 88 processor.process(XSLinput, new XSLTInputSource(templateName), 89 XSLoutput); 90 } catch (Exception e) { 91 e.printStackTrace(); 92 } 93 String result = XSLoutput.getCharacterStream().toString(); 94 return (result); 95 } 96 97 } 98 | Popular Tags |