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

[Selectors4] Complex Attribute Value Matching

From: Christoph Päper <christoph.paeper@crissov.de>
Date: Mon, 25 Jul 2011 17:14:46 +0200
Message-Id: <EAFE4B94-330F-4D6F-A60C-509CAA75FBB8@crissov.de>
To: CSS WG <www-style@w3.org>
List Matches
------------

‘^’ and ‘$’ clearly were inspired by regular expression syntax, which knows several flags. Besides ‘g’ (global) and ‘i’ (ignore case), there is ‘m’ (work over multiple lines):

  ‘^’ is start of line (SOL) instead of start of string (SOS),
  ‘$’ is end of line (EOL) instead of end of string (EOS)

This may translate usefully for whitespace-separated lists:

  [att~=val] – includes an item that equals ‘val’
             = [att*~=val]
  [att^~val] – begins with an item that equals ‘val’
             = [att^~=val]
  [att$~val] – ends with an item that equals ‘val’
             = [att$~=val]

  [att~^val] – includes an item that starts with ‘val’
             = [att~^=val]
  [att~$val] – includes an item that ends with ‘val’
             = [att~$=val]
  [att~*val] – includes an item that contains ‘val’
             = [att~*=val]

  [att^~^=val] – begins with an item that starts with ‘val’
  …

I prefer the alternative, long forms that always include an equals sign, like it is the case with current attribute selectors.

Not all value lists separate their items by whitespace (alone), but by comma, semicolon or the like:

  [att,=val]  – includes item ‘val’, works analogous to [att~=val]
  …

Substring Matches
-----------------

When attribute ‘att’ has a string literal, textual value:

  [att=val]   – equals ‘val’
  [att!=val]  – not equals ‘val’

  [att^=val]  – begins with ‘val’
  [att$=val]  – ends with ‘val’

  [att*=val]  – contains ‘val’ at least once    {1,}
  [att+=val]  – contains ‘val’ more than once   {2,}
  [att-=val]  – contains ‘val’ at most once     {0,1}
              = [att!=val],[att?=val]
  [att?=val]  – contains ‘val’ exactly once     {1,1}
              = [att*=val][att-=val]
  [att!*=val] – contains ‘val’ not at all       {0,0}
              ≈ :not([att*=val])

  [att/=val]  – matches the regular expression ‘val’

Numeric Matches
---------------

When attribute ‘att’ has a numeric value:

  [att%=val] – equals ‘val’
  [att<>val] – not equals ‘val’ or:
  [att%!=val]  if every comparison should end with ‘=’
             = [att<val],[att>val]
  [att<val]  – less than ‘val’ or:
  [att<<=val]  if every comparison should end with ‘=’
  [att>val]  – greater than ‘val’ or:
  [att>>=val]  if every comparison should end with ‘=’
  [att<=val] – less than or equal to ‘val’
             = [att%=val],[att<val]
  [att>=val] – greater than or equal to ‘val’
             = [att%=val],[att>val]

When attribute ‘att’ has a string literal, textual value of n characters:

  [att&=val] – length n equals ‘val’

Binary Matches
--------------

When attribute ‘att’ has a binary value:

  [att!]     – false
             ≈ [att%=0],[att=false],[att=off]
  [att?]     – true 
             ≈ [att%=1],[att=true],[att=on],[att=att]

Switch exclamation and question mark?

Other Matches
-------------

When attribute ‘att’ has a value of any or of a different type:

  [att#=val] – dynamic text value currently equals ‘val’
             ≈ ::value

  [att.]     – would be valid if set (assertion) or:
  [att:]
  [att.=val] – value would be valid if ‘val’ 

  [att_=val] – typed value (length, color etc.) equals ‘val’
  [att@=val] – URI value equals ‘val’ when resolved

  [att:comp]     – value has a component ‘comp’
  [att:comp=val] – value component ‘comp’ equals ‘val’

PS: Some of these ideas differ from earlier ones in <http://lists.w3.org/Archives/Public/www-style/2011Apr/0817.html>
Received on Monday, 25 July 2011 15:15:27 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:42 GMT