Java tutorial
//package com.java2s; import java.io.StringReader; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import org.w3c.dom.Node; public class Main { public static Node transform(String xslSource, Node original) { StringReader sr = new StringReader(xslSource); DOMResult result = new DOMResult(); doTransform(new StreamSource(sr), new DOMSource(original), result); return result.getNode(); } private static void doTransform(Source xslSource, Source xmlSource, Result xslResult) { try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(xslSource); transformer.transform(xmlSource, xslResult); } catch (TransformerFactoryConfigurationError ex) { throw new RuntimeException(ex); } catch (TransformerException ex) { throw new RuntimeException(ex); } } }