I can use XML namespaces on CSS attribute selectors fine, even with pseudoclasses:
<root xmlns="http://www.tei-c.org/ns/1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<s xml:id="s382.11.1" n="someValue">Content goes here</s>
</root>
@namespace url(https://www.tei-c.org/ns/1.0);
@namespace xml url(https://www.w3.org/XML/1998/namespace);
[xml|id]::before {
content: attr(n);
}
But when applying the same namespace syntax to the attr
function in a content
declaration, Google Chrome 126 and Opera 106 don’t get it, although Firefox 128 does:
@namespace url(https://www.tei-c.org/ns/1.0);
@namespace xml url(https://www.w3.org/XML/1998/namespace);
s {
display: block;
margin: 8px 16px;
clear: both;
}
s::before {
content: attr(xml|id);
display: block;
float:left;
width: 144px;
}
Chrome and Opera don’t display the ::before
pseudoelement at all, i.e. don’t reserve the specified width either, unless I set it to a default-namespace attribute @n
, in which case they behave as intended. Firefox works as intended with either attribute selected. The W3C CSS Validation Service throws a parse error at precisely this point: xml|id)
(sic). It is happy if I write attr(xml:id)
instead, but then no browser renders the pseudoelement. Is there some other way I can render this value? Moving the attribute to the default namespace in my XML corpus is not an option.