Text blocks

In this example text blocks whose characteristics are controlled by the instance are generated.

Here, a template for the generation of texts blocks is demonstrated. These blocks can be formatted by the instance with the help of attributes.
So, in this example, characteristics as font size, alignment, indents, bold, italic etc. are determined.

Excerpt from the DTD:

<!ELEMENT TB (#PCDATA | ...)*>
     Size (normal | large | small) "normal"
     Font (normal | bold | italic) "normal"
     Alignment (left | right | center | justify) "justify"
     IndentLeft (without | with | line1 | hanging) "without">


<xsl:template match="TB"> 
   <fo:block text-align="justify" hyphenate="true" xml:lang="en"           ❶
         <xsl:when test="@Size='large'">                                   ❷
            <xsl:attribute name="font-size">14pt</xsl:attribute>           ❸
         <xsl:when test="@Size='small'"> 
            <xsl:attribute name="font-size">10pt</xsl:attribute>
         <xsl:otherwise>                                                   ❹   
            <xsl:attribute name="font-size">12pt</xsl:attribute>
         <xsl:when test="@Font='bold'">                                    ❺
            <xsl:attribute name="font-weight">bold</xsl:attribute>
         <xsl:when test="@Font='italic'">
            <xsl:attribute name="font-style">italic</xsl:attribute>
         <xsl:otherwise/>                                                  ❻
         <xsl:when test="@Alignment='left'">
            <xsl:attribute name="text-align">left</xsl:attribute>
         <xsl:when test="@Alignment='right'"> 
            <xsl:attribute name="text-align">right</xsl:attribute>
         <xsl:when test="@Alignment='center'">
            <xsl:attribute name="text-align">center</xsl:attribute>
            <xsl:attribute name="text-align">justify</xsl:attribute>
         <xsl:when test="@IndentLeft='with'">
            <xsl:attribute name="margin-left">15mm</xsl:attribute>
         <xsl:when test="@IndentLeft='line1'">
            <xsl:attribute name="text-indent">10mm</xsl:attribute>
         <xsl:when test="@IndentLeft='hanging'">
            <xsl:attribute name="text-indent">-10mm</xsl:attribute> 


❶ Universally valid attributes are specified for the block: justification, English hyphenation, left indent.

❷ The further specification depends on the attributes and their values. The whole is embedded in the <xsl:choose> XSLT concept.

❸ Under the condition that the font size is large, the font size 14pt shall be set.

❹ Under the condition that the font size is normal or if the attribute is not set in the instance (because it is the default value), the font size 12pt is valid.

❺ The same as mentioned for the font size applies accordingly.

❻ The same as mentioned for the default value of the font size applies accordingly. Here, no attribute is specified. Therefore, <xsl:otherwise> stays empty.

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") 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@dpunkt.de