Linked Styles
The next type of style definition, linked styles are actually a paired combination of styles which can be applied to the contents of one or more runs of text within a document’s contents or the entire contents of one or more paragraphs in a WordprocessingML document. This definition implies that the style can define both a set of character properties (properties which apply to text within a paragraph) as well as a set of paragraph properties (properties which apply to the positioning and appearance of the paragraph) because it must be possible to apply the style to paragraphs as well as characters.
In order to accomplish these dual uses, a linked style is actually a pairing of a paragraph style and a character style in the WordprocessingML document. Each style exists uniquely within the styles part, but are linked by the <link>
element, which specifies that these styles are each half of a linked style definition and should be treated as one style at runtime.
A typical example of the use of a linked style is a quote style - if the style is applied to a paragraph, the quoted text should be indented additionally to create a block quote effect, but if the style is applied to text in a paragraph, only the character level effects should be applied.
Consider the following two styles which comprise a linked style pairing:
<w:style w:type="paragraph" w:styleId="TestLinkedStyle"> <w:name w:val="Test Linked Style"/> <w:link w:val="TestLinkedStyleChar"/> <w:qformat/> <w:rsid w:val="009C1646"/> <w:pPr> <w:spacing w:line="480" w:lineRule="auto"/> <w:ind w:left="1440"/> </w:pPr> <w:rPr> <w:rFonts w:ascii="Arial" w:hAnsi="Arial"/> <w:color w:val="22B14C"/> </w:rPr> </w:style> <w:style w:type="character" w:styleId="TestLinkedStyleChar"> <w:name w:val="Test Linked Style Char"/> <w:link w:val="TestLinkedStyle"/> <w:rsid w:val="009C1646"/> <w:rPr> <w:rFonts w:ascii="Arial" w:hAnsi="Arial"/> <w:color w:val="22B14C"/> </w:rPr> </w:style>
The <link>
element in the paragraph style specifies TestLinkedStyleChar
, the @styleId
of the paired character style, and the <link>
element in the character style specifies TestLinkedStyle
, the @styleId
of the paired paragraph style, creating a linked style combination.
Paragraph-level instances of linked styles can only be referenced by paragraphs within a document, and they must be referenced by the <pStyle>
element within the paragraph’s paragraph properties element (<pPr>
), which must referrence the paragraph version of the linked style. Character-level instances of linked styles can only be referenced by a run's run properties element (<rPr>
) within a document, and they must be referenced by the <rStyle>
element within the run properties element which must reference the character version of the linked style.
Consider a linked style titled "Test Linked Style" which defines; font = Arial, font color = green; paragraph spacing = double, indent = 1” left. The resulting style definitions would be:
<w:style w:type="paragraph" w:styleId="TestLinkedStyle"> <w:name w:val="Test Linked Style"/> <w:link w:val="TestLinkedStyleChar"/> <w:qformat/> <w:rsid w:val="009C1646"/> <w:pPr> <w:pStyle w:val="TestLinkedStyle"/> <w:spacing w:line="480" w:lineRule="auto"/> <w:ind w:left="1440"/> </w:pPr> <w:rPr> <w:rFonts w:ascii="Arial" w:hAnsi="Arial"/> <w:color w:val="22B14C"/> </w:rPr> </w:style> <w:style w:type="character" w:styleId="TestLinkedStyleChar"> <w:name w:val="Test Linked Style Char"/> <w:link w:val="TestLinkedStyle"/> <w:rsid w:val="009C1646"/> <w:rPr> <w:rFonts w:ascii="Arial" w:hAnsi="Arial"/> <w:color w:val="22B14C"/> </w:rPr> </w:style>
Notice that the linked style definition is composed of the paragraph style, which specifies both the run and paragraph properties, and the character style, which specifies only the run properties. The document content for a paragraph with this linked style would be:
<w:p> <w:pPr> <w:pStyle w:val="TestLinkedStyle"/> </w:pPr> <w:r> <w:t xml:space="preserve">A para version of Test Linked Style.</w:t> </w:r> </w:p>
The <pStyle>
element in the paragraph’s properties links the paragraph with the paragraph version of the linked style definition.
The document content for a paragraph with a run of this linked style would be:
<w:p> <w:r> <w:t xml:space="preserve">Next run is character version of </w:t> </w:r> <w:r> <w:rPr> <w:rStyle w:val="TestLinkedStyleChar"/> </w:rPr> <w:t>Test Linked Style</w:t> </w:r> <w:r> <w:t>.</w:t> </w:r> </w:p>
The <rStyle>
element in the second run’s properties links the run with the character version of the linked style definition.