views:

96

answers:

1

Hi there. I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output. The architecture that I'm using is as follows: [Client Side] Web-Browser => [Server Side: Glassfish v3] JSP-pages -> Web-Services. My web service generates some XML-data, then I want to format it with XSL-stylesheet, pass the result to JSP-page and show to user. I'm using JAXP for XSL-transformations and I want to create a javax.xml.transform.stream.StreamSource object with XSL-file stream for the javax.xml.transform.Transformer object, but I'm having a difficulty with specifying the path/URL for the XSL-file.

So the question is: where should I put my XSL-stylesheets in a project and how should I access them from code? I'm using Glassfish v3 and NetBeans 6.8.

Thanks.

+1  A: 

The crucial point here is that you should do the XSLT process in memory, where the transformation is done with a DOMSource on the output from your web service.

A typical scenario is placing the XSLT-files in your classpath, and loading them through the class loader (getResourceAsStream), which can be used in your StreamSource. A more efficient approach is to create a Templates object (precompiled XSLT) which can be done at the beginning of your program, catching any syntax errors up front.

Thorbjørn Ravn Andersen
Thanks. I tried approach with a ClassLoader and it works fine.
Tony