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