[selectors4] Attribute selectors for numerical comparison

It seems that the need for greater-than and less-than operators in attribute selectors (i.e. [attr>value]) is very common, yet we only have equality and partial string matching. I imagine this is because every attribute is a string, but I don’t understand why we can’t define the selector to convert the attribute value to a <number> first, using the same grammar as CSS. If the conversion fails, the selector doesn’t match anything (this is on par with how comparisons work in JS too).

The main wart with this is that what authors need is not always numerical comparison, but sometimes they need to compare e.g. dates [1]. There are multiple ways to deal with this:
1. We ignore it and just deal with numbers, since that already solves several use cases. We can always use different comparison attribute selectors in the future for dates.
2. We use heuristics to determine whether it's a date or a number. Can’t think of any conflict, but it's a bit hacky.
3. We use a whitelist, which could be different per host language. 

[1]: https://lists.w3.org/Archives/Public/www-style/2007Jan/0080.html <https://lists.w3.org/Archives/Public/www-style/2007Jan/0080.html>
Lea Verou ✿ http://lea.verou.me ✿ @leaverou

Received on Monday, 2 November 2015 14:08:11 UTC