Custom PDF plugin doesn't recognize FIRST and LAST body pages

Here should go questions about transforming XML with XSLT and FOP.
GregWait42
Posts: 8
Joined: Wed Feb 19, 2020 10:52 pm

Custom PDF plugin doesn't recognize FIRST and LAST body pages

Post by GregWait42 » Mon Dec 28, 2020 9:26 pm

I need different footers for the FIRST and LAST page of my body in an existing custom PDF DITA-OT plugin.
I have:

Code: Select all

<xsl:template name="insertBodyFirstFooter">
        <fo:static-content flow-name="first-body-footer">
            <fo:block xsl:use-attribute-sets="__body__odd__footer" text-align="right" space-after="10pt" start-indent="0pt" space-after.conditionality="retain">
                <fo:inline/>
            </fo:block>
        </fo:static-content>
    </xsl:template>
   
   <xsl:template name="insertBodyOddFooter">
        <fo:static-content flow-name="odd-body-footer">
            <fo:block xsl:use-attribute-sets="__body__odd__footer" text-align="right" space-after="10pt" start-indent="0pt" space-after.conditionality="retain">
                <fo:inline><fo:page-number/></fo:inline>
            </fo:block>
        </fo:static-content>
    </xsl:template>
   
   <xsl:template name="insertBodyEvenFooter">
        <fo:static-content flow-name="even-body-footer">
            <fo:block xsl:use-attribute-sets="__body__odd__footer" text-align="right" space-after="10pt" start-indent="0pt" space-after.conditionality="retain">
                <fo:inline><fo:page-number/></fo:inline>
            </fo:block>
        </fo:static-content>
    </xsl:template>
   
   <xsl:template name="insertBodyLastFooter">
        <fo:static-content flow-name="last-body-footer">
            <fo:block xsl:use-attribute-sets="__body__odd__footer" text-align="right" space-after="10pt" start-indent="0pt" space-after.conditionality="retain">
                <fo:inline/>
            </fo:block>
        </fo:static-content>
    </xsl:template>
When I run it the resulting PDF has the ODD footer on page 1 and the EVEN footer on the last page (which is an even numbered page). I have compared it with other PDF plugins where the FIRST and LAST pages are treated differently, and I cannot find what differs to make it work. Any help is greatly appreciated!

Regards,
GW

Dan
Posts: 480
Joined: Mon Feb 03, 2003 10:56 am

Re: Custom PDF plugin doesn't recognize FIRST and LAST body pages

Post by Dan » Thu Dec 31, 2020 10:49 am

A hint, I am not an expert in XSL-FO customization, probably this type of questions are better answered on the DITA-OT discussion list (see https://www.dita-ot.org/support)

These templates generate static content that is associated to a page sequence.

By repeatedly applying find in files (each time by the name of the called template) I found that in the file DITA-OT-3.x/plugins/org.dita.pdf2/cfg/fo/layout-masters.xsl, at line 257, the $mirror-page-margins variable controls the usage of the odd/even page references:

Code: Select all

 <xsl:choose>
          <xsl:when test="$mirror-page-margins">
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"
                                                  odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-even"
                                                  odd-or-even="even"/>
          </xsl:when>
          <xsl:otherwise>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"/>
          </xsl:otherwise>
        </xsl:choose>
Maybe you have to change the value of this variable, it is declared in DITA-OT-3.x/plugins/org.dita.pdf2/cfg/fo/attrs/basic-settings.xsl

For XSL-FO customization resources, please read: https://www.dita-ot.org/dev/topics/pdf- ... urces.html
(There is metioned a book by Leigh W. White, for DITA-OT 2.0 )

Many regards,
Dan

GregWait42
Posts: 8
Joined: Wed Feb 19, 2020 10:52 pm

Re: Custom PDF plugin doesn't recognize FIRST and LAST body pages

Post by GregWait42 » Thu Dec 31, 2020 9:32 pm

Dan,

Thanks for the reply. I have the identical code plus lines above that section that deal specifically with first and last...

Code: Select all

<fo:page-sequence-master master-name="{$master-name}">
      <fo:repeatable-page-master-alternatives>
        <xsl:if test="$first">
          <fo:conditional-page-master-reference master-reference="{$master-reference}-first"
                                                odd-or-even="odd"
                                                page-position="first"/>
        </xsl:if>
        <xsl:if test="$last">
          <fo:conditional-page-master-reference master-reference="{$master-reference}-last"
                                                odd-or-even="even"
                                                page-position="last"/>
                                            <!--blank-or-not-blank="blank"-->
        </xsl:if>
        <xsl:choose>
          <xsl:when test="$mirror-page-margins">
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"
                                                  odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-even"
                                                  odd-or-even="even"/>
          </xsl:when>
          <xsl:otherwise>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"/>
          </xsl:otherwise>
        </xsl:choose>
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
What I assume is missing is either something that triggers

Code: Select all

$master-reference}-first
/

Code: Select all

$master-reference}-last
OR something that recognizes the first and last pages. (Those may be one thing.) - G

GregWait42
Posts: 8
Joined: Wed Feb 19, 2020 10:52 pm

Re: Custom PDF plugin doesn't recognize FIRST and LAST body pages

Post by GregWait42 » Mon Jan 04, 2021 10:04 pm

Still hoping for a helping hand from someone on this one. Anyone got any thoughts? - G

julien_lacour
Posts: 164
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom PDF plugin doesn't recognize FIRST and LAST body pages

Post by julien_lacour » Tue Jan 05, 2021 11:48 am

Hello,

As Dan mentioned before, you should try to check the mirror-page-margins variable used in the following template:

Code: Select all

  <xsl:template name="generate-page-sequence-master">
    <xsl:param name="master-name"/>
    <xsl:param name="master-reference"/>
    <xsl:param name="first" select="true()"/>
    <xsl:param name="last" select="true()"/>
    <fo:page-sequence-master master-name="{$master-name}">
      <fo:repeatable-page-master-alternatives>
        <xsl:if test="$first">
          <fo:conditional-page-master-reference master-reference="{$master-reference}-first"
                                                odd-or-even="odd"
                                                page-position="first"/>
        </xsl:if>
        <xsl:if test="$last">
          <fo:conditional-page-master-reference master-reference="{$master-reference}-last"
                                                odd-or-even="even"
                                                page-position="last"/>
                                            <!--blank-or-not-blank="blank"-->
        </xsl:if>
        <xsl:choose>
          <xsl:when test="$mirror-page-margins">
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"
                                                  odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-even"
                                                  odd-or-even="even"/>
          </xsl:when>
          <xsl:otherwise>
            <fo:conditional-page-master-reference master-reference="{$master-reference}-odd"/>
          </xsl:otherwise>
        </xsl:choose>
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
    
  </xsl:template>
You can also run the transformation with the 'clean.temp' parameter set to no, then check inside the generated /temp folder the .fo file.
Inside you will find the generated fo:conditional-page-master-reference and see which attributes are set on it and why the odd footer is displayed instead of the first footer (or even instead of last).
If you are used to XSL you can also try to debug the transformation using Oxygen XSLT Debugger.

Also, as this is a default DITA-OT transformation, you may try to ask this question on the DITA-OT Discussion Lists: https://www.dita-ot.org/support (especially the DITA Users group)

Regards,
Julien

Post Reply