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

Content model definitions 

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

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

  • 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.

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

( ... )
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:

下面是來自 HTML DTD的例子:

   <!ELEMENT UL - - (LI)+>

The UL element must contain one or more LI elements.

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

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

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

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

   <!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文檔的作者應該瞭解如下事實:很多用戶代理(瀏覽器)只能識別最小化形式的布爾型屬性而不能識別完整形式。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章