]> granicus.if.org Git - docbook-dsssl/commitdiff
Add support for side body margins and side static content regions.
authorBob Stayton <bobs@sagehill.net>
Wed, 23 Nov 2011 22:29:23 +0000 (22:29 +0000)
committerBob Stayton <bobs@sagehill.net>
Wed, 23 Nov 2011 22:29:23 +0000 (22:29 +0000)
Fixes bug 3389931.

xsl/fo/pagesetup.xsl

index 9c96bc1f9cfeceb19a5d91d88f8692392d05ff68..8cd845e088ca7f0eb25ca206bd91c6819b00c652 100644 (file)
     <xsl:value-of select="$symbol.font.family"/>
 </xsl:param>
 
-<xsl:param name="margin.left.inner">
+<!-- These are internal parameters are for the individual precedence attributes -->
+<xsl:param name="region.start.precedence">
   <xsl:choose>
-    <xsl:when test="$passivetex.extensions != 0">
-      <xsl:value-of select="$page.margin.inner"/>
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:value-of select="$page.margin.inner"/>
-      <xsl:text> - </xsl:text>
-      <xsl:value-of select="$title.margin.left"/>
-    </xsl:otherwise>
+    <xsl:when test="$side.region.precedence = 'true'">true</xsl:when>
+    <xsl:otherwise>false</xsl:otherwise>
+  </xsl:choose>
+</xsl:param>
+
+<xsl:param name="region.end.precedence">
+  <xsl:choose>
+    <xsl:when test="$side.region.precedence = 'true'">true</xsl:when>
+    <xsl:otherwise>false</xsl:otherwise>
+  </xsl:choose>
+</xsl:param>
+
+<xsl:param name="region.before.precedence">
+  <xsl:choose>
+    <xsl:when test="$side.region.precedence = 'true'">false</xsl:when>
+    <xsl:otherwise>true</xsl:otherwise>
+  </xsl:choose>
+</xsl:param>
+
+<xsl:param name="region.after.precedence">
+  <xsl:choose>
+    <xsl:when test="$side.region.precedence = 'true'">false</xsl:when>
+    <xsl:otherwise>true</xsl:otherwise>
   </xsl:choose>
 </xsl:param>
 
       <fo:region-body display-align="center"
                       margin-bottom="{$body.margin.bottom}"
                       margin-top="{$body.margin.top}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
         <xsl:if test="$fop.extensions = 0 and $fop1.extensions = 0">
           <xsl:attribute name="region-name">blank-body</xsl:attribute>
         </xsl:if>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-blank"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-blank"
                        extent="{$region.after.extent}"
-                        display-align="after"/>
+                       precedence="{$region.after.precedence}"
+                       display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">blank</xsl:with-param>
+        <xsl:with-param name="pageclass">blank</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">blank</xsl:with-param>
+        <xsl:with-param name="pageclass">blank</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- title pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.titlepage}"
                       column-count="{$column.count.titlepage}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="titlepage-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.titlepage}"
                       column-count="{$column.count.titlepage}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="titlepage-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.titlepage}"
                       column-count="{$column.count.titlepage}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- list-of-title pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.lot}"
                       column-count="{$column.count.lot}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="lot-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.lot}"
                       column-count="{$column.count.lot}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="lot-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.lot}"
                       column-count="{$column.count.lot}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">lot</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- frontmatter pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.front}"
                       column-count="{$column.count.front}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="front-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.front}"
                       column-count="{$column.count.front}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="front-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.front}"
                       column-count="{$column.count.front}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                         display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">front</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- body pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.body}"
                       column-count="{$column.count.body}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="body-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.body}"
                       column-count="{$column.count.body}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                       precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="body-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.body}"
                       column-count="{$column.count.body}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                       precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+        <xsl:with-param name="sequence">even</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="pageclass">body</xsl:with-param>
+        <xsl:with-param name="sequence">even</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- backmatter pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.back}"
                       column-count="{$column.count.back}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="back-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.back}"
                       column-count="{$column.count.back}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="back-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.back}"
                       column-count="{$column.count.back}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">back</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <!-- index pages -->
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.index}"
                       column-count="{$column.count.index}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-first"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-first"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">first</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="index-odd"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.index}"
                       column-count="{$column.count.index}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-odd"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-odd"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">odd</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <fo:simple-page-master master-name="index-even"
                       margin-top="{$body.margin.top}"
                       column-gap="{$column.gap.index}"
                       column-count="{$column.count.index}">
+        <xsl:attribute name="margin-{$direction.align.start}">
+          <xsl:value-of select="$body.margin.outer"/>
+        </xsl:attribute>
+        <xsl:attribute name="margin-{$direction.align.end}">
+          <xsl:value-of select="$body.margin.inner"/>
+        </xsl:attribute>
       </fo:region-body>
       <fo:region-before region-name="xsl-region-before-even"
                         extent="{$region.before.extent}"
+                        precedence="{$region.before.precedence}"
                         display-align="before"/>
       <fo:region-after region-name="xsl-region-after-even"
                        extent="{$region.after.extent}"
+                        precedence="{$region.after.precedence}"
                        display-align="after"/>
+      <xsl:call-template name="region.outer">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
+      <xsl:call-template name="region.inner">
+        <xsl:with-param name="sequence">even</xsl:with-param>
+        <xsl:with-param name="pageclass">index</xsl:with-param>
+      </xsl:call-template>
     </fo:simple-page-master>
 
     <xsl:if test="$draft.mode != 'no'">
         </xsl:if>
         <fo:region-body margin-bottom="{$body.margin.bottom}"
                         margin-top="{$body.margin.top}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-blank"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-blank"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">blank</xsl:with-param>
+          <xsl:with-param name="pageclass">blank</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">blank</xsl:with-param>
+          <xsl:with-param name="pageclass">blank</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft title pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.titlepage}"
                         column-count="{$column.count.titlepage}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="titlepage-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.titlepage}"
                         column-count="{$column.count.titlepage}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="titlepage-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.titlepage}"
                         column-count="{$column.count.titlepage}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">titlepage</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft list-of-title pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.lot}"
                         column-count="{$column.count.lot}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="lot-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.lot}"
                         column-count="{$column.count.lot}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="lot-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.lot}"
                         column-count="{$column.count.lot}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">lot</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft frontmatter pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.front}"
                         column-count="{$column.count.front}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="front-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.front}"
                         column-count="{$column.count.front}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="front-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.front}"
                         column-count="{$column.count.front}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">front</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft body pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.body}"
                         column-count="{$column.count.body}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="body-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.body}"
                         column-count="{$column.count.body}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="body-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.body}"
                         column-count="{$column.count.body}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">body</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft backmatter pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.back}"
                         column-count="{$column.count.back}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="back-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.back}"
                         column-count="{$column.count.back}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="back-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.back}"
                         column-count="{$column.count.back}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">back</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <!-- draft index pages -->
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.index}"
                         column-count="{$column.count.index}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-first"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-first"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">first</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="index-odd-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.index}"
                         column-count="{$column.count.index}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-odd"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-odd"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">odd</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
 
       <fo:simple-page-master master-name="index-even-draft"
                         margin-top="{$body.margin.top}"
                         column-gap="{$column.gap.index}"
                         column-count="{$column.count.index}">
+          <xsl:attribute name="margin-{$direction.align.start}">
+            <xsl:value-of select="$body.margin.outer"/>
+          </xsl:attribute>
+          <xsl:attribute name="margin-{$direction.align.end}">
+            <xsl:value-of select="$body.margin.inner"/>
+          </xsl:attribute>
           <xsl:if test="$draft.watermark.image != ''">
             <xsl:attribute name="background-image">
               <xsl:call-template name="fo-external-image">
         </fo:region-body>
         <fo:region-before region-name="xsl-region-before-even"
                           extent="{$region.before.extent}"
+                          precedence="{$region.before.precedence}"
                           display-align="before"/>
         <fo:region-after region-name="xsl-region-after-even"
                          extent="{$region.after.extent}"
+                          precedence="{$region.after.precedence}"
                          display-align="after"/>
+        <xsl:call-template name="region.outer">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
+        <xsl:call-template name="region.inner">
+          <xsl:with-param name="sequence">even</xsl:with-param>
+          <xsl:with-param name="pageclass">index</xsl:with-param>
+        </xsl:call-template>
       </fo:simple-page-master>
     </xsl:if>
 
   <xsl:if test="$fop.extensions = 0 and $fop1.extensions = 0">
     <xsl:call-template name="blank.page.content"/>
   </xsl:if>
+
+  <xsl:apply-templates select="." mode="region.inner.mode">
+    <xsl:with-param name="master-reference" select="$master-reference"/>
+    <xsl:with-param name="gentext-key" select="$gentext-key"/>
+  </xsl:apply-templates>
+
+  <xsl:apply-templates select="." mode="region.outer.mode">
+    <xsl:with-param name="master-reference" select="$master-reference"/>
+    <xsl:with-param name="gentext-key" select="$gentext-key"/>
+  </xsl:apply-templates>
+
 </xsl:template>
 
 <xsl:template name="footnote-separator">
   </fo:static-content>
 </xsl:template>
 
+<xsl:template name="running.side.content">
+  <xsl:apply-templates select="." mode="region.inner.mode"/>
+</xsl:template>
+
 <xsl:template name="header.table">
   <xsl:param name="pageclass" select="''"/>
   <xsl:param name="sequence" select="''"/>
   </fo:block>
 </xsl:template>
 
+<!-- ==================================================================== -->
+<xsl:template match="*" mode="region.inner.mode">
+  <xsl:param name="master-reference" select="'unknown'"/>
+  <xsl:param name="gentext-key" select="local-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-inner-first">
+    <xsl:call-template name="inner.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'first'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-inner-odd">
+    <xsl:call-template name="inner.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'odd'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-inner-even">
+    <xsl:call-template name="inner.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'even'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-inner-blank">
+    <xsl:call-template name="inner.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'blank'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+</xsl:template>
+
+<xsl:template match="*" mode="region.outer.mode">
+  <xsl:param name="master-reference" select="'unknown'"/>
+  <xsl:param name="gentext-key" select="local-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-outer-first">
+    <xsl:call-template name="outer.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'first'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-outer-odd">
+    <xsl:call-template name="outer.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'odd'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-outer-even">
+    <xsl:call-template name="outer.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'even'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+  <fo:static-content flow-name="xsl-region-outer-blank">
+    <xsl:call-template name="outer.region.content">
+      <xsl:with-param name="pageclass" select="$pageclass"/>
+      <xsl:with-param name="sequence" select="'blank'"/>
+      <xsl:with-param name="gentext-key" select="$gentext-key"/>
+    </xsl:call-template>
+  </fo:static-content>
+
+</xsl:template>
+
+<xsl:template name="inner.region.content">
+  <xsl:param name="pageclass" select="''"/>
+  <xsl:param name="sequence" select="''"/>
+  <xsl:param name="position" select="''"/>
+  <xsl:param name="gentext-key" select="''"/>
+
+  <!-- pageclass can be front, body, back -->
+  <!-- sequence can be odd, even, first, blank -->
+  <!-- position can be left, center, right -->
+
+  <!-- Customize to add side region content-->
+  <fo:block xsl:use-attribute-sets="inner.region.content.properties">
+    <!-- Add your content here -->
+  </fo:block>
+</xsl:template>
+
+<xsl:template name="outer.region.content">
+  <xsl:param name="pageclass" select="''"/>
+  <xsl:param name="sequence" select="''"/>
+  <xsl:param name="position" select="''"/>
+  <xsl:param name="gentext-key" select="''"/>
+
+  <!-- pageclass can be front, body, back -->
+  <!-- sequence can be odd, even, first, blank -->
+  <!-- position can be left, center, right -->
+
+  <!-- Customize to add side region content-->
+  <fo:block xsl:use-attribute-sets="outer.region.content.properties">
+    <!-- Add your content here -->
+  </fo:block>
+</xsl:template>
+
 <!-- ==================================================================== -->
 
 <xsl:template name="page.number.format">
 </xsl:template>
 <!-- ==================================================================== -->
 
+<!-- Customize this template for custom side regions -->
+<xsl:template name="region.inner">
+  <xsl:param name="sequence">blank</xsl:param>
+  <xsl:param name="classname">blank</xsl:param>
+
+  <xsl:choose>
+    <xsl:when test="$sequence = 'first' or $sequence = 'odd'">
+      <fo:region-start xsl:use-attribute-sets="region.inner.properties">
+        <xsl:attribute name="region-name">
+          <xsl:text>xsl-region-inner-</xsl:text>
+          <xsl:value-of select="$sequence"/>
+        </xsl:attribute>
+        <xsl:attribute name="precedence">
+          <xsl:value-of select="$region.start.precedence"/>
+        </xsl:attribute>
+        <xsl:attribute name="extent">
+          <xsl:value-of select="$region.inner.extent"/>
+        </xsl:attribute>
+      </fo:region-start>
+    </xsl:when>
+    <xsl:otherwise>
+      <fo:region-end xsl:use-attribute-sets="region.inner.properties">
+        <xsl:attribute name="region-name">
+          <xsl:text>xsl-region-inner-</xsl:text>
+          <xsl:value-of select="$sequence"/>
+        </xsl:attribute>
+        <xsl:attribute name="precedence">
+          <xsl:value-of select="$region.end.precedence"/>
+        </xsl:attribute>
+        <xsl:attribute name="extent">
+          <xsl:value-of select="$region.inner.extent"/>
+        </xsl:attribute>
+      </fo:region-end>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- Customize this template for custom side regions -->
+<xsl:template name="region.outer">
+  <xsl:param name="sequence">blank</xsl:param>
+  <xsl:param name="classname">blank</xsl:param>
+
+  <xsl:choose>
+    <xsl:when test="$sequence = 'first' or $sequence = 'odd'">
+      <fo:region-end xsl:use-attribute-sets="region.outer.properties">
+        <xsl:attribute name="region-name">
+          <xsl:text>xsl-region-outer-</xsl:text>
+          <xsl:value-of select="$sequence"/>
+        </xsl:attribute>
+        <xsl:attribute name="precedence">
+          <xsl:value-of select="$region.start.precedence"/>
+        </xsl:attribute>
+        <xsl:attribute name="extent">
+          <xsl:value-of select="$region.outer.extent"/>
+        </xsl:attribute>
+      </fo:region-end>
+    </xsl:when>
+    <xsl:otherwise>
+      <fo:region-start xsl:use-attribute-sets="region.outer.properties">
+        <xsl:attribute name="region-name">
+          <xsl:text>xsl-region-outer-</xsl:text>
+          <xsl:value-of select="$sequence"/>
+        </xsl:attribute>
+        <xsl:attribute name="precedence">
+          <xsl:value-of select="$region.end.precedence"/>
+        </xsl:attribute>
+        <xsl:attribute name="extent">
+          <xsl:value-of select="$region.outer.extent"/>
+        </xsl:attribute>
+      </fo:region-start>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>