CSS, XML and Browsers

jjohn on 2002-01-30T01:51:09

Don't panic -- I'm not trying to sell you anything despite the acronyms in the subject line.

In my quest to bring docbook XML into 1990's, when users could easily change the fonts of their documents at the slightest whim, I ran across an interesting chapter in XML in a Nutshell. It mentions that many modern browsers can actually render XML documents that reference a CSS stylesheet. Ok. I knew this was clearly going to be an exercise in pain, but I had to see how painful. Remember, I want to turn docbook into PDF with my choice of fonts, not Fop's.

So I cruise over to the docbook project site and pick up a few of the contributed CSS files. I create a very simple docbook file and reference one of these CSS files. I used Opera on both Linux and Windows, I used IE 5.5, I used Mozilla. I got nothing but the XML file back without formating.

mmm.

Upon closer inspection, it was clear that these CSS files were meant for HTML files, not raw XML. So, I hacked up this lame CSS file:

/* jjohn's CSS hack for docbook --
This is to get BROWSERS to render XML.
There is *NO* transformational step */

para {
display: block;
font-family: courier;
font-size: 12pt;
}

title {
display: block;
font-family: verdana;
font-size: 14pt;
font-weight: bold;
}

Ah-HA! Progress! I got the XML to render (weakly) in Galeon but as a proof-of-concept test, it worked as expected. Now, how to get this into PDF. Well, Galeon can print PS to a file, which I did. Unfortunately the funky fonts I had picked didn't get into the PS, so I didn't even bother running ps2pdf. I think that's weird because the fonts do show up on screen. But then, I don't really understand the implementation of rendering fonts.

Still, this seems like a promising line of research. Does anyone here know if the Mozilla project has a command line CSS processor that will vomit forth Postscript? That would be super-fantastic. Heck if I had that, I could go docbook->HTML->CSS->PS->PDF and hopefully get formatting AND fonts. Excellent.


Oh my God: CSS is compiled to JavaScript!

jjohn on 2002-01-30T02:06:02

I was just reading the netscape.public.mozilla.layout newsgroup and was horrified to learn that CSS was implemented with JavaScript in Netscape browsers. Yow! That'll make my CSS command line process even more unlikely (besides the fact that it would need to parse and render HTML too. Sigh. Life isn't fair.

Re:Oh my God: CSS is compiled to JavaScript!

pudge on 2002-01-31T15:03:25

In Mozilla, MANY things are implemented with JavaScript. Kinda pretty scary.

JavaScript

TorgoX on 2002-01-30T03:19:48

And isn't JavaScript still implemented in Java?

Re:JavaScript

chromatic on 2002-01-30T04:57:05

Assuming you don't know better, it's always been an entirely different kind of pain.