-
Notifications
You must be signed in to change notification settings - Fork 664
/
Overview.bs
341 lines (277 loc) · 12.9 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<pre class='metadata'>
Title: CSS Namespaces Module Level 3
Group: csswg
Shortname: css-namespaces
Level: 3
Status: ED
Work Status: Completed
ED: https://drafts.csswg.org/css-namespaces/
TR: https://www.w3.org/TR/css3-namespace/
Test Suite: http://test.csswg.org/suites/css3-namespace/20090210/
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Former Editor: Anne van Kesteren, Opera Software ASA
Former Editor: Peter Linss, Netscape Communications
Former Editor: Chris Lilley, W3C
Previous Version: https://www.w3.org/TR/2014/REC-css-namespaces-3-20140320/
Previous Version: https://www.w3.org/TR/2011/REC-css3-namespace-20110929/
Previous Version: https://www.w3.org/TR/2011/PR-css3-namespace-20110811/
Previous Version: https://www.w3.org/TR/2008/CR-css3-namespace-20080523/
Abstract: This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the ''@namespace'' rule for declaring the default namespace and binding namespaces to namespace prefixes, and it also defines a syntax that other specifications can adopt for using those prefixes in namespace-qualified names.
Link Defaults: selectors-4 (dfn) type selectors, css-syntax-3 (dfn) at-rule
Boilerplate: omit footer
</pre>
<!--
<h2 class="no-num no-toc" id="status">Status of this document</h2>
A CSS Namespace <a href="http://www.w3.org/Style/CSS/Test/">Test Suite</a>
has been developed during the Candidate Recommendation phase of this CSS
Namespaces specification. An <a href="/Style/CSS/Test/CSS3/Namespace/20090210/reports/implement-report.html">implementation report</a> is also available.
This document is the same as the previous, Candidate Recommendation
version, except for editorial changes.
<em>W3C asks that members of the W3C Advisory Committee review this
document and fill in the corresponding <a
href="/2002/09/wbs/33280/PR-css3-namespace/" >online form
[member-only].</a> The review closes on 8 September 2011.</em>
-->
<h2 id="intro">
Introduction</h2>
<em>This section is non-normative.</em>
This CSS Namespaces module defines syntax for using namespaces in CSS.
It defines the ''@namespace'' rule for declaring a default namespace
and for binding namespaces to namespace prefixes.
It also defines a syntax for using those prefixes to represent namespace-qualified names.
It does not define where such names are valid or what they mean:
that depends on their context and is defined by a host language,
such as Selectors ([[SELECT]]),
that references the syntax defined in the CSS Namespaces module.
Note that a CSS client that does not support this module will
(if it properly conforms to <a href="https://www.w3.org/TR/CSS21/syndata.html#parsing-errors">CSS's forward-compatible parsing rules</a>)
ignore all ''@namespace'' rules,
as well as all style rules that make use of namespace qualified names.
The syntax of delimiting namespace prefixes in CSS was deliberately chosen
so that these CSS clients would ignore the style rules
rather than possibly match them incorrectly.
<h3 id="terminology">
Terminology</h3>
Besides terms introduced by this specification,
CSS Namespaces uses the terminology defined in Namespaces in XML 1.0. [[!XML-NAMES]]
However, the syntax defined here is not restricted to representing XML element and attribute names
and may represent other kinds of namespaces as defined by the host language.
In CSS Namespaces a namespace name consisting of the empty string
is taken to represent the null namespace
or lack of a namespace.
<div class="example">
For example, given the namespace declarations:
<pre>
@namespace empty "";
@namespace "";
</pre>
The <a>type selectors</a>
<code>elem</code>,
<code>|elem</code>,
and <code>empty|elem</code>
are equivalent.
</div>
<h2 id="declaration">Declaring namespaces: the ''@namespace'' rule</h2>
The <dfn>@namespace</dfn> <a>at-rule</a> declares a namespace prefix
and associates it with a given namespace name (a string).
This namespace prefix can then be used in namespace-qualified names
such as the <a>CSS qualified names</a> defined below.
<div class="example">
<pre>
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";
</pre>
The first rule declares a default namespace
<code>http://www.w3.org/1999/xhtml</code>
to be applied to names that have no explicit namespace component.
The second rule declares a namespace prefix <code>svg</code>
that is used to apply the namespace <code>http://www.w3.org/2000/svg</code>
where the <code>svg</code> namespace prefix is used.
</div>
In CSS Namespaces, as in Namespaces in XML 1.0,
the prefix is merely a syntactic construct;
it is the <dfn export>expanded name</dfn>
(the tuple of local name and namespace name)
that is significant.
Thus the actual prefixes used in a CSS style sheet,
and whether they are defaulted or not,
are independent of the namespace prefixes used in the markup
and whether these are defaulted or not.
<div class="example">
For example, given the following XML document:
<pre>
<qml:elem xmlns:qml="http://example.com/q-markup"></qml:elem>
</pre>
and the following ''@namespace'' declarations at the
beginning of a CSS file:
<pre>
@namespace Q "http://example.com/q-markup";
@namespace lq "http://example.com/q-markup";
</pre>
The selectors ''Q|elem'' and ''lq|elem'' in that CSS file
would both match the element <code><qml:elem></code>.
(The selector ''qml|elem'' would be invalid,
because CSS namespaces only recognize prefixes declared in CSS,
not those declared by the document language.)
</div>
<h3 id="syntax">
Syntax</h3>
The syntax for the ''@namespace'' rule is:
<pre>
@namespace <<namespace-prefix>>? [ <<string>> | <<url>> ] ;
<dfn><namespace-prefix></dfn> = <<ident>>
</pre>
Any ''@namespace'' rules must follow all @charset and @import rules
and precede all other non-ignored at-rules and style rules in a style sheet.
For CSS syntax this adds <code>[ namespace [S|CDO|CDC]* ]*</code>
immediately after <code>[ import [S|CDO|CDC]* ]*</code> in the <code>stylesheet</code> grammar.
A syntactically invalid ''@namespace'' rule
(whether malformed or misplaced)
must be <a href="https://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
A CSS <a href="https://www.w3.org/TR/CSS21/conform.html#style-sheet">style sheet</a> containing an invalid ''@namespace'' rule
is not a <a href="https://www.w3.org/TR/CSS21/conform.html#valid-style-sheet">valid style sheet</a>.
A URI string parsed from the <code>URI</code> syntax must be treated as a literal string:
as with the <code>STRING</code> syntax,
no URI-specific normalization is applied.
All strings--
including the empty string and strings representing invalid URIs--
are valid namespace names in ''@namespace'' declarations.
<h3 id="scope">
Scope</h3>
The namespace prefix is declared only within the style sheet in which its
''@namespace'' rule appears. It is not declared in any style sheets
importing or imported by that style sheet, nor in any other style sheets
applying to the document.
<h3 id="prefixes">
Declaring Prefixes</h3>
A <dfn export>namespace prefix</dfn>, once declared,
represents the namespace for which it was declared
and can be used to indicate the namespace of a namespace-qualified name.
Namespace prefixes are,
<a href="https://www.w3.org/TR/CSS21/syndata.html#counter">like CSS counter names</a>,
case-sensitive.
<!-- They do not, however, distinguish between equivalent
canonical Unicode representations. Essentially, an ''@namespace''
declaration declares all prefixes that map to the same NFC representation as
the given prefix to the same namespace name. (See [[!UNICODE]] for the definition
of NFC normalization.) -->
If in the namespace declaration the namespace prefix is omitted,
then the namespace so declared is the default namespace.
The <dfn export>default namespace</dfn> may apply to names that have no explicit namespace prefix:
modules that employ namespace prefixes must define in which contexts the default namespace applies.
For example, following [[!XML-NAMES]],
in Selectors [[SELECT]] the default namespace applies to type selectors--
but it does not apply to attribute selectors.
There is no default value for the default namespace:
modules that assign unqualified names to the default namespace
must define how those unqualified names are to be interpreted
when no default namespace is declared.
Note: Note that using default namespaces in conjunction with type selectors
can cause UAs that support default namespaces
and UAs that don't support default namespaces
to interpret selectors differently.
If a namespace prefix or default namespace is declared more than once
only the last declaration shall be used.
Declaring a namespace prefix or default namespace more than once is nonconforming.
<h2 id="css-qnames">
CSS Qualified Names</h2>
A <dfn export>CSS qualified name</dfn> is a name explicitly located within (associated with) a namespace.
To form a qualified name in CSS syntax,
a namespace prefix that has been declared within scope is prepended to a local name
(such as an element or attribute name),
separated by a "vertical bar" (<code>|</code>, U+007C).
The prefix, representing the namespace for which it has been declared,
indicates the namespace of the local name.
The prefix of a qualified name may be omitted to indicate that the name belongs to no namespace,
i.e. that the namespace name part of the expanded name has no value.
Some contexts (as defined by the host language)
may allow the use of an asterisk (<code>*</code>, U+002A)
as a wildcard prefix to indicate a name in any namespace,
including no namespace.
<div class="example">
Given the namespace declarations:
<pre>
@namespace toto "http://toto.example.org";
@namespace "http://example.com/foo";
</pre>
In a context where the default namespace applies
<dl>
<dt><code>toto|A</code>
<dd>
represents the name <code>A</code>
in the <code>http://toto.example.org</code> namespace.
<dt><code>|B</code>
<dd>
represents the name <code>B</code>
that belongs to no namespace.
<dt><code>*|C</code>
<dd>
represents the name <code>C</code>
in any namespace,
including no namespace.
<dt><code>D</code>
<dd>
represents the name <code>D</code>
in the <code>http://example.com/foo</code> namespace.
</dl>
</div>
The syntax for the portion of a CSS qualified name before the local name is given below,
both for qualified names that allow wildcard prefixes (<code>wqname</code>)
and for qualified names that disallow wildcard prefixes (<code>qname</code>).
(The syntax uses notation from the <a href="https://www.w3.org/TR/CSS21/grammar.html">Grammar appendix of CSS 2.1</a>. [[!CSS21]]
Note this means that comments, but not white space, are implicitly allowed between tokens.):
<pre>
qname_prefix
: namespace_prefix? '|'
;
wqname_prefix
: [ namespace_prefix? | '*' ] '|'
;
qname
: qname_prefix? ident
;
wqname
: wqname_prefix? ident
;
wqwname
: wqname_prefix? [ ident | '*' ]
;
</pre>
CSS qualified names can be used in (for example)
selectors and property values as described in other modules.
Those modules must define handling of namespace prefixes that have not been properly declared.
Such handling should treat undeclared namespace prefixes as a parsing error
that will cause the selector or declaration (etc.) to be considered invalid
and, in CSS, <a href="https://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
<div class="example">
For example, the Selectors module [[SELECT]] defines a type selector
with an undeclared namespace prefix
to be an invalid selector,
and CSS [[!CSS21]] requires style rules with an invalid selector to be completely ignored.
</div>
<h2 class="no-num" id="changes">
Changes</h2>
Changes made since the <a href="https://www.w3.org/TR/2011/REC-css3-namespace-20110929/">29 September 2011 Recommendation</a>:
<ul>
<li>Added predefined ''qname'', ''wqname'', and ''wqwname'' productions,
to make those constructs easier for other specs to use.
</ul>
<h2 class="no-num" id="acks">
Acknowledgments</h2>
This draft borrows heavily from earlier drafts on CSS namespace support
by Chris Lilley and by Peter Linss
and early (unpublished) drafts on CSS and XML by Håkon Lie and Bert Bos,
and XML Namespaces and CSS by Bert Bos and Steven Pemberton.
Many current and former members of the CSS Working Group have contributed to this document.
Discussions on www-style@w3.org and in other places have also contributed ideas to this specification.
Special thanks goes to
L. David Baron,
Karl Dubost,
Ian Hickson,
Björn Höhrmann,
and Lachlan Hunt
for their comments.
<h2 class=no-num id=privacy>Privacy Considerations</h2>
No new privacy considerations have been reported on this specification.
<h2 class=no-num id=security>Security Considerations</h2>
No new security considerations have been reported on this specification.