HTML.and.XHTML.The.Complete.Reference.4th.Edition [Electronic resources]

Thomas Powell

نسخه متنی -صفحه : 252/ 219
نمايش فراداده

Parameter Entities

An entity is essentially a macro that allows a short name to be associated with replacement text. Parameter entities define replacement text used in DTD declarations. Syntactically, a parameter entity is distinguished by using the percent (%) symbol. Its general form is shown here:

<!ENTITY % name "replacement text">

It is used in DTDs as follows:

%name;

Parameter entities are a convenient way to define commonly occurring pieces of a DTD so that changes only need to be made in one place. We see in XHTML a parameter entity to define the core attributes common to most elements.

<!ENTITY % coreattrs
 "id          ID             #IMPLIED
  class       CDATA          #IMPLIED
  style       %StyleSheet;   #IMPLIED
  title       %Text;         #IMPLIED"
>

Notice that entity %coreattrs further references entities (%StyleSheet; and %Text;) to define values for the style and title attributes. Once defined, the core attributes could be added to an attribute list declaration for an element, as follows:

<!ATTLIST some-element  %coreattrs;>

Oftentimes, you will see entities that in turn contain further entities. For example, under HTML 4.0 the coreattrs parameter entity is used with the %i18n and events parameter entities to define the expansion text for an aggregate entity called attrs.

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