Syntax of CSS Rules in HTML style attribute

All,

I have some comments and questions regarding the Working Draft
http://www.w3.org/TR/2002/WD-css-style-attr-20020515. I have looked at 
the W3C member pages for any updates to it but cannot find any, possibly 
because I just don't know where to look. So if these have already been 
covered then please could you refer me to the resolution.

1) I noticed that the draft is very old, 2002, so was wondering what the 
plan was for this specification. Is it still being worked on, has it 
been abandoned, or superceded, ... ? Hopefully it is still active in 
some way as I am interested in implementing full support for it but need 
to be sure that what I do is 'standard'. The rest of my questions assume 
that it is active.

2) There appears to be an ambiguity in the grammar between the 
inline-ruleset and the stylesheet productions as they can both match the 
following string ":hover {color:red}" but depending on which one does 
the effect will be different. i.e. if inline-ruleset matches then it 
only applies to the current element but if stylesheet matches then it 
applies to the current and all nested elements.

The conflicting productions are listed below for convenience. It is 
obvious that the inline-ruleset matches and stylesheet matches as follows:
     stylesheet
     -> ruleset*
     -> selector LBRACE S* declaration [ ';' S* declaration ]* '}' S*
     -> simple_selector
     -> pseudo+

inline-stylesheet
   : S* [ declarations | declarations-block | inline-ruleset* | stylesheet ]
   ;

inline-ruleset
   : [ pseudo* S* [ ',' S* pseudo* S* ]* ]?
     declarations-block
   ;

stylesheet
   : [ CHARSET_SYM STRING ';' ]?
     [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
     [ [ ruleset | media | page ] [S|CDO|CDC]* ]*
   ;
ruleset
   : selector [ COMMA S* selector ]*
     LBRACE S* declaration [ ';' S* declaration ]* '}' S*
   ;
selector
   : simple_selector [ combinator simple_selector ]*
   ;
simple_selector
   : element_name [ HASH | class | attrib | pseudo ]*
   | [ HASH | class | attrib | pseudo ]+
   ;
pseudo
   : ':' [ IDENT | FUNCTION S* IDENT? S* ')' ]
   ;

As I see it there are two ways around this. The first is to require that 
an inline-ruleset always has to start with a declarations-block 
(possibly empty), followed by any optional pseudo attributes, or another 
at-rule is added, say @scoped {stylesheet} to contain the scoped stylesheet.

The first option seems to require less effort to specify, slight 
modification to grammar rules, and an example, but is a bit less obvious 
about what is happening than @scoped.

The new grammar would look like:

inline-stylesheet
   : S* [ declarations | declarations-block inline-ruleset* | stylesheet ]
   ;

Example: The following style attribute contains a scope stylesheet that 
applies to the element and all its children.
<div style=":visited {color: green}
             :hover {background: yellow}
             :visited:hover {color: purple}">
   <a href="/Style/CSS">Styled By Containing Style Attribute</a>
   <a href="/Style/CSS">Styled By Containing Style Attribute</a>
   <a href="/Style/CSS">Styled By Containing Style Attribute</a>
</div>

If in future a combination of style sheet and inline-ruleset is required 
then inline-ruleset could be extended to allow @scoped {} or something 
different.

3) It references CSS 2 instead of CSS 2.1 to define the specificity of 
CSS in a style attribute and they are different. I presume that CSS 2.1 
as the later specification is correct, as it is also referenced from CSS 3.

Received on Tuesday, 22 January 2008 10:42:07 UTC