开发者

XSL-stylesheet URI using JAX-WS and Glassfish v3

开发者 https://www.devze.com 2022-12-26 02:51 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消