Java tutorial
//package com.java2s; import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.io.*; public class Main { public static String transform(String xmlString, String stylesheetPathname) throws Exception { try { TransformerFactory factory = TransformerFactory.newInstance(); Source stylesheetSource = new StreamSource(new File(stylesheetPathname).getAbsoluteFile()); Transformer transformer = factory.newTransformer(stylesheetSource); Source inputSource = new StreamSource(new StringReader(xmlString)); Writer outputWriter = new StringWriter(); Result outputResult = new StreamResult(outputWriter); transformer.transform(inputSource, outputResult); return outputWriter.toString(); } catch (TransformerConfigurationException tce) { throw new Exception(tce.getMessageAndLocation()); } catch (TransformerException te) { throw new Exception(te.getMessageAndLocation()); } } }