Search code examples
xmlxsltapache-fopdocbook

add fo:marker marker-class-name="section.head.marker" to specific sections


I have been trying to figure out how I can manually or automatically add the fo:marker section.head.marker to specific sections.

I am using FOP to convert my xml files to pdf.

My format looks as such

Article
    section A1 -
        section A2 -
            section A3
    section B1 -
        section B2 -
            section B3

I can use the

<xsl:param name="marker.section.level">3</xsl:param>

to generate the header for all of the sections, however i do not want the header to be generated for A3, but I do want it for B3.

I have tried switching A3 to a simplesect however simplesect at that level still has the header generated.

I have also tried manually adding the fo:marker as such:

<section id="B3">
    <fo:marker marker-class-name="section.head.marker">
        B3
    </fo:marker>
    <title id="B3.title">B3</title>
    ...

but in my pdf output i get:

<fo:marker> sensors </fo:marker>

Is there something that I am missing to manually add the fo:marker to my xml file, or is there a way to prevent fo:markers from being generated in simplesect's via xsl?

It looks like this might be solved in a similar way as

<xsl:template match="processing-instruction('hard-pagebreak')">
    <fo:block break-after='page'/>
</xsl:template>

where instead of adding the hard-pagebreak command to the xml I add a header command of sorts that grabs the current section title and creates the fo:header

The xsl section that handles the running header generation is:

<xsl:param name="marker.section.level">2</xsl:param>
<xsl:template name="header.content">  
    <xsl:param name="position" select="''"/>
    <xsl:param name="sequence" select="''"/>

    <fo:block>
        <!-- position can be left, center, right -->
        <xsl:choose>
            <xsl:when test="$sequence = 'first'">
                <!-- off -->
            </xsl:when>
            <xsl:when test="$position = 'left'">
                <xsl:call-template name="draft.text"/>
            </xsl:when>
            <xsl:when test="$position = 'center'">
                <fo:retrieve-marker 
                      retrieve-class-name="section.head.marker"
                      retrieve-position="first-including-carryover"
                      retrieve-boundary="page-sequence"/>
            </xsl:when>
        </xsl:choose>
    </fo:block>
</xsl:template>

The rest of my xsl file handles:

imports     <xsl:import href="./docbook-xsl/fo/docbook.xsl"/> first
moving TOC to new page
allowing hard page breaks
Adding footer ( title, page# )
verbatim segment properties
    shading/word wrap
formatting revision history
disable hyphenation
disable showing URLs of links
Color links

Solution

  • I was able to generate a manual section.head.marker with the following xsl code:

    <xsl:template match="processing-instruction('running-header')">
        <fo:block>
            <fo:marker marker-class-name="section.head.marker">
                <xsl:value-of select="../title"/>
            </fo:marker>
        </fo:block>
    </xsl:template>
    

    then I just included the running header processing-instruction.

    <section id="B3"
         xmlns:fo="http://www.w3.org/1999/XSL/Format"
         >
     <?running-header?>
    <title id="B3.title">B3</title>
    

    This allows me to manually add a section.head.marker with the current section title.