Java tutorial
//package com.java2s; import java.io.File; import java.io.StringReader; import java.io.StringWriter; 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 { public static String transformString(String xmlString, String xsltFilePath) throws Exception { StreamResult result = new StreamResult(new StringWriter()); StreamSource s = new StreamSource(new File(xsltFilePath)); StreamSource xml = new StreamSource(new StringReader(xmlString)); Transformer transformer = TransformerFactory.newInstance().newTransformer(s); transformer.transform(xml, result); String response = result.getWriter().toString(); return response; } public static String transform(String xmlFilePath, String xsltFilePath) throws Exception { StreamResult result = new StreamResult(new StringWriter()); StreamSource s = new StreamSource(new File(xsltFilePath)); StreamSource xml = new StreamSource(new File(xmlFilePath)); Transformer transformer = TransformerFactory.newInstance().newTransformer(s); transformer.transform(xml, result); String response = result.getWriter().toString(); return response; } }