Block and in-line elements

When formatting text, the concept of 'block' and 'in-line' elements is an important distinction. Block elements have content that is to be separated from neighbouring blocks, usually by starting a new line and by creating a gap above and below the block. Titles and paragraphs are typical examples. The XSL 'block' property is used to create a new block (and the DIV element can be used in an HTML document). In-line elements have content that is to be simply appended to previous text, without creating a new line. Bold and italic phrases are typical examples. The XSL 'inline-sequence' property is used to create an new in-line region (and the SPAN element can be used in an HTML document). It is possible to identify block and in-line elements from studying the DTD content models.

It is important to discover which elements are block elements, and which are in-line elements, not only to apply appropriate formatting to them but simply because they are the elements that are most likely to require templates to be defined for them.

Text content

Both block and in-line elements share a common property; they may directly contain text. Elements that directly contain text are in any case good candidates for requiring a template, as this is the last chance to define a style for the embedded characters.

The #PCDATA keyword in the content model indicates this possibility. The 'Emph' element defined below is allowed to contain only text:

<!ELEMENT Emph (#PCDATA)>


   <Emph>This is important text.</Emph>

When the definition includes other elements as well, further templates will probably be needed to cater for the text content of these other elements:

<!ELEMENT Emph (#PCDATA|Important)>


   <Emph>This is <Important>not</Important> very important
   text.</Emph>


This is not very important text.

In-line elements

In-line elements can be detected by studying the model for the parent element(s). If the parent element is allowed to contain text, as well as the given element, then it is almost certainly an in-line element. The Important element below is an in-line element:

<!ELEMENT Para (#PCDATA|Important)>

<!ELEMENT Important (#PCDATA)>

The case is strengthened further if the given element may itself directly contain text, as in the example above.

Some in-line elements may be present only for the purposes of allowing the enclosed text to be located (for searching purposes, for extraction and reuse, or for some other purpose), so it cannot automatically be assumed that the content needs to be styled in some way, though this is usually the case.

Block elements

Block elements are elements that can directly contain text but are not themselves used within other elements that can directly contain text. The Title and Para elements described above are good examples of this type. In the example above, they are used in Chapter and Book elements, which cannot contain text.

<!ELEMENT Chapter (Title, Para*)>

<!ELEMENT Para (#PCDATA|Important)>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset