Often, in a book, the current chapter name is displayed on the header. To implement this feature, the XSL-FO marker element is needed.
First the user must "mark" (delimitate) pieces of the content as being retrievable for the purpose of displaying them in headers or footers.
For this the fo:marker element must be used. The marker is usually associated with a fo:block, therefore, the information from the marker can be displayed in all the pages where the fo:block element generates areas.
Then in header or footer the user must "tell" the engine to display a marker using the fo:retrieve-marker element.
There can be, of course, multiple markers on a certain page, so each marker must has an unique name, as well as the retrieval rule: first marker with the given name present in the page, or the first that starts in the page, or the last one, etc.
Example of usage for two chapters document, with the chapter title displayed in the header:
<?xml version="1.0" encoding="utf-8" ?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<fo:layout-master-set>
<fo:simple-page-master master-name="all-pages" page-width="5in" page-height="1.2in" margin="0.1in">
<fo:region-body region-name="xsl-region-body" margin-top="0.14in"/>
<fo:region-before region-name="xsl-region-before" extent="0.12in" padding-right="0.2in" border-bottom="1pt solid black" display-align="after"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="all-pages">
<fo:static-content flow-name="xsl-region-before" font="italic 10pt'Verdana'">
<fo:block>
The first title starting on this page:
<fo:retrieve-marker retrieve-class-name="title" retrieve-position="first-starting-within-page" retrieve-boundary="page"/>(1)
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font="10pt Arial">
<fo:block font-weight="bold"><fo:marker marker-class-name="title">(2)
Title of Chapter 1
</fo:marker>
Chapter 1
</fo:block>
<fo:block widows="1">(3)
Text text text text text text text text text text text text
text text text text text text text text text text text text
............................................................
text text text text text text text text text text text text
</fo:block>
<fo:block font-weight="bold"><fo:marker marker-class-name="title">(4)
Title of Chapter 2
</fo:marker>
Chapter 2
</fo:block>
<fo:block>Text text text, text</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Output:
Key observations:
(2),(4)In the page's body a marker for each fo:block has been declared in the flow.
(3) The second paragraph will be located on the second page because it has the widows attribute set.
(1) In the header region, that applies for every generated page, the markers are retrieved using the fo:retrieve-marker element. The marker "type" is specified in the retrieve-class-name attribute. The scope of the marker retrieval is limited to be on the same page as the retrieve-marker element. First occurrence will be displayed.