HTML4.01規範中英文對照-有關SGML和HTML的一些事(2)

Content model definitions 

The content model describes what may be contained by an instance of an element type. Content model definitions may include:html

內容模型描述了什麼能夠被一個元素類型的實例所包含。內容模型定義能夠包含以下信息:瀏覽器

  • The names of allowed or forbidden element types (e.g., the UL element contains instances of the LI element type, and the P element type may not contain other P elements).
  • 容許或者禁止出現的元素類型的名字(例如:UL元素包含LI元素類型的實例,P元素類型不能夠再包含其餘的P元素)。
  • DTD entities (e.g., the LABEL element contains instances of the "%inline;" parameter entity).
  • DTD實體(例如:LABEL元素能夠包含全部參數實體"%inline"型的實例)。
  • Document text (indicated by the SGML construct "#PCDATA"). Text may contain character references. Recall that these begin with & and end with a semicolon (e.g., "Hergé's adventures of Tintin" contains the character entity reference for the "eacute" character).
  • 文檔文本(採用SGML基礎構件"#PCDATA"表示)。文本能夠包含字符引用。回憶一下:字符引用是以"&"開開始以分號結束(例如: "Hergé's adventures of Tintin"包含了對"eacute"字符的字符實體引用)。

The content model of an element is specified with the following syntax. Please note that the list below is a simplification of the full SGML syntax rules and does not address, e.g., precedences.app

元素的內容模型要採用下面的語法來進行描述。請注意下面的列表只是SGML語法規則全集的簡化版本,並不涉及好比優先級等其餘複雜規則。ide

( ... )
Delimits a group.
界定一個組。
A
A must occur, one time only.
A必須出現而且這能出現一次。

A+
A must occur one or more times.
A至少出現一次。
A?
A must occur zero or one time.
A不出現或只出現一次。
A*
A may occur zero or more times.
A能夠不出現後者能夠出現任意屢次。
+(A)
A may occur.
A能夠出現。

-(A)
A must not occur.
A必須不出現。
A | B
Either A or B must occur, but not both.
A和B必須出現,但不能同時出現。
A , B
Both A and B must occur, in that order.
A和B必須出現而且按照指定的前後順序出現。
A & B
Both A and B must occur, in any order。
A和B必須出現,順序隨意。

Here are some examples from the HTML DTD:ui

下面是來自 HTML DTD的例子:this

   <!ELEMENT UL - - (LI)+>

The UL element must contain one or more LI elements.spa

UL元素必須至少包含一個LI元素代理

   <!ELEMENT DL    - - (DT|DD)+> 

The DL element must contain one or more DT or DD elements in any order.code

DL元素必須包含一個以上(含一個)DT或DD元素,DT和DD元素的順序隨意。orm

   <!ELEMENT OPTION - O (#PCDATA)> 

The OPTION element may only contain text and entities, such as &amp; -- this is indicated by the SGML data type #PCDATA.

根據SGML對#PCDATA的定義,OPTION 元素僅能包含文本和相似於&amp;的實體。

A few HTML element types use an additional SGML feature to exclude elements from their content model. Excluded elements are preceded by a hyphen. Explicit exclusions override permitted elements.

少數幾個元素類型爲了能夠將某些元素從他們的內容中清除出去,他們使用了附加的SGML特性。被排除的元素以連詞符爲前綴。顯式排除規則覆蓋容許的規則。

In this example, the -(A) signifies that the element A cannot appear in another A element (i.e., anchors may not be nested).

在下面的例子中,-(A)指明瞭A不能再另一個A元素中出現(例如:錨定點不能嵌套)。

   <!ELEMENT A - - (%inline;)* -(A)> 

Note that the A element type is part of the DTD parameter entity "%inline;", but is excluded explicitly because of -(A).

請注意,A元素類型是DTD參數實體"%inline"的一部分,可是經過顯式的排除方式-(A)將其從容許的集合中去掉了。

Similarly, the following element type declaration for FORM prohibits nested forms:

相似的,下面的FORM元素類型聲明中禁止了嵌套的FORM。

   <!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM)>

3.3.4 Attribute declarations

The <!ATTLIST keyword begins the declaration of attributes that an element may take. It is followed by the name of the element in question, a list of attribute definitions, and a closing >. Each attribute definition is a triplet that defines:

元素可以擁有的屬性聲明以關鍵字<!ATTLIST開始。後接屬於的元素名以及屬性定義列表,最後以>結束。每個屬性定義都是一個三段式結構:

  • The name of an attribute.
  • 屬性名稱。
  • The type of the attribute's value or an explicit set of possible values. Values defined explicitly by the DTD are case-insensitive. Please consult the section on basic HTML data types for more information about attribute value types.
  • 屬性值的類型或者是容許取值的集合。在DTD中顯式定義的取值是大小寫不敏感。對於關於屬性值類型的更多信息請參閱《HTML基礎數據類型》部分。
  • Whether the default value of the attribute is implicit (keyword "#IMPLIED"), in which case the default value must be supplied by the user agent (in some cases via inheritance from parent elements); always required (keyword "#REQUIRED"); or fixed to the given value (keyword "#FIXED"). Some attribute definitions explicitly specify a default value for the attribute.
  • 屬性的缺省值是不是隱含的(關鍵字"#IMPILED"),若是是隱含的狀況,那麼用戶代理就必須爲屬性提供缺省值,好比在有些狀況下是繼承自父元素。屬性值是不是必須的(關鍵字 "#REQUIRED");屬性值是不是固定的(關鍵字"#FIXED")。有些屬性的定義會明確的給出這個屬性的缺省值。

In this example, the name attribute is defined for the MAP element. The attribute is optional for this element.

下面的例子是爲MAP元素定義的name屬性。該屬性對於該元素來說是可選的。

<!ATTLIST MAP
  name        CDATA     #IMPLIED
  >

The type of values permitted for the attribute is given as CDATA, an SGML data type. CDATA is text that may contain character references.

在上面的例子中name屬性容許的取值爲CDATA型,CDATA是一種SGML數據類型。它是一個能夠包含字符引用的文本。

For more information about "CDATA", "NAME", "ID", and other data types, please consult the section on HTML data types.

關於"CDATA","NAME","ID"以及其餘數據類型的更多信息,請參閱HTML數據類型部分。

The following examples illustrate several attribute definitions:

下面的例子列舉了幾個屬性定義情形:

rowspan     NUMBER     1         -- number of rows spanned by cell --

http-equiv  NAME       #IMPLIED  -- HTTP response header name  --

id          ID         #IMPLIED  -- document-wide unique id -- 

valign      (top|middle|bottom|baseline) #IMPLIED

The rowspan attribute requires values of type NUMBER. The default value is given explicitly as "1". The optional http-equiv attribute requires values of type NAME. The optional id attribute requires values of type ID. The optional valign attribute is constrained to take values from the set {top, middle, bottom, baseline}.

rowspan 屬性要求NUMBER類型的值。它的缺省值顯式定義爲"1"。可選的http-equiv屬性要求NAME類型的值。可選的id屬性要求ID類型的值。可選的valign屬性被限制成只能是{top, middle, bottom, baseline}集合中的值。

DTD entities in attribute definitions

屬性定義中的DTD實體

Attribute definitions may also contain parameter entity references.

屬性定義中一樣能夠包含參數實體的引用。

In this example, we see that the attribute definition list for the LINK element begins with the "%attrs;" parameter entity.

在下面的例子中,咱們能夠看到LINK元素的屬性定義列表是以參數實體"%attrs"開頭的。

<!ELEMENT LINK - O EMPTY               -- a media-independent link -->
<!ATTLIST LINK
 %attrs;                              -- %coreattrs, %i18n, %events --
  
 charset     %Charset;      #IMPLIED  -- char encoding of linked resource --
 href        %URI;          #IMPLIED  -- URI for linked resource --

 hreflang    %LanguageCode; #IMPLIED  -- language code --

 type        %ContentType;  #IMPLIED  -- advisory content type --
  
 rel         %LinkTypes;    #IMPLIED  -- forward link types --

 rev         %LinkTypes;    #IMPLIED  -- reverse link types --
 media       %MediaDesc;    #IMPLIED  -- for rendering on these media --
  >

Start tag: required, End tag: forbidden

The "%attrs;" parameter entity is defined as follows:

參數實體"%attrs;"的定義以下:

<!ENTITY % attrs "%coreattrs; %i18n; %events;">

The "%coreattrs;" parameter entity in the "%attrs;" definition expands as follows:

"%attrs;"中的參數實體"%coreattrs;"的定義以下:

<!ENTITY % coreattrs

 "id          ID             #IMPLIED  -- document-wide unique id --
  
class       CDATA          #IMPLIED  -- space-separated list of classes --

  style       %StyleSheet;   #IMPLIED  -- associated style info --
  
title       %Text;         #IMPLIED  -- advisory title --
"
  >

The "%attrs;" parameter entity has been defined for convenience since these attributes are defined for most HTML element types.

參數實體"%attrs"定了了絕大多數HTML元素類型都須要的屬性,它能夠被用來簡化DTD的書寫和組織。

Similarly, the DTD defines the "%URI;" parameter entity as expanding into the string "CDATA".

相似的,DTD定義了"%URI"參數實體做爲一個"CDATA"字符串。

<!ENTITY % URI "CDATA"
    -- a Uniform Resource Identifier,
       see [URI]
    -->

As this example illustrates, the parameter entity "%URI;" provides readers of the DTD with more information as to the type of data expected for an attribute. Similar entities have been defined for "%Color;", "%Charset;", "%Length;", "%Pixels;", etc.

做爲驗證的例子,參數實體"%URI"給讀者提供了更多的關於屬性值數據類型的信息。類似的實體還有:"%Color;", "%Charset;", "%Length;", "%Pixels;"等

Boolean attributes

布爾型屬性

Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

有一些屬性充當布爾變量,例如:OPTION元素selected屬性。若是他們出如今元素的開始標籤中就意味着這個屬性的值是"true",相反若是不出現就意味着屬性取值爲"false"。

Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").

布爾型屬性原則上能夠有一個單一的值:屬性自己的名字(例如:selected="selected")。

This example defines the selected attribute to be a boolean attribute.

下面的例子是把selected的屬性定義爲布爾型屬性。

selected     (selected)  #IMPLIED  -- option is pre-selected --

The attribute is set to "true" by appearing in the element's start tag:

經過將該屬性放置在元素的開始標籤中,該屬性的值被設置爲"true":

<OPTION selected="selected">
...contents...
</OPTION>

In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:

在HTML語境中,布爾型屬性能夠採用最小化形式來表述——只須要在元素的開始標籤中出現屬性值。在這樣的背景下,selected能夠經過下嗎的寫法來設定"true":

<OPTION selected>

而無需使用以下寫法:

<OPTION selected="selected">

Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.

HTML文檔的做者應該瞭解以下事實:不少用戶代理(瀏覽器)只能識別最小化形式的布爾型屬性而不能識別完×××式。
相關文章
相關標籤/搜索