The recurring search for an XML version of CSS

By Bryan Rasmussen
June 26, 2008 | Comments: 4

Every now and then someone asks for an XML version of CSS, I can't say that I don't know why because I've wanted it in the past myself but I do wonder if the wish isn't a little wrong-headed, it smacks a little bit of thinking that everything should be structured as XML. Which is a viewpoint think I would like to avoid because I worry that it seems perhaps too religious about technologies.

There are various reasons why you might want a CSS version of XML, for me it was because I was programming for Cross-media generation and I wanted a way to reuse definitions easily in one format with other formats, so I wanted an XML format that I could reuse. This made it easier to control that presentations of the data in XHTML, PDF, Ebook, or Microsoft Help or Word files all had the same styling where relevant, or to do calculations from a base style that altered specific to the media.

Roger Costello recently posted the question to xml-dev "CSS does not use the XML syntax. Why not?" in which it was generally concluded that the main reason was that CSS was created some years before XML, this is also one of the points that was made by Håkon Wium Lee in his thesis although he obviously had several other points...

The mobileOK checker task force also felt the need for an XML version of CSS some time ago, and made a proof of concept in cssxml
, an example of their version is here , they follow the structure of CSS very closely, so as use validation tools and more easily transform the XML to the output IIRC.

As I said I've also rolled my own cssxml version in the past, this was from 2002:


<style xmlns="cssxml">
<selector class="fileheaderblock">
<s name="width">7.5in</s><s name="height">3in</s>
<s name="line-height">45pt</s>
<s name="color">black</s><s name="font-size">20pt</s><s
name="font-family">Courier</s></selector>
<selector class="regionbeforeblock">
<s name="font-weight">bold</s><s name="font-size">28pt</s><s
name="font-family">Courier</s>
<s name="text-align">center</s>
<s name="color">black</s>
</selector>


<selector id="p1">
<s name="color">#ff0000</s>
<s name="font">11pt Times</s>
<s name="space-before.optimum">4pt</s>
</selector>


</style>

The above was basically used to provide CSS like capabilities to XSL-FO generation, in the case of XHTML it was possible to also have list attributes on a selector, where one could have more complicated CSS declarations. I prefer mine to the cssxml, not just because it's mine (this is too old and too interesting to take any pride of ownership) but because it is less verbose, the format was still meant to be authored by hand in some cases, although in the end I did build some tools for parsing in normal CSS and generating the cssxml format I was using.


You might also be interested in:


4 Comments

You should read your history books, Bryan. There is an XML version of CSS. It's called XSL-FO, and before that it was just XSL, the -T and -FO becoming to separate specifications for various reasons, one of which was an outcry from the CSS folks that XSL was attempting to too many things to too many people.

BTW... I know you know this. I simply wonder why you make statements like "The above was basically used to provide CSS like capabilities to XSL-FO generation," knowing full well that XSL-FO provides all of the style and formatting capabilities of CSS, but with a focus on more than just web documents.

Bryan,

Around 2003 I was also engaged in a very similar enterprise where I wanted a single source of styling that could be applied to multiple output formats (XHTML and PDF). I too did the CSS as XML thing and used XSLT to apply the styles to the output documents.

I once again revisited the theme in 2007 when I was looking at creating SMIL presentations from other XML source documents, where I needed to map CSS referenced from the source document to RealPlayer and QuickTime styling properties. In this case I parsed the original CSS and generated an intermediate XML format that could be processed with XSLT as part of the transformation process.

It is a lot of fun playing with this, and it has a lot of benefits but, like you, I think the notion of an XML version of CSS is a bit 'wrong-headed' - at least from the perspective of authoring the stylesheet - but as an internal format for mapping styles between different XML formats, it can work rather well.

Popular Topics

Archives

Or, visit our complete archives.

Recommended for You

Got a Question?