Re: pseudoclass based on document content

Justin Watt wrote:

>This might be something of a black hole, but has anyone thought about
>using pseudoclasses to apply style based on document content, as opposed
>to structure or other intrinsic qualities of structure?
>
>One example of what I mean is described here:
>http://www.unc.edu/~jwatt/2004/07/css-pseudoclass-for-negative-numbers.html
>
>Let's say you have a table that has negative numbers in it. You want the
>negative numbers to appear red while the other numbers inherit their
>color.
>
>The might be "pseudo"-coded in CSS as:
>
>TD:negative-number {color:red;}
>
>The problem is that variations in content are infinite. So it probably
>wouldn't make sense to create a ":negative-number" pseudoclass because 100
>different people would probably request 100 different selectors for their
>special cases.
>
>Maybe there is a way to take advantage of simple pattern matching based on
>content, perhaps using regular expressions?
>
>The following might read: make the text inside TDs red if that text begins
>with a hypen (minus-sign) and ends with one or more other characters.
>
>TD:content-regex(/-.+/) {color:red;}
>
>The benefit of this approach being that if negative numbers in your
>document are surrounded by parentheses, you can modify the regular
>expression in the stylesheet rather than having to modify your document to
>play nice with a UA's implementation of ":negative-number".
>
>Thoughts?
>
>Justin Watt
>
>
>
>  
>
As a note, I like the *thought* of the reg-ex, however think of the CSS 
forward compat parsing rules, what would happen when a regex contains a 
) or a {, } etc. (insert other possible regex chars), even when escaped  
a UA that does not understand the :content-regex( ... )  as you propose 
would END parsing at the closing ).

so in light of "thought" it is good, but there would have to be a way to 
specify such characters without actually using them, which would make 
any worthwhile regex that much harder to write/parse and also make for 
real annoying author errors on the subject.

The rest of your issue which I would have stated has been responded to 
in the thread already, so I will keep from adding duplicate thought.

~Justin Wood

Received on Saturday, 17 July 2004 01:13:21 UTC