Controlling White Space Characters

This section provides a tutorial example on how to control white space characters in the content of 'block' formatting object. By default, white space characters are collapsed and linefeed chacters are converted to space.

XSL-FO 1.1 offers a number of attributes on "block" formatting objects to control how white space characters in the content should be handled:

Here is my tutorial example, White-Space-Character-Handling.fo, that has 3 "block" formatting objects with different white space character settings:

<?xml version="1.1" encoding="utf-8"?>
<!-- White-Space-Character-Handling.fo
 - Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4.4in" page-width="3.4in">
   <fo:region-body region-name="body"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body">
<fo:block background-color="#ffddff" font-family="monospace"
 font-size="8pt"
> _____________________
|  _________________  |
| |                 | |
| |      0   0      | |
| |        -        | |
| |      \___/      | |
| |_________________| |
|_____________________|
     _|_________|_
    /             \
   -----------------
</fo:block>
<fo:block background-color="#dddddd" font-family="monospace"
 font-size="8pt" linefeed-treatment="preserve"
> _____________________
|  _________________  |
| |                 | |
| |      0   0      | |
| |        -        | |
| |      \___/      | |
| |_________________| |
|_____________________|
     _|_________|_
    /             \
   -----------------
</fo:block>
<fo:block background-color="#ffdddd" font-family="monospace"
 font-size="8pt" linefeed-treatment="preserve"
 white-space-collapse="false" white-space-treatment="preserve"
> _____________________
|  _________________  |
| |                 | |
| |      0   0      | |
| |        -        | |
| |      \___/      | |
| |_________________| |
|_____________________|
     _|_________|_
    /             \
   -----------------
</fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

When you process the above sample XSL-FO document to a PDF file and open it, you will see a big block area that contains some text and two child blocks:

White Space Character Handling

Last update: 2016.

Table of Contents

 About This XSL-FO Tutorial Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

 XSL-FO Document Basics and Examples

 Page Layout Masters

Block-Level Formatting Objects

 What Are Block-Level Formatting Objects?

 What Is "block" Formatting Object?

 "block" Formatting Object Examples

 Margin Collapsed between Block Areas

 space-before/space-after vs. Margin

 Block Splitting for Page Break

 "block" with Mixed Content

Controlling White Space Characters

 What Is "block-container" Formatting Object?

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

 Font Attributes and Font Families

 Apache FOP Font Configurations

 RenderX XEP Font Configurations

 References

 PDF Printing Version