Perform an XSLT transformation.
String xsltFileName = null;
try {
// figure out the complete XSLT stylesheet file name
synchronized (filenameCache) {
xsltFileName = (String) filenameCache.get(xsltBaseName);
if (xsltFileName == null) {
ServletContext ctx = servlet.getServletContext();
xsltFileName = ctx.getRealPath(
"/WEB-INF/xslt/" + xsltBaseName);
filenameCache.put(xsltBaseName, xsltFileName);
}
}
// write the JDOM data to a StringWriter
StringWriter sw = new StringWriter();
XMLOutputter xmlOut = new XMLOutputter("", false, "UTF-8");
xmlOut.output(xmlJDOMData, sw);
response.setContentType("text/html");
Transformer trans = StylesheetCache.newTransformer(xsltFileName);
// pass a parameter to the XSLT stylesheet
trans.setParameter("rootDir", "/forum/");
trans.transform(new StreamSource(new StringReader(sw.toString())),
new StreamResult(response.getWriter()));
} catch (IOException ioe) {
throw ioe;
} catch (Exception ex) {
throw new ServletException(ex);
}