Contents | < Footnotes | Bookmarks >

Markers

You have probably noticed how in a book, the current chapter name is displayed on the header. To implement this feature, you need to understand XSL-FO marker elements.

First you "mark" (delimitate) pieces of your content as being retrievable for the purpose of displaying them in headers or footers. For this you use fo:marker. The marker is usually associated with a fo:block, therefore, the information from the marker can be displayed in all that pages where the fo:block generates areas.

Then in the headers or footer you tell the engine to display a marker using fo:retrieve-marker. There can be of course multiple markers in a certain page, so you have to use an unique name for each marker, 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.

The next example shows a two chapter document, with the chapter title being displayed in the header.

<fo:page-sequence master-reference="all-pages" font="italic 10pt Verdana">
    <fo:static-content flow-name="xsl-region-before">
        <fo:block>
            The first title present on this page:
            <fo:retrieve-marker retrieve-class-name="title"  Œ  
                                retrieve-position="first-starting-within-page"    
                                retrieve-boundary="page" /> Ž
        </fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body" font="10pt Verdana">
        <fo:block>
            <fo:block font="18pt 'Arial Narrow'">
                <fo:marker marker-class-name="title" > 
                    Title of Chapter 1
                </fo:marker>
                Chapter 1
            </fo:block>
            Text ...
        </fo:block>
        <fo:block break-before="page">
            <fo:block font="18pt 'Arial Narrow'">
                <fo:marker marker-class-name="title" > 
                    Title of Chapter 2
                </fo:marker>
                Chapter 2
            </fo:block>
            Text ...
        </fo:block>
    </fo:flow>
</fo:page-sequence>
For the complete source code for this code example see "Tutorial/Markers.fo" located under XML Documents Samples/Tutorial folder.

The rendering result is displayed in the next figure.

Figure 1

The important points in this document are:

 In the body of the page we declare a marker for each fo:block in the flow. The second paragraph will go on the second page because it has the break-before attribute set.

Œ In the header region, that applies for every generated page, we retrieve the markers using fo:retrieve-marker. The marker "type" is specified in retrieve-class-name attribute.

 Ž Limit the scope of the marker retrieval to be in the same page as retrieve-marker element. First occurrence will be displayed.

 

Contents | < Footnotes | Bookmarks >