XSL-FO Tutorials - Herong's Tutorial Examples - Version 2.10, by Dr. Herong Yang
"float" Formatting Object Moving to Top
This section provides a tutorial example on how to use a 'float' formatting object to move a block area to the top edge of the page. This will reduce the height of the region-body content area on the page.
The "float" formatting object can also be used to float a block area to the "before" edge of the page in a hidden sub-region called "xsl-before-float" of the page layout. This is called before-float and done by specifying the float="before" attribute in the "float" formatting object
A before-float is different than a side-float in several ways:
Here is my tutorial example, Float-Block-to-the-Top.fo, that has a "float" formatting object floating to the "before" edge of the page:
<?xml version="1.0" encoding="utf-8"?> <!-- Float-Block-to-the-Top.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.08in" page-height="3in" page-width="2.5in"> <fo:region-body region-name="body" background-color="#eeeeee"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="page"> <fo:flow flow-name="body"> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> Appeared in English Fairy Tales by Joseph Jacobs, first published in 1890. </fo:block> <fo:block margin="0.08in" font-size="10pt"> The Three Little Pigs </fo:block> <fo:float float="before"> <fo:block margin="0in" padding="0.08in" font-size="8pt" border-width="1px" border-style="solid" background-color="#ffeeff" text-align="justify"> "Little pig, little pig, let me come in". "No, no, no by the hairs of my chinny chin chin I will not let you in". </fo:block> </fo:float> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> Once upon a time there was not one, not two but three little pigs who lived with their mother. Early one morning they woke up and their mother said "you're too big for this house and it is time you left home." </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> So they walked and they walked and they walked. The first little pig made a house out of straw. Unfortunately, a wolf came creeping by. </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> "Little pig, little pig, let me come in". "No, no, no by the hairs of my chinny chin chin I will not let you in". "Then I'll huff and I'll puff and I'll blow your house down". So the wolf huffed and he puffed and he blew the house down. </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> So the first little pig ran away to find his brothers. </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> Next the second little pig made a house out of sticks. Unfortunately, a wolf came creeping by. </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> "Little pig, little pig, let me come in". "No, no, no by the hairs of my chinny chin chin I will not let you in". "Then I'll huff and I'll puff and I'll blow your house down". So the wolf huffed and he puffed and he blew the house down. </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
Since Apache FOP 2.1 does not support "float" formatting objects, you need to use RenderX XEP to process the above example. The resulting PDF file has 2 pages as shown in the picture below:
As you can see in the picture, the before-float block is floated to the "before" edge of the page. But it is floated to the second page instead of the first page, where I coded the "float" formatting object.
Last update: 2016.
Table of Contents
About This XSL-FO Tutorial Book
Apache™ FOP (Formatting Objects Processor)
XSL-FO Document Basics and Examples
Block-Level Formatting Objects
Inline-Level Formatting Objects
Including Graphics in XSL-FO document
►Floating Blocks - "float" and "footnote"
What Is "float" Formatting Object?
"float" Formatting Object Shifting to Left
clear="..." - Block Cleared from Side-Float
►"float" Formatting Object Moving to Top
Adding "xsl-before-float" Separator
Adding "xsl-footnote" Separator
Hyperlinks, Table of Contents and Indexes
Headers and Footers using "static-content"
Font Attributes and Font Families
Apache FOP Font Configurations