Static Content

Contact Us or call 1-877-932-8228
Static Content

Static Content

Static content is added to page sequences with the static-content FO. Generally, static content is used in regions other than the body region. The example below adds a header and a footer to our "Hello-World" document.

Code Sample:

FoBasics/Demos/HelloWorld-Static.fo
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

	<fo:layout-master-set>
		<fo:simple-page-master master-name="hello" page-height="11in" 
			page-width="8.5in" margin-top="1in" margin-bottom="1in" 
			margin-left="1in" margin-right="1in">
			<fo:region-body margin-top="1in" margin-bottom=".5in"/>
			<fo:region-before extent=".5in" background-color="silver"/>
			<fo:region-after extent=".5in" background-color="silver"/>
		</fo:simple-page-master>
	</fo:layout-master-set>
	
	<fo:page-sequence master-reference="hello">
		<fo:static-content flow-name="xsl-region-before">
			<fo:block font-size="24pt">Hello World!</fo:block>
		</fo:static-content>
		<fo:static-content flow-name="xsl-region-after">
			<fo:block font-size="24pt" text-align="right">
				Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page"/>
			</fo:block>
		</fo:static-content>
		<fo:flow flow-name="xsl-region-body">
			<fo:block font-size="36pt" text-align="center" font-weight="bold">
				Hello World!
			</fo:block>
			<fo:block id="last-page"/>
		</fo:flow>
	</fo:page-sequence>
	
</fo:root>

The above code results in the following output.

Let's examine the new FOs we have added.

region-before and region-after

The region-before and region-after FOs have been added to the simple-page-master FO.

<fo:simple-page-master master-name="hello" page-height="11in" page-width="8.5in" margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in"> <fo:region-body margin-top="1in" margin-bottom=".5in"/> <fo:region-before extent=".5in" background-color="silver"/> <fo:region-after extent=".5in" background-color="silver"/> </fo:simple-page-master>

These FOs effectively create header and footer regions. The extent attribute specifies the header and footer height. In both cases, it is set to .5 inches. The background-color attribute specifies the background color.

static-content

<fo:static-content flow-name="xsl-region-before"> <fo:block font-size="12pt">Hello World!</fo:block> </fo:static-content><fo:static-content flow-name="xsl-region-after"> <fo:block font-size="12pt" text-align="right"> Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page"/> </fo:block> </fo:static-content>

The static-content FO is used to add content that will repeat for every page in the current page sequence. The flow-name attribute specifies the region in which this content will appear.

In this case, the first static-content causes the text "Hello World!" to be added to the header of every page in this sequence. The second static-content causes a right-aligned page number to be added to the footer of every page. Let's look at that one a little more closely.

<fo:static-content flow-name="xsl-region-after"> <fo:block font-size="12pt" text-align="right"> Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page"/> </fo:block> </fo:static-content>

The page-number FO is pretty straightforward. It simply inserts the current page number. The page-number-citation FO is used to reference the page number of an FO on another page by its unique id, in this case "last-page". If you look further down in the document, you'll see <fo:block id="last-page"/> at the bottom of the region-body flow. The purpose of placing this FO there is to mark the last page of the document.

Next