1. Technology

How to Write Blocks in XSL-FO

Understanding XSL-FO – Part 6

By

Writing the element block in XSL-FO is one of the most influential tools you have to control the appearance of the output page. A block section takes the data and applies formatting to it. This is where you decide to display your inventory in a table or to make a list of your services. Block sections contain the data you want the viewers to see and designs how they see it. Understanding how to write blocks in XSL-FO will help you create dynamic and smart pages for your website utilizing XML.

Page-Sequence

Page-sequence is the parent element of the component flow. Page-sequence attaches the master-name from the layout-master-set to this template. This way the browser can connect the formatting dots. The processor knows this template has a name and what instructions from other sections, such as layout-master-set, go with it.

<fo:layout-master-set>
<fo:simple-page-master master-name="myPageone">
</fo:simple-page-master>
</layout-master-set>
<fo:page-sequence master-reference="myPageone">

The output stream is segregated by sections, or regions. By using regions to place data on a page, you can position the information. The job of positioning belongs to the child element flow. Flow assign regions to the template and places the block section inside.

<fo:page-sequence master-reference="myPageone">
<fo:flow flow-name="xsl-region-body">

If you are confused about regions, go back to Part 2 of this series and read Breaking Down the Regions of XSL-FO Formatting. Page-sequence connects the template name to the master-reference, flow assigns the positioning. The element block nests inside flow and contains the data and formatting instructions specific to that data.

<fo:page-sequence master-reference="myPageone">
<fo:flow flow-name="xsl-region-body">
<fo:block>

With block, you to create space, margins, borders, backgrounds, and fonts that apply to the presentation of the information contained within the element tags. All the formatting specifics are attributes to block.

<fo:block font-size="14pt" font-family="arial" color="green" >
Hello World!
</fo:block>

Create different blocks for different looks to highlight sections of information. For example, if creating an inventory, set up a separate block as a section header.

<fo:block font-size="18pt" font-family="verdana" color="red" space-after="10mm">
Table Lamps
</fo:block>

This code creates a title that appears in a different font and size than the inventory listing. You assign whitespace under the heading by using space-after. This will further enhance the title and divide it from the list. Create a separate block for every section to give your page substance and style.

Attributes to the Block Element

The formatting attributes start with the design point you want to assign, such as font, text, background, border, padding or space. Add a ‘-’ after the point name and fix the specifics to the attribute.

  • font-size
  • text-align
  • background-color
  • border-style

Page-sequence allows you to develop the page and create a view to display your information for each template. Within the page template, you can isolate sections and control the presentation using block and then assign style within the block using attributes. The data you want to display sits inside the block opening and closing tags.

©2014 About.com. All rights reserved.