« MARC authorities formatting | Main | Embedding XSLT in XML »

XML and CSS

Css One problem with using XSLT to format Web pages in the browser is that some don't support it, Opera in particular.  Looking into this, I was looking at the Opera site and they claim to be able to parse and display XML documents.  Looking around, the approach you need to do this is to associate a CSS style sheet with the XML and use JavaScript/DOM to do any transformations needed.  Here's a good explanation of the technique.  The example they give, though, only worked correctly for me in Opera, not Firefox or IE.

From all I've read, it looks like Opera has done a great job supporting CSS compared to other browsers, and you can do some amazing things with CSS. So, we could probably make the Dewey Browser's client-side formatting work with Opera, but it would take quite a bit of work.  (The Dewey Browser does make extensive use of CSS, but it is applied to the HTML page that the XSLT generates, not on the raw XML page the server sends out.)  It would probably be easier for us just to detect Opera and do the transformation from XML to HTML on our server, although for the number of visits we see from Opera on our site for other things, we may not even do that right away.

I was wondering why this style of programming never caught on.  It's been available longer than XSLT support, but I wasn't even aware of the possibility, much less seeing examples of it.  Maybe it's a case of a technology being ahead of its time, or maybe DOM transformations are just easier to do with XSLT than with JavaScript.  Or maybe by the time CSS support became reliable, XSLT was there too.  Whatever the reason, I doubt if avoiding XSLT is going to catch on.  Looking around the Web this seems to have been a bigger topic a few years ago (XSL Considered Harmful), but the arguments get a bit muddy, since they worry about XSL Formatting Objects, which is a direct competitor to CSS, and another technology I was only barely aware of, even though a book I sometimes use does talk about it.  As far as I can tell the major browsers don't support XSL-FO (the XML stylesheet language).  W3C has an overview page of XSL's three parts: XSLT, XML Path, and XSL-FO.

--Th

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83459bf2269e200e55085cebe8834

Listed below are links to weblogs that reference XML and CSS:

Comments

FO has had a tough road. It's really more of a print-layout language, and most of the applications for it have focused primarily on PDF generation, with other renderings trailing. It's really tough stuff to work with without tool support, and tool support has seriously lagged.
Håkon Wium Lie, Opera's CTO, created CSS while at W3C, so it's no surprise that Opera's CSS support is pretty good.

Love the blog, Thom.

XSL-FO was thought by some to eventually go to the browser, but the biggest push in XSL-FO has typically been for the creation of print documents. If you actually look at the spec you'll see it shares common roots with CSS.

XSL-FO really hasn't caught on just in part because even the print tools that are open source tend to be rough. So one must learn the standards, typography, and how the various processors actually process the XSL-FO.

I'll have to follow up on the CSS stuff. Main reason I'll choose XSLT over CSS styling is that so far it seems that CSS tends to work better with html and with XML as an after-thought. So I prefer having the html and having CSS style that. I still remember one project I worked on where we were hoping to use CSS because it was a simple enough project but then realized some of the elements in our schema used periods in their names. At the tyime we couldn't figure out how to specify the element any element with a period in the name in a css file.


In practice I've tended to find it easier to use XSLT rather than Javascript for transformation, but it's possible to do both. Of couse, my gut feeling is that most have avoided it also just because it's only lately there seems to be a sharp increase in the number of people working with XML and doing client-side transformations. I think we'll see more of this happening as AJAX gets more powerful and more of the web community actually starts playing with both DOM and actual XML.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

My Photo

June 2009

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30