wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser)" Watch "using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser)" New topic
Author

using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser)

raya ku
Greenhorn

Joined: May 05, 2001
Posts: 1
Hi,
I can say ur help will be appreciated very well,Becoz ,We are at designing stage.
Is there any processer/parser to generate .xsl/.xslt files by accepting .xml files as input. If it is there , It is easier to generate .html files using XT processer. Becoz i am sick of writing .xsl .xslt and .html files from .xml files.
If i want to use this .html file in JSP file as presentation how should i approach?.
AND
How should i write a servlet/jsp file by using (.xml and .xsl/.xslt) files to generage .html content as output and input to browser.
Your help will be aprreciated.
raya.ku
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Is there any processer/parser to generate .xsl/.xslt files by accepting .xml files as input. If it is there , It is easier to generate .html files using XT processer. Becoz i am sick of writing .xsl .xslt and .html files from .xml files.
Raya, it�s not clear what level of control you have on your XML and HTML files. Do you have predefined HTML file for each XML, so you have to convert to this particular HTML? If not, and if all you need is somehow show your XML, you can write one generic XSLT which will, for example, translate any element into <p>element content</p> or something like this.
If you do have predefined HTML, then I am not sure you can 100% automatize this task. There always will be need to tell an automat which XML tags corresponds to which piece of HTML. Perhaps there are tools which allow you to do it in run time via GUI or some kind of script, check this: http://www.xmlsoftware.com/convert/
Another possibility: if you have a control on how your XML files are generated, you can modify this process by including presentation information in XML document itself. This is described in XML Journal, vol. 2, issue 3, p.32
something like:

and then have one generic XSLT which will produce HTML output (or another XSLT, or even Java program; the article I mentioned describes Java program generation from XSLT )
How should i write a servlet/jsp file by using (.xml and .xsl/.xslt) files to generage .html content as output and input to browser.
Usually you simply call your XSLT processor and tell it your input XML and XSL files. For example with Xalan and Jakarta taglib you would write:

in this case resulting HTML will be inserted after <body> tag.
For more information you can read:
Using XML and JSP together By Alex Chaffee http://www.javaworld.com/jw-03-2000/jw-0331-ssj-jspxml.html
Serving XML with JavaServer Pages by Duan Yunjian and Willie Wheeler http://www.devx.com/upload/free/features/javapro/2000/08aug00/ww0008/ww0008.asp

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Is there any processer/parser to generate .xsl/.xslt files by accepting .xml files as input.
What kind of xml files as input? Or do you mean what Mapraputa appears to think you mean and do you have .html templates/examples as a starting point? If not, and you mean what you write, there certainly is a processor which may be able to generate .xsl files from your .xml input. It's called XSLT (remember, an .xsl file is a valid xml file, and can itself be generated using a stylesheet). It may even be able to generate your .html. Whether it is feasible depends on what information is present in your .xml input.
I'd like to add that the Orion application server comes with Xalan and makes the XSLT processing very smooth indeed. Just code your JSP to generate XML with the appropriate stylesheet link. Orion comes preconfigured to recognise this, puts it through Xalan and sends the generated HTML to the browser. When I first started to dabble in XSLT, I thought that was incredibly cool
- Peter
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Mapraputa Is:
[...] if you have a control on how your XML files are generated, you can modify this process by including presentation information in XML document itself.

Mapraputa, doesn't this ruin the division of responsibilities between the stylesheet and the XML files? Presumably, the stylesheet is there to generate the visual formatting. By including presentation information in the XML file, you start to couple the XML file pretty tightly to the layout and you lose all the advantages of an XML + XSLT -> HTML setup. Or am I missing something?
- Peter
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Peter, thanks for disagreement
I think that XML + some metadata about how the data should be rendered is not so bad design decision. It�s something between 100% data + layout coupling and 100% separating. By putting such information in XML document we do not actually tie data to representation, it�s still possible to have various XSLT which will simply ignore this meta information and produce any other desired output. We just provide recommendations (or, if you want, default representation) how data could be shown.
I suggested such trick based on Raya�s wish to get rid of XSLT creative writing process Unfortunately, we do not see the whole picture: what all those XML document came from? Do they all have different structure? What kind of processing is required to show them as HTML? If there is no need to select/rearrange elements, then CSS would suffice. Raya, if you could give us more information, we hopefully could say something more appropriate to your task.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser)
 
Similar Threads
xsl variables to core set
How can I apply a XSL to the result of another XSL?
PDF generation
transform xml -> xml with xsl(t)
jsp to xml