Java tutorial
//package com.java2s; /* * * * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement. * Contributors retain copyright to elements licensed under a Contributor Agreement. * Licensed to the User under the LGPL license. * * $ */ import java.io.Reader; import java.io.Writer; import java.util.Iterator; import java.util.Map; 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 void style(Reader xsl, Reader xml, Writer out, Map params) throws TransformerException { Source xmlSource = new javax.xml.transform.stream.StreamSource(xml); TransformerFactory factory = TransformerFactory.newInstance(); Source xslSource = new javax.xml.transform.stream.StreamSource(xsl); Transformer transformer; transformer = factory.newTransformer(xslSource); if (params != null && !params.isEmpty()) { Iterator entries = params.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); transformer.setParameter((String) entry.getKey(), entry.getValue()); } } StreamResult result = new StreamResult(out); transformer.transform(xmlSource, result); } }