Re: [selectors] Anonymous Attribute Selector

On Fri, May 30, 2014 at 2:33 AM, Christoph Päper
<christoph.paeper@crissov.de> wrote:
> 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.

Selectors defines a data model in terms of the DOM, but that doesn't
mean that your markup has to map into the DOM in exactly the way that
HTML would.

In particular, you should feel free to define that your language maps
the unnamed attribute into a DOM attribute named "attr" or something
for the purposes of Selectors.

> 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 */

Same thing here - the attr() function relies on the DOM, and you can
map your language into the DOM however you want.

~TJ

Received on Friday, 30 May 2014 18:07:32 UTC