Here you can find the source of transform(final Source xml, final Source xslt, final Map params, final Writer err)
public static String transform(final Source xml, final Source xslt, final Map params, final Writer err) throws TransformerException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; public class Main { public static String transform(final Source xml, final Source xslt, final Map params, final Writer err) throws TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); factory.setErrorListener(new ErrorListener() { public void warning(final TransformerException e) throws TransformerException { append(e.getMessageAndLocation()); }/* ww w. j av a 2 s. co m*/ public void error(final TransformerException e) throws TransformerException { append(e.getMessageAndLocation()); } public void fatalError(final TransformerException e) throws TransformerException { append(e.getMessageAndLocation()); } private void append(final String msg) { if (err != null) { try { err.append(msg + "\n"); } catch (IOException e) { e.printStackTrace(); } } } }); Transformer transform = factory.newTransformer(xslt); if (params != null) { for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) { Entry param = (Entry) iter.next(); transform.setParameter((String) param.getKey(), param.getValue()); } } StreamResult result = new StreamResult(new StringWriter()); transform.transform(xml, result); return result.getWriter().toString(); } }