This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [docbook-apps] Getting static content into region-start and region-end


Hi Bob,

On Wed, Apr 21, 2004 at 09:56:21AM -0700, Bob Stayton wrote:

> The body margin-right is zero because the region-end extent provides
> the right margin. You would do something mirrored for left-hand
> pages.

XSL-FO's page setup mechanism is still something I don't fully
understand (despite the best efforts of Dave Pawson's "XSL-FO"---Hi
Dave!), but through trial-and-error I found that setting
margin-right="0pt" on the simple-page-master _and_
margin-right="{$page.margin.outer}" on the region-body were required,
at least to get the output I wanted.  The region-body previously had
no margin-right attribute, and without it, the body did indeed extend
to the far edge of the page after zeroing the right margin on the
simple-page-master.  (Substitute 'margin-left' and 'margin.left.outer'
where appropriate for the body-even simple-page-master.)

> To get some content into your start or end regions, you need to add
> fo:static-content elements with the correct flow-names (such as
> 'xsl-region-end-first') at the top of the generated
> fo:page-sequences in your output.  This means customizing the
> templates for the elements that generate page sequences, such as
> chapter and appendix.  I found it easiest to copy the way the
> running headers are handled with 'running.head.mode' but adapt it
> for 'running.side.mode'.  I can provide more details if needed.

For the benefit of the archive, I will document how I did it.  I am
using 'article' as the root, so for now I am customising only the
'body' pages.  This is what I have done:

1. Set up a 'user.pagemasters' template:

  <xsl:template name="user.pagemasters">
    <fo:page-sequence-master master-name="body-cms">
      <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference master-reference="blank"
                                              blank-or-not-blank="blank"/>
        <fo:conditional-page-master-reference master-reference="body-first-cms"
                                              page-position="first"/>
        <fo:conditional-page-master-reference master-reference="body-odd-cms"
                                              odd-or-even="odd"/>
        <fo:conditional-page-master-reference master-reference="body-even-cms"
                                              odd-or-even="even"/>
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>

    <fo:simple-page-master master-name="body-first-cms"
			   page-width="{$page.width}"
			   page-height="{$page.height}"
			   margin-top="{$page.margin.top}"
			   margin-bottom="{$page.margin.bottom}"
			   margin-left="{$margin.left.inner}"
			   margin-right="0pt">
      <fo:region-body margin-bottom="{$body.margin.bottom}"
		      margin-top="{$body.margin.top}"
		      column-gap="{$column.gap.body}"
		      column-count="{$column.count.body}"
                      margin-right="{$page.margin.outer}">
      </fo:region-body>
      <fo:region-before region-name="xsl-region-before-first"
			extent="{$region.before.extent}"
			display-align="before"/>
      <fo:region-after region-name="xsl-region-after-first"
		       extent="{$region.after.extent}"
		       display-align="after"/>
      <fo:region-start region-name="xsl-region-start-first"
		       extent="0pt"/>
      <fo:region-end region-name="xsl-region-end-first"
		     extent="{$page.margin.outer}"/>
    </fo:simple-page-master>

    <!-- And so on for body-odd-cms and body-even-cms, substituting
         'left-margin' and '{$margin.left.outer}' where appropriate
         for the latter. -->


2. Set up a 'select.user.pagemasters' template:

   (Something I did not initially realise here is that this template
   also returns the master-name for the page-sequence-master, not just
   the simple-page-masters.)

  <xsl:template name="select.user.pagemaster">
    <xsl:param name="element"/>
    <xsl:param name="pageclass"/>
    <xsl:param name="default-pagemaster"/>

    <xsl:choose>
      <xsl:when test="$default-pagemaster = 'body'">
	<xsl:value-of select="'body-cms'"/>
      </xsl:when>
      <xsl:when test="$default-pagemaster = 'body-first'">
	<xsl:value-of select="'body-first-cms'"/>
      </xsl:when>
      <xsl:when test="$default-pagemaster = 'body-odd'">
	<xsl:value-of select="'body-first-cms'"/>
      </xsl:when>
      <xsl:when test="$default-pagemaster = 'body-even'">
	<xsl:value-of select="'body-first-cms'"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select="$default-pagemaster"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


3. Customised the 'article' template to call my 'runing.side.mode'
   template:

  <xsl:template match="article">
    <xsl:variable name="id">
      <xsl:call-template name="object.id"/>
    </xsl:variable>

    <xsl:variable name="master-reference">
      <xsl:call-template name="select.pagemaster"/>
    </xsl:variable>

    <!-- The elided part here just copied and pasted from
         fo/component.xsl ... -->

      <!-- This is a new template to add side content -->
      <xsl:apply-templates select="." mode="running.side.mode">
	<xsl:with-param name="master-reference" select="$master-reference"/>
      </xsl:apply-templates>


4. Added a 'running.side.mode' template, basically cut, pasted and
   edited from 'running.head.mode':

  <xsl:template match="*" mode="running.side.mode">
    <xsl:param name="master-reference" select="'unknown'"/>
    <xsl:param name="gentext-key" select="name(.)"/>

    <!-- remove -draft from reference -->
    <xsl:variable name="pageclass">
      <xsl:choose>
	<xsl:when test="contains($master-reference, '-draft')">
	  <xsl:value-of select="substring-before($master-reference, '-draft')"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:value-of select="$master-reference"/>
	</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
    <fo:static-content flow-name="xsl-region-end-first">
      <fo:block>foo</fo:block>
    </fo:static-content>
    
    <fo:static-content flow-name="xsl-region-end-odd">
      <fo:block>foo</fo:block>
    </fo:static-content>
    
    <fo:static-content flow-name="xsl-region-end-even">
      <fo:block>foo</fo:block>
    </fo:static-content>
    
    <fo:static-content flow-name="xsl-region-end-blank">
      <fo:block>foo</fo:block>
    </fo:static-content>
  </xsl:template>


Of course, at some point, I will replace the word 'foo' there with the
graphic I want in the outer margins.  How does that look, Bob?  Thanks
for your advice.


-- 
Paul.

mailto:paulh@logicsquad.net

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]