public static synchronized void applyTransformation(InputStream srcIs,
OutputStream destOs,
InputStream templateIs,
Properties outputProps,
Properties xslParams) throws TransformerException, IOException {
StreamSource source = new StreamSource( srcIs );
StreamResult result = new StreamResult( destOs );
StreamSource template = new StreamSource( templateIs );
Templates templates = transformerFactory.newTemplates( template );
// set output properties
Transformer transformer = templates.newTransformer();
if(outputProps != null)
{
transformer.setOutputProperties(outputProps);
}
// set xsl parameters
if(xslParams != null)
{
// note, xslParams.keys() will not work properly,
// because it will not return the keys for default properties.
Enumeration keys = xslParams.propertyNames();
while( keys.hasMoreElements() )
{
String key = (String)keys.nextElement();
transformer.setParameter(key, xslParams.getProperty(key));
}
}
transformer.transform( source, result );
}
Applies template templateIs to xml source
srcIs with output properties outputProps
and parameters xslParams.
The resulting xml is written to destOs |