Can anyone please provide me a sample code snippet in java to convert xslt and xml to xhtml. My requirement is to replace jsp in my application with xhtml. I will take user input, convert to xml format. Use xslt and xml to generate xhtml at server side.
Hi. Thanks for the reply. I understand that it is a tough job but it meets my busines requirements. I want to create a dynamic page for my users. In short, user is allowed to choose the layout desin and click save. After this I store the layout details in the form of xml. The next time this page is rendered to the user in the same session, I want the page to be in xhtml format. I have heard it is as good as jsp. Since the pages are created on the fly, I don't wish to generate seperate jsps for each user.
Could you help me with a sample code snippet that meets my requirement? It will be a great help. Thanks in advance.
You really haven't ever seen an example of how to execute an XSL transformation in Java? That's all you're asking for, really. Try chapter 17 of ERH's online book.
Joined: Jul 07, 2009
Hi I tried to generate XHTML on server side using xml source and XSLT source as input and performed XSL transformation of XML document into servlet output stream. But I get a blank page. I am clueless as to why this is happening. Following is a piece of code I have written in my servlet.
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslSource = new StreamSource(new File(path, xsl+".xsl")); t = tFactory.newTransformer(xslSource);
t.transform(xmlSource, new StreamResult(out));
Please help. Thanks in advance.
Author and all-around good cowpoke
Joined: Mar 22, 2000
I suggest proceeding with one of the following
1. perform the transformation offline to capture the transformation result to a file so you can inspect it
2. use TCPMON to capture the actual text output from the server
3. use the Firefox browser with one of the plugins that lets you examine the response content
One possible cause for a blank screen is a failure to close the response output stream - in which case the browser is still waiting for the rest of the page.
IF you are using the MS IE browser - turn off the "friendly HTTP error messages" checkbox in the Internet options - Advanced settings dialog so you can see actual error codes.
Why not just test your transformation code at the command line? Using a servlet as a test base means that you don't know whether the problem is in the servlet or in the transformation or in something else to do with the application server or the Internet.