This snippet of code shows how to do an XSL transform with Java

private static final String ERR_XSL_CONFIGURATION = "Error during XSL Transform configuration.";
private static final String ERR_XSL_TRANSFORM = "Error during XSL Transform execution.";

/** XSL Transform with input, output and parameters. */
@SuppressWarnings("unchecked")
public static void transform(Source xml, Source xsl, Result out, HashMap< String, ? > params){

    // factory init
    TransformerFactory factory = TransformerFactory.newInstance();

    // Transformer object init
    Transformer t;
    try {
        t = factory.newTransformer(xsl);
    } catch (TransformerConfigurationException e) {
        // if any XSL error
        throw new RuntimeException( ERR_XSL_CONFIGURATION, e );
    }

    // insert parameters (if any)
    if( params != null && params.size() > 0 ){
        Iterator< ? > i = params.entrySet().iterator();
        Entry< String, ? > me ;
        while(i.hasNext()){
            me = (Entry< String, ? >) i.next();
            t.setParameter(me.getKey(), me.getValue());
        }
    }

    // Transformation execution
    try {
        t.transform(xml, out);
    } catch (TransformerException e) {
        // if any Transformation error
        throw new RuntimeException( ERR_XSL_TRANSFORM, e );
    }
}