Hello, I have a question regarding xml, xlst, and jsp. I'm using... WebSphere 4.04 Xerces 2.5.1 Xalan 2.5.1 I am currently developing an application that retreives an xml document from a database, applies any of several different xslt documents to the xml file and displays it inside of a jsp. I have done some research and found that most people have the xml and xsl documents as files and use a Transform.transform(Source, OutputStream) to display the transformed xml document. My questions are... 1. Since my xml document lives in a database is there a way to pass the xml document object to the transformer, or do I HAVE to save it as a file to the server's file system and then pass the path to the 'temporary' document as an argument? 2. The all of the transformer examples I have looked at create an output stream to get the transformed data to the client. Is there anyway I can capture the output and store it into a String or StringBuffer? I realize this is more of an IO issue but I am trying to generate this output to an object that can placed into the session and displayed inside of a jsp page. Based on what I seen I have to treat the generation of the transformed document as I would the generation of an image. (i.e. I create a jsp with an include tag that calls a url with arguments. That url is to a servlet/action class combo that retrieves the xml transforms it and just spits the data back to the client via the output stream.) 3. Is this a "best practice", acceptable solution or am I going down a wrong path? Just looking for validation and/or other options. Thanks for your time.
Balaji Loganathan
author and deputy
Bartender
Joined: Jul 13, 2001
Posts: 3150
posted
0
Originally posted by Heath Lilley: Hello, 2. The all of the transformer examples I have looked at create an output stream to get the transformed data to the client. Is there anyway I can capture the output and store it into a String or StringBuffer? I realize this is more of an IO issue but I am trying to generate this output to an object that can placed into the session and displayed inside of a jsp page.
Answer to your 2nd question. Here is the same code for doing this
You can the the variable content to write to a file using Java.IO now. Rgd question 1 The other way(if the XML file is small), you can read the XML file from database,store it on a stringbuffer and give it directly to the transformer obejct, see line2 of the above code.