Stylesheet features

Typically, stylesheets attempt to accomplish a number of tasks, including styling the text, adding template text, reordering and moving content, and styling text differently depending on the current context.

Style

The one thing that all stylesheets should be able to achieve is to apply stylistic information to the text of a document. This includes the shape of the characters (the font used), the size of the characters (the point size), style variants (including bold, italic and small caps), underlining and the use of colour.

In addition, they should be able to distinguish between in-line styles and block styles. An in-line object does not break the flow of words (the bold words in this paragraph are in-line styles). But when an element is identified as a block element, its contents are separate from surrounding blocks. Titles and paragraphs, for example, are separated from each other. Formatting instructions should be able to specify the size of the gaps between block objects, and perhaps allow border lines to be drawn around them.

Template text

When documents are encoded in XML, it is advisable to omit information that never varies. This can be described as 'template' text. For example, if every paragraph that would normally begin with the word 'CAUTION' is tagged using a Caution element, there is no need to include this word in the content of the element. Instead, it can be generated automatically when the Caution element is presented. This approach reduces the size of the document and the effort involved in data entry, but also gives the stylesheet developer more options. For example, in one rendition the word 'CAUTION' may be deemed redundant, because the warning text is to be presented in bold, italic lettering:

<caution>This is a caution</caution>


      This is a caution

In another rendition, the word may be added, and perhaps given a different style to the content:

CAUTION

This is a caution


Whole document fragments may need to be inserted by the stylesheet, such as a standard preamble that describes the publishing organization. This also applies to header and footer text (such as 'The XML Companion' in this book).

Reordering and reusing

The order in which components of a document are to be presented may not always be the same as the order in which they were created. The needs of the ultimate readers of the document may be very different to those of the document authors and editors. In addition, information in documents aimed at different audiences may need to be omitted in some cases, or moved to a more (or less) prominent position in others. In the following example, the summary is moved to the top, and the secret paragraph is omitted from the presentation:

<para>This is the FIRST paragraph.</para>
<secret>Not everyone can read this.</secret>
<summary>This summary may appear first
in some cases.</summary>


      This summary may appear first in some cases.
      This is the FIRST paragraph.

When the XML philosophy has been rigorously applied, redundancy is avoided by omitting material that already appears elsewhere. Many stylesheet languages are able to copy information to other parts of the document presentation. For example, if a book review contains a number of keywords, marked up within the review text, it would be wasteful (and also error-prone) to repeat these keywords in a summary at the top:

<book>
  <review>This book covers <kw>XML</kw> and <kw>XSL</kw>,
  as well as the <kw>CSS</kw> styling language.</review>
  ...
</book>


     KEYWORDS: XML, XSL, CSS

     This book covers XML and XSL, as well as the CSS styling
     language.

The ability to reuse and sort information can also be very useful for building table of contents lists.

Context-specific formatting

The same element type may need to be presented in a number of different ways, depending on the location of each specific instance of that element within the document. For example, the content of a Paragraph element may need to be presented in larger text than normal if that instance of the element appears within an introduction section, or bolder if it occurs inside a Warning element. Most stylesheet languages can detect the current context and select the formatting that applies in that context.

However, conflicting context specifications may arise when the current element is deeper than two levels in the document hierarchy. For example, if there is a formatting rule for paragraphs in introductions, and another rule for paragraphs within Warning elements, then it is not clear what should happen when a paragraph appears in a Warning element that is inside an Introduction element:

<para>Normal paragraph. No context applies.</para>
<warning>
  <para>Paragraph in Warning.</para>
</warning>
<intro>
  <para>Paragraph in Introduction</para>
  <warning>
    <para>Paragraph in Warning and Introduction.</para>
  </warning>
						</intro>
					

In order to avoid such conflicts, some rules need to be given a higher priority than others. Much of the effort and skill involved in developing stylesheets centres on ensuring that the correct rule is used in every circumstance.

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

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