Styles

There are four types of styles in Word:

  • Paragraph styles refer to entire paragraphs.

  • Character styles refer to inline contents within a paragraph.

  • Table styles.

  • List styles control the appearance of the lists in all levels.

Most elements which are permitted within the paragraph properties <w:pPr> and the inline formatting <w:rPr> and which have already been introduced, can also be used in styles.

The formatting properties have an effect on all paragraphs, lists, inline markups and tables formatted with these styles.

In the WordML document, the styles of the paragraphs, tables and characters can be found within the <w:styles> container element in the header of the document. The styles for the lists can also be found in the header, but they are enclosed by the <w:lists> element.

All styles used in the text shall be declared in the header. Moreover, Word 2003 tends to define styles not used in the header.

The styles can be edited in the menu Format-> Formatvorlagen und Formatierung (styles and formatting). There, new styles can be generated or already existing ones can be edited.

The following example for paragraph styles shows how the interplay between texts and styles is working. Since all styles can be generated directly in Word 2003 via the appropriate menu, it is not important to know all elements which provide the desired formatting. So, Word 2003 can be used in this example as well as in other contexts to generate the appropriate XML fragments.

image - changing of styles

Figure: changing of styles

Paragraph and character styles

The styles for paragraphs and characters hardly differ with regard to their representation in WordML. The following example shows a paragraph style:

<w:style w:type="paragraph" w:styleId="Unterschrift">  (1)
  <w:name w:val="Signature"/>                          (2)
  <w:basedOn w:val="Standard"/>                        (3)
  <w:rsid w:val="00B52A7C"/>
  <w:pPr>                                              (4)
    <w:pStyle w:val="Unterschrift"/>
    <w:ind w:left="4252"/>
  </w:pPr>
  <w:rPr>                                              (5)
    <w:b/>
  </w:rPr>
</w:style>
...
<w:p>
  <w:pPr>
    <w:pStyle w:val="Unterschrift"/>                   (6)
  </w:pPr>
  <w:r>
    <w:t>Unterschrift <!-- en: Signature --> </w:t>
  </w:r>
</w:p>

(1) The <w:style> element with its child elements and attributes defines a style. The w:type attribute indicates with its values (table, character, list and paragraph) the type of the style. The w:styleId attribute contains a unique ID to which reference is made during a call.

(2) <w:name> indicates a language-independent name of the style. In this example, it is a style from the Normal.dot file. Therefore, the version-independent Signature is used as a name. When opening the file in an Office programme using another language, the name being standard in this language is used.

If the style is not stored in the Normal.dot file, the name indicated in the example is displayed in the style list.

(3) <w:basedOn> indicates an inheritance. Here, all formatting properties of the Standard style are used and, where appropriate, overwritten.

(4) All indications within this <w:pPr> element are adopted as formatting in the paragraphs which call up this style. Here, also other styles can be called up. Curiously, always the own style is deposited as a call <w:pStyle w:val="Unterschrift"/>.

(5) In addition to paragraph formattings, also inline formattings may occur with the <w:rPr> element.

(6) The style is called up with <w:pStyle> whose attribute value of the w:val attribute refers to the ID of the paragraph style.

Default styles

In each WordML document you can define a paragraph style and a table style as default. These styles do not have to be called up explicitly for each used paragraph, but are always used if no explicit application of a style is entered.

<w:style w:type="paragraph" w:default="on" w:styleId="Standard">
...
</w:style>

You can determine a style as default by using the w:default attribute.

Default font

WordML supports the definition of a default font with the <w:defaultFonts> element. If no font has been determined in a style or in a direct formatting, the default font is used. In this way, indications on the font to be used can be managed at a central point.

<w:fonts>
 <w:defaultFonts w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman"/>
 

Inheritance of styles

In WordML styles can adopt properties of an already defined style by using the <w:basedOn> element.

The following example shall demonstrate the use of the <w:basedOn> element:

<w:style w:type="paragraph" w:default="on" w:styleId="Standard">
  <w:name w:val="Normal"/>
  <wx:uiName wx:val="Standard"/>
  <w:rsid w:val="00B52A7C"/>
  <w:rPr>
    <w:sz w:val="24"/>
    <w:sz-cs w:val="24"/>
    <w:b/>
    <w:lang w:val="DE" w:fareast="DE" w:bidi="AR-SA"/>
  </w:rPr>
</w:style>
<w:style w:type="paragraph" w:styleId="Anrede">
  <w:name w:val="Salutation"/>
  <wx:uiName wx:val="Anrede"/>
  <w:basedOn w:val="Standard"/>                          (1)
  <w:rsid w:val="00B52A7C"/>
  <w:pPr>
    <w:pStyle w:val="Anrede"/>
  </w:pPr>
  <w:rPr>
    <w:sz w:val="48"/>                                   (2)
    <w:sz-cs w:val="48"/>
  </w:rPr>
</w:style>

(1) The <w:basedOn> element refers with its w:val attribute to the style with the Standard ID. All properties defined in this style are transfered to the Anrede (Salutation) style including the font size and the bold type.

(2) Here, the font size changed in relation to the Standard style has priority. The inheritance of formatting properties always refers to not explicitly indicated properties.

The following situation arises with regard to the inheritance of properties in the text to be formatted: a text (except for lists) may contain formatting properties about:

  • direct formatting in the running text properties <w:rPr> or

  • direct formatting in the paragraph properties <w:pPr>,

  • the assignment of a character style,

  • the assignment of a paragraph style,

  • the assignment of a style which has inherited properties of another style via the <w:basedOn> element.

The following example demonstrates the ranking of the formatting possibilities:

<w:style w:type="paragraph" w:styleId="Ebene1">
  <w:name w:val="Ebene1"/>
  <w:basedOn w:val="Standard"/>
  <w:rPr><w:sz w:val="20"/></w:rPr>
</w:style>
<w:style w:type="paragraph" w:styleId="Ebene2">
  <w:name w:val="Ebene2"/>
  <w:basedOn w:val="Ebene1"/>
  <w:rPr><w:sz w:val="40"/></w:rPr>
</w:style>
<w:style w:type="character" w:styleId="Ebene3">
  <w:name w:val="Ebene3"/>
  <w:basedOn w:val="Ebene2"/>
  <w:rPr><w:sz w:val="60"/></w:rPr>
</w:style>
...
<w:p>
  <w:pPr><w:pStyle w:val="Ebene1"/></w:pPr>
  <w:r><w:t>Ebene1 <!-- en: Level 1 --> </w:t></w:r>
</w:p>
<w:p>
  <w:pPr><w:pStyle w:val="Ebene2"/></w:pPr>
  <w:r><w:t>Ebene2</w:t></w:r>
</w:p>
<w:p>
  <w:pPr><w:pStyle w:val="Ebene2"/></w:pPr>
  <w:r>
    <w:rPr><w:rStyle w:val="Ebene3"/></w:rPr>
    <w:t>Ebene3</w:t>
  </w:r>
</w:p>
<w:p>
  <w:pPr><w:pStyle w:val="Ebene2"/></w:pPr>
  <w:r>
    <w:rPr>
      <w:rStyle w:val="Ebene3"/>
      <w:sz w:val="100"/>
    </w:rPr>
    <w:t>Ebene4</w:t>
  </w:r>
</w:p>

image - inheritance of styles

Figure: inheritance of styles

In general, the following rules apply for the ranking of inherited properties:

  1. Direct formatting has priority over styles.

  2. Character styles have priority over paragraph styles.

  3. Styles which adopt properties of other styles via the <w:basedOn> element have priority over these.

<< back next >>

 


Copyright © dpunkt.verlag GmbH 2007
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "Professionelle XML-Verarbeitung mit Word" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo(at)dpunkt.de