XSL-FO Tutorials - Herong's Tutorial Examples - v2.24, by Herong Yang
Table Column and Row Merge or Span
This section provides a tutorial example on how to merge or span table columns and rows with table-cell[@number-columns-spanned] and/or table-cell[@number-rows-spanned] attributes.
If you want to merge table cells, you need to use table-cell[@number-columns-spanned] and/or table-cell[@number-rows-spanned] attributes, as shown in the following XSL-FO example, Table-Column-and-Row-Span.fo:
<?xml version="1.0" encoding="utf-8"?> <!-- Table-Column-and-Row-Span.fo - Copyright (c) 2006 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="5in" page-width="5in"> <fo:region-body region-name="body" background-color="#eeffff"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="page"> <fo:flow flow-name="body"> <fo:block>Table with column and row spanned:</fo:block> <fo:table> <fo:table-column border-width="2px" border-style="solid" column-width="20%"/> <fo:table-column border-width="2px" border-style="solid" column-width="30%"/> <fo:table-column border-width="2px" border-style="solid" column-width="30%"/> <fo:table-column border-width="2px" border-style="solid" column-width="20%"/> <fo:table-body> <fo:table-row border-width="2px" border-style="solid"> <fo:table-cell padding="8pt" background-color="#ffddff"> <fo:block text-align="center">Logo</fo:block></fo:table-cell> <fo:table-cell padding="8pt" background-color="#ffffdd" number-columns-spanned="3"> <fo:block text-align="center">Top Menu</fo:block></fo:table-cell> </fo:table-row> <fo:table-row border-width="2px" border-style="solid"> <fo:table-cell padding="8pt" background-color="#ffffdd" number-rows-spanned="2" display-align="center"> <fo:block text-align="center">Side Menu</fo:block></fo:table-cell> <fo:table-cell padding="8pt"> <fo:block text-align="center" line-height="500%">World News</fo:block></fo:table-cell> <fo:table-cell padding="8pt"> <fo:block text-align="center" line-height="500%">Financial</fo:block></fo:table-cell> <fo:table-cell padding="8pt" background-color="#ffddff" number-rows-spanned="2" display-align="center"> <fo:block text-align="center">List of Ads</fo:block></fo:table-cell> </fo:table-row> <fo:table-row border-width="2px" border-style="solid"> <fo:table-cell padding="8pt"> <fo:block text-align="center" line-height="500%">Technology</fo:block></fo:table-cell> <fo:table-cell padding="8pt"> <fo:block text-align="center" line-height="500%">Sports</fo:block></fo:table-cell> </fo:table-row> <fo:table-row border-width="2px" border-style="solid"> <fo:table-cell padding="8pt" background-color="#dddddd" number-columns-spanned="4"> <fo:block text-align="center">Footer</fo:block></fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </fo:flow> </fo:page-sequence> </fo:root>
If you process this example XSL-FO document with Apache FOP, you will see a table with some cells merged:
Notice that table-cell[@display-align="center"] attribute is used to control the vertical alignment of cell content.
Table of Contents
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
Table Cell Borders Collapsed and Separated
Table Row Borders and Column Borders
Table Column Headers and Footers
Table and Column Width Control
►Table Column and Row Merge or Span
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