Re: Suggestion for Attribute Selectors (and answer to Q[lang] problem)

On Sat, 7 Mar 1998, Ian Hickson wrote:

> We currently have
>      [attr="fullvalue"]
>      [attr~="wordinlist"]
> in the CSS2 Working Draft. What about
>      [attr?="partvalue"]
> for a case (in)sensitive search of an attribute? (operator ?= could be
> anything).
[examples omitted]

We've certainly thought about this, but we decided that you would soon
need full regular expressions, and those would complicate both the syntax
and the implementations rather a lot. Case-insensitive matching is a real
problem once you go beyond ASCII. And in fact, once you start matching
attributes, why not match content as well? Then you could highlight all
occurrences of your name, without adding markup! 

The selector syntax is already getting complex, and we decided to give it
a rest, and take some time to think about this:

  1. what do we need to match on?
  2. how complex can we make the selectors while keeping them readable?
  3. can we come up with intuitive syntax?
  4. what can be implemented without a performance hit?

It's also our policy not to go to far ahead of implementation experience.
Most of the new selector features have been implemented in some form or
another in various programs, and about the rest we have implementers'
assurance that they can do it.

We want many interoperable implementations of CSS, and that means we have
to proceed step by step. It also means designers and authors still have to
work together to insert appropriate CLASS attributes. 

We have, however, decided to add the operator "|=", specifically for
matching language codes:

    [lang |= fr]

will match all language codes whose first segment is "fr": "fr", "fr-ca",
"fr-fr-argot", etc.

> =-=-=-=-=-=-=-=-=-
> 
> Note - in the page about generated content, there is a comment about "how do
> we do language dependant quotes?".
> The answer is
>    [lang="fr"] Q:before, Q[lang="fr"]:before { content: '\AB' }
> which copes with quotes within a language section, and quotes of a
> particular language in another language's section. (unless I've missed
> something important!)

It's a bit more complex than that:

  1 if there are quotes within quotes, you want a different quote for each
    level (you can try to list all combinations, but the number of
    selectors quickly gets long)

  2 your selector will match <DIV lang=fr>...<DIV lang=en>...<Q> and put
    French quotes on the English Q.

  3 sometimes the language is not set on any LANG attribute, but only on a
    META tag or on an HTTP header.

We've decided to add an inherited property 'quotes' and keywords
'open-quote' and 'close-quote': 

    [lang|=fr] {quotes: "\AB" "\BB"  "\2039" "\203A"  '"' '"'}
    [lang|=en] {quotes: '"' '"'  "'" "'"}
    Q:before {content: open-quote}
    Q:after {content: close-quote}

'Open-quote' will insert one of the quotes given by the 'quotes' property
and will automatically keep track of the nesting level.

This seems to solve the problems 1 and 2 above, but unfortunately not 3.

To solve 3, we want to add a pseudo-class ":lang(fr)", which matches if
the element is in language fr according to the language inheritance rules
of the source document. Thus

    HTML:lang(en) {quotes: '"' '"'  "'" "'"}

will select English quotes if the HTML element is in English, either
because HTML had a LANG attribute, or because a META tag or an HTTP header
made the whole document English. 

Comments?


Bert
--
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/INRIA
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 4 93 65 76 92               06902 Sophia Antipolis Cedex, France
  +33 (0)4 92 38 76 92 (<--- after 5 Jan 1998)

Received on Saturday, 7 March 1998 11:09:30 UTC