W3C home > Mailing lists > Public > www-style@w3.org > May 2014

[selectors] Anonymous Attribute Selector

From: Christoph Päper <christoph.paeper@crissov.de>
Date: Fri, 30 May 2014 11:33:29 +0200
To: www-style list <www-style@w3.org>
Message-Id: <8EE801EF-75D7-4D87-A8B4-F09AADBBA428@crissov.de>
Let’s assume I have a document language with usual named element types, but without predefined attributes. The only attribute for each element type is anonymous and its value can be any string or digit or, possibly, any other type:

  <element attribute>
  <element true>
  <element 123>
  <element 12px>
  <element 100%>

If HTML/SGML faces the first case, a boolean attribute is created, i.e. it’s defined as a shorthand of

  <element attribute="attribute">

which enables Selectors

  element[attribute]
  element[attribute="attribute"]

In SGML, the attribute name and its value keyword wouldn’t even have to match, but the other cases cannot be modeled and therefore are not possible in HTML and XML, maybe they are in SGML with some DTD trickery. 

Anyway, my (actually not so hypothetic) language isn’t *ML-based. There currently is no way in Selectors to match such anonymous attributes, but there’s kind of a way to match anonymous elements with the universal selector which is optional in ID, class, pseudo-class, pseudo-element and attribute selectors. 

  *
  *#id              =   #id
  *.class           =   .class
  *:pseudo-class    =   :pseudo-class
  *::pseudo-element =   ::pseudo-element
  *[attribute]      =   [attribute]

Therefore, I’d like to propose an anonymous attribute selector. Since ‘*’ is already used in the “contains” attribute selector ‘*=’, I suggest the at-sign ‘@’, which is often used to symbolize attributes anyway.

  [@*="a"]   {}
  [@="true"] {}
  [@^=1]     {}
  [@$="px"]  {}
  [@$="%"]   {}

The ‘attr()’ pseudo-function would of course also have to accept that symbol:

  [@*="a"]::before {content: attr(@);}
  [@$="px"] {width: attr(@ length);}

That’s also the reason why the attribute cannot just be left out:

  [*="a"]   {}
  [="true"] {}
  [^=1]     {}
  [$="px"]  {}
  [$="%"]   {}

  [*="a"]::before {content: attr();} /* might still work */
  [$="px"] {width: attr(length);}    /* fails */

In languages that do have named attributes, any attribute would match that selector, probably. This may make it useful for HTML, but probably not all that often.

 PS: Attribute selectors for detailed numeric matching, like ‘<=’, ‘>=’ or ‘!=’,
     have been proposed earlier, but sadly haven‘t made it into the ED yet.
Received on Friday, 30 May 2014 09:33:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:51:27 UTC