Non-element Selectors Module Level 1

W3C Working Group Note,

This version:
https://www.w3.org/TR/2019/NOTE-selectors-nonelement-1-20190402/
Latest published version:
https://www.w3.org/TR/selectors-nonelement-1/
Editor's Draft:
https://drafts.csswg.org/selectors-nonelement/
Previous Versions:
Editors:
(Invited Expert)
Tab Atkins Jr. (Google)
Suggest an Edit for this Spec:
GitHub Editor
Issue Tracking:
GitHub Issues

Abstract

Non-element Selectors extends [SELECTORS4] and allow selecting other kinds of document nodes than elements. This is useful when selectors are used as a general document query language. Non-element Selectors are not intended to be used in CSS, but only as a separate query language in other host environments.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

This specification is obsolete. Please see the latest CSS Snapshot for the specifications that make up CSS.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

GitHub Issues are preferred for discussion of this specification. When filing an issue, please put the text “selectors-nonelement” in the title, preferably like this: “[selectors-nonelement] …summary of comment…”. All issues and comments are archived, and there is also a historical archive.

This document was produced by the CSS Working Group.

This document was produced by a group operating under the W3C Patent Policy.

This document is governed by the 1 March 2019 W3C Process Document.

1. Introduction

Selectors are a very popular mechanism for selecting things in HTML and XML content. They are not used only in CSS [CSS3SYN] but also as a standalone query language in libraries like jQuery, in newer standardized browser APIs like [SELECTORS-API] and in other Web standards like ITS 2.0.

The [SELECTORS4] specification only defines selectors for selecting element nodes from the document, but some uses of Selectors would like to select other types of nodes as well. This specification extends [SELECTORS4] with additional selectors that can be used for selecting non-element nodes in a document tree.

Note: Currently the draft only defines means for selecting and matching attribute nodes, but other kinds of nodes, such as comments or processing instructions, might be supported in the future.

2. Non-element Selectors

2.1. Attribute node selector

An attribute node selector represents an attribute node in a document tree. Its syntax is:

::attr() = ::attr( <namespace-attr>? )
<namespace-attr> = [ <na-prefix>? '|' ]? <na-name>
<na-prefix> = <ident> | '*'
<na-name> = <ident> | '*'

No whitespace is allowed between the tokens of <namespace-attr>.

<namespace-attr> is divided into two halves: an optional prefix preceding a '|' character, and an attribute name following it.

If the <na-prefix> is provided as an <ident>, it must match a declared namespace prefix, in which case the selector only matches attributes in that namespace; if it doesn’t match a declared namespace prefix, the selector matches nothing. If the <na-prefix> is provided as a * character, the selector matches attributes in any namespace. If the <na-prefix> is omitted, the selector only matches attributes in no namespace.

If the <na-name> is an <ident>, the selector matches attributes with that name. If the <na-name> is a * character, the selector matches attributes with any name.

If the <namespace-attr> is omitted entirely, the selector matches any attribute in any namespace.

The selector matches an attribute node with the given namespace and name on the originating element, if such an attribute exists.

The selector uses pseudo-element syntax.

The following ITS rules use an attribute node selector to switch off translatability of title attribute on abbr elements.
<rules xmlns="http://www.w3.org/2005/11/its"
       version="2.0"
       queryLanguage="css">
  <translateRule selector="abbr::attr(title)" translate="no"/>
</rules>

Although entirely valid in Selectors used in the scope of CSS, attribute node selectors never generate boxes.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-NAMESPACES-3]
Elika Etemad. CSS Namespaces Module Level 3. 20 March 2014. REC. URL: https://www.w3.org/TR/css-namespaces-3/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. 31 January 2019. WD. URL: https://www.w3.org/TR/css-values-4/
[SELECTORS4]
Elika Etemad; Tab Atkins Jr.. Selectors Level 4. 21 November 2018. WD. URL: https://www.w3.org/TR/selectors-4/

Informative References

[CSS3SYN]
Tab Atkins Jr.; Simon Sapin. CSS Syntax Module Level 3. 20 February 2014. CR. URL: https://www.w3.org/TR/css-syntax-3/
[SELECTORS-API]
Anne van Kesteren; Lachlan Hunt. Selectors API Level 1. 21 February 2013. REC. URL: https://www.w3.org/TR/selectors-api/