Here you can find the source of xslString(final String xmlFile, final InputStream xslStream)
private static String xslString(final String xmlFile, final InputStream xslStream) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Main { private static String xslString(final String xmlFile, final InputStream xslStream) throws Exception { return xslString(xmlFile, new StreamSource(xslStream)); }/*from ww w .j ava 2 s.co m*/ private static String xslString(final String xml, final Source xslSource) throws Exception { TransformerFactory tFactory = TransformerFactory.newInstance(); // 2. Use the TransformerFactory to process the stylesheet Source and // generate a Transformer. Transformer transformer = tFactory.newTransformer(xslSource); // 3. Use the Transformer to transform an XML Source and send the // output to a Result object. StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8"))), sr); return sw.getBuffer().toString(); } }