Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL and XSLT

 
Yogesh Deshmukh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we access the XSLT to give HTML from XML?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic