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

Re: [selectors] Anonymous Attribute Selector

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 2 Jun 2014 12:32:27 -0700
Message-ID: <CAAWBYDBe5ujU6Hm9ZsSN1teFR8sk9yL7Jkw5sTQjXCbqQMU5YQ@mail.gmail.com>
To: Christoph Päper <christoph.paeper@crissov.de>
Cc: www-style list <www-style@w3.org>
On Mon, Jun 2, 2014 at 2:11 AM, Christoph Päper
<christoph.paeper@crissov.de> wrote:
> Tab Atkins Jr. <jackalmage@gmail.com>:
>> On Fri, May 30, 2014 at 2:33 AM, Christoph Päper
>>> 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.
> Sure, that could work today, but why shouldn’t there be a generic solution for attributes when there is one for elements?

Because there's no use-case for it (or at least, none has been
presented so far).

> The universal element selector is actually used a lot,
> although usually in its implicit form wherein the optional asterisk ‘*’ isn’t used:
>   .class
>   #id
>   :pseudo
>   [attribute]

The fact that Selectors talks about * being there implicitly is, I
think, a remnant of a somewhat confused old notion that every compound
selector needs to have a type selector in it.  Don't pay any attention
to it; a compound selector is just a string of selectors; using a * in
conjunction with any other simple selector is just empty noise, and
not actually useful in any fashion.

> It’s used explicitly the most in descendant selectors
> (and when targeting browser parsing bugs).
>   foo>*>bar
>   foo * bar

Yup, this is one of the two use-cases for the universal selector - to
provide a placeholder when you want to just chain combinators, because
the syntax of Selectors doesn't allow combinators to be chained

(The other use-case is to select all elements in the page, because the
syntax of CSS doesn't allow an empty selector.)

> A universal attribute selector would encompass my anonymous attribute selector,
> because if it selects any attribute it doesn’t matter whether that’s named, implicit or anonymous.

Yes, it encompasses your use-case, meaning that it's broader and more
powerful than your use-case requires.  Without any use-cases for the
increased power, though, it's probably reaching too far.

Once again, though, you do *not* need to select an "anonymous"
attribute.  You just need to specify that your single unnamed
attribute maps to an attribute of a particular name in DOM.  The only
reason you have trouble here is because you're trying to lean on
HTML's parsing rules to parse a non-HTML language that makes different
assumptions about some things (namely, the syntax of attributes).  Fix
that and your CSS problem goes away.

> So I would like to upgrade my proposal accordingly.
>   [@]
> selects a node that has any attribute specified, but
>   attr(@)
> still only uses the [first?] anonymous attribute.
>   []
> remains a syntax error and selects nothing and
>   attr()
> also fails to do anything useful.
> In HTML4/RFC1942, for instance,
>   table[@="border"]
> unlike
>   table[border]
> would be a correct way to match
>   <table border>
> since that’s shorthand for
>   <table frame="border">
> but
>   table[frame]
>   table[frame="border"]
> should both match then, too, of course.

HTML4 is irrelevant (and no browser has ever applied the SGML rules
for enumerated attributes), but 'border' is an attribute in its own
right, and takes an integer value.

> In BBCode,
>   [URL=http://example.com]foo[/URL]
> would be matched by
>   URL[@*="example.com"]

Just like your example, BBCode needs to define a mapping into DOM if
it expects to be matched by CSS, which means defining a name for the
attribute of the [url] tag.

To reiterate - I don't see a use-case for an unnamed attribute here.
Selectors is based on the DOM, and you're defining your own markup
language, so you can define how it maps into a DOM.  In particular,
you can define a name for your attribute for the purpose of Selectors
and the DOM, even if that name is never written or referenced within
your markup language.  I strongly oppose complicating the Selectors
syntax and data model to address this when it's so trivial to address
it on the host language side.

Received on Monday, 2 June 2014 19:33:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:43 UTC