File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XSL and XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL and XSLT" Watch "XSL and XSLT" New topic


Yogesh Deshmukh

Joined: Dec 26, 2000
Posts: 20
How do we access the XSLT to give HTML from XML?
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Yogesh Deshmukh:
How do we access the XSLT to give HTML from XML?

What do you mean exactly? If I'd interpret your question literally the answer would be "using a text editor"
Oh well, this is as good a place as any to try a summary; given that this forum is the subject of this week's giveaway there may actually be people reading it to the end
First, XSL versus XSL Transformations (XSLT). XSLT deals with transformations of one XML tree (parsed document) into the other. It is great for XML-XML, XML-HTML, XML-WML transformations etc.
To this transformation facility, XSL adds Formatting Objects (FO). They convert the output tree into an arbitrary output format, and are used e.g. for XML-PDF transformations (see the Cocoon framework for a fleshed out example of this).
But, you wanted to transform XML into HTML and are happy with XSLT. To give the flavour, take the following example XML file.

Suppose you wanted to transfom it into the following HTML

Then you could use the following XSL transformation:

You see that in this basic form, there is very little to it. You iterate through the XML file with for-each; you retrieve values from it using value-of.
The approach illustrated here pulls the values from the XML file. The template (HTML file, in this case) is in the driving seat. But XSLT is actually a pattern-matching language which allows you to let the XML file sit in the driving seat, if you prefer; in that case you specify a number of templates and patterns and the XSLT processor applies the templates which match the structure of your XML file. In fact, in the XSLT file above I'm implictly matching the pattern "/", the root of the XML document.
See the W3C for the formal standards, the XSL FAQ for your basic questions. XSL(T) processors: the Apache XML project, XT, Saxon. The #1 mailing list on XSL is this one.
Last but not least, if you prefer your information thorough, solid and densely packed, and G. Ken Holman is speaking at a conference near you, run, don't walk. His were the best two hours I ever spent at a conference, ever.
- Peter
PS. I did a little, lightweight 5-page write-up about XML and XSL half a year ago from which I cut and pasted much of the above. Not sure how useful it would be to anyone but I'd be willing it to e-mail it to you (Word or HTML).

[This message has been edited by Peter den Haan (edited March 13, 2001).]
I agree. Here's the link:
subject: XSL and XSLT
It's not a secret anymore!