Markers

Top Previous Topic Next Topic  Print this topic

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: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" (1)

                                                       retrieve-boundary="page"/>

               </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>

 

The rendering result is displayed in the next figure:

 

markers

 Figure 22.

The important points in this document are:

 

(2),(4)In the body of the page we declare a marker for each fo:block in the flow.

(3) The second paragraph will go on the second page because it has the widows attribute set.

(1) 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.