W3C home > Mailing lists > Public > www-style@w3.org > July 2002

Re: CSS in XML format ?

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 11 Jul 2002 02:07:03 +0100
Message-ID: <3D2CDA37.2090605@hixie.ch>
To: Patrick Andries <pandries@iti.qc.ca>
Cc: www-style@w3.org

Patrick Andries wrote:
> 
> CGML (California Generic Markup Language, no joke : some legacy format) and
> FO, currently.

Interesting.

In that case, are you in fact really intending to take on the task of writing a 
CSS renderer in XSLT? Because if you are, I guarentee that the parsing of the 
stylesheets will be by *far* the least of your problems.


>> CSS is not a tree-like language, XML is not suitable for representing
>> the content of CSS.
> 
> Could you explain this part ? This sounds interesting (fendamental).

Of course.

Let's take a sample stylesheet:


    @import url(colors.css);
    @namespace html url(http://www.w3.org/1999/xhtml);
    @namespace test url(http://xmlns.example.org/test);

    @color-profile {
       name: example;
       rendering-intent: saturation;
    }

    html|* { opacity: 1.0 1; }

    *|test /* any element named test in any namespace */
      >    /* have as child */
    test|* /* any element in the test namespace declared above */
      { color: rgba( /* red */ 25%, /* green */ 100%, /* blue */ 0%,
                     /* alpha */ 0.5); }
    q::before { content: counters(quote, ':') " " open-quote;
                counter-increment: quote 1; }
    :link:hover::first-letter { border: curly green; border: solid green; }


I don't really know how to put it... but... there is no way you are going to 
convert that to an XML representation without making it so verbose that no one 
could look at it without bursting out in laughter. Try it. Without losing any of 
the semantics of that stylesheet, convert it to an XML representation which 
doesn't require further parsing.

It *is* possible to throw in some random XML tags into the mix, to make it look 
like XML, for example the rule above mentioning 'color' could be:

    <rule>
      <selector>
        *|test <!-- any element named test in any namespace -->
         &gt;  <!-- have as child -->
        test|* <!-- any element in the test namespace declared above -->
      </selector>
      <declaration>
       <property> color </property>
       <value>
         rgba( <!-- red --> 25%, <!-- green --> 100%, <!-- blue --> 0%,
               <!-- alpha --> 0.5);
       </value>
      </declaration>
    </rule>

...but that wouldn't help you in the least, since the selector and values are 
still in CSS syntax. Not only that, but the document just doubled in size.

The point is that XML fundamentally models tree structures. CSS, on the other 
hand, is not a tree structure, it's a rich grammar with more in common with 
programming language grammars than with tree based markup.

CSS maps (effectively) unordered sets of properties and complex values to lists 
of elements matched by selectors.


>> Especially don't fall prey to the notion that because your tool (XSLT)
>> has limitations (only being able to handle XML), everything should fit
>> those limitations. Paraphrasing an old saying: "When all you have is a
>> hammer, you want everything to be a nail."
> 
> It remains to be proven what has limitations (question above) : the syntax
> of CSS excluding it from processing by W3C standards or XSLT.

XSLT has limitations because it cannot handle CSS, which came before it. CSS, 
having existed before XSLT, certainly has no reason to be shoe-horned into being 
compatible with XSLT.

-- 
Ian Hickson                                      )\._.,--....,'``.    fL
"meow"                                          /,   _.. \   _\  ;`._ ,.
http://index.hixie.ch/                         `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 10 July 2002 21:07:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:15 GMT