]> granicus.if.org Git - docbook-dsssl/commitdiff
Improve formatting of table footnotes and fix numeration of table/non-table footnotes
authorNorman Walsh <ndw@nwalsh.com>
Thu, 14 Mar 2002 12:17:06 +0000 (12:17 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Thu, 14 Mar 2002 12:17:06 +0000 (12:17 +0000)
xsl/fo/docbook.xsl
xsl/fo/fo-rtf.xsl [new file with mode: 0644]
xsl/fo/footnote.xsl
xsl/fo/formal.xsl

index c5da75bf6892c5293046381628c1f4194d7e8931..2a24fe57d8aac03c037c5176467a50ef891699b4 100644 (file)
@@ -44,6 +44,7 @@
 <xsl:include href="inline.xsl"/>
 <xsl:include href="footnote.xsl"/>
 <xsl:include href="fo.xsl"/>
+<xsl:include href="fo-rtf.xsl"/>
 <xsl:include href="info.xsl"/>
 <xsl:include href="keywords.xsl"/>
 <xsl:include href="division.xsl"/>
diff --git a/xsl/fo/fo-rtf.xsl b/xsl/fo/fo-rtf.xsl
new file mode 100644 (file)
index 0000000..8a01bcf
--- /dev/null
@@ -0,0 +1,144 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:fo="http://www.w3.org/1999/XSL/Format"
+                xmlns:exsl="http://exslt.org/common"
+                xmlns:set="http://exslt.org/sets"
+                exclude-result-prefixes="exsl set"
+                version="1.0">
+
+<!-- This module contains templates that match against FO nodes. It is used
+     to post-process result tree fragments for some sorts of cleanup.
+     These templates can only ever be fired by a processor that supports
+     exslt:node-set(). -->
+
+<!-- ==================================================================== -->
+
+<!-- insert.fo.fnum mode templates insert a particular RTF at the beginning
+     of the first paragraph in the primary RTF. In fact, they are inserting
+     a footnote-number, so we tinker a few other things too, like spacing and
+     font-sizes. -->
+
+<xsl:template match="/" mode="insert.fo.fnum">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:apply-templates mode="insert.fo.fnum">
+    <xsl:with-param name="mark" select="$mark"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="*" mode="insert.fo.fnum">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="insert.fo.fnum">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="fo:block" mode="insert.fo.fnum">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:for-each select="@*">
+      <xsl:choose>
+        <xsl:when test="starts-with(name(.), 'space-before')"/>
+        <xsl:when test="starts-with(name(.), 'space-after')"/>
+        <xsl:when test="starts-with(name(.), 'font-size')"/>
+        <xsl:otherwise>
+          <xsl:copy-of select="."/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+    <xsl:if test="not(preceding::fo:block)">
+      <xsl:copy-of select="$mark"/>
+    </xsl:if>
+    <xsl:apply-templates mode="insert.fo.fnum">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="insert.fo.fnum">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy/>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<!-- insert.fo.block mode templates insert a particular RTF at the beginning
+     of the first paragraph in the primary RTF. -->
+
+<xsl:template match="/" mode="insert.fo.block">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:apply-templates mode="insert.fo.block">
+    <xsl:with-param name="mark" select="$mark"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="*" mode="insert.fo.block">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="insert.fo.block">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="fo:block" mode="insert.fo.block">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:if test="not(preceding::fo:block)">
+      <xsl:copy-of select="$mark"/>
+    </xsl:if>
+    <xsl:apply-templates mode="insert.fo.block">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="insert.fo.block">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy/>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<!-- insert.fo.text mode templates insert a particular RTF at the beginning
+     of the first text-node in the primary RTF. -->
+
+<xsl:template match="/" mode="insert.fo.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:apply-templates mode="insert.fo.text">
+    <xsl:with-param name="mark" select="$mark"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="*" mode="insert.fo.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="insert.fo.text">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="insert.fo.text">
+  <xsl:param name="mark" select="'?'"/>
+
+  <xsl:if test="not(preceding::text())">
+    <xsl:copy-of select="$mark"/>
+  </xsl:if>
+
+  <xsl:copy/>
+</xsl:template>
+
+<xsl:template match="processing-instruction()|comment()" mode="insert.fo.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy/>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+</xsl:stylesheet>
index 497243a7c1723a6041664d5e00e475a62c3de537..1d036d06333eb47ea894c707c10f15c1f7d8ccf6 100644 (file)
@@ -1,6 +1,8 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
+                xmlns:exsl="http://exslt.org/common"
+                exclude-result-prefixes="exsl"
                 version='1.0'>
 
 <!-- ********************************************************************
      ******************************************************************** -->
 
 <xsl:template match="footnote">
-  <fo:footnote>
-    <fo:inline baseline-shift="super" font-size="90%">
-      <xsl:apply-templates select="." mode="footnote.number"/>
-    </fo:inline>
-    <fo:footnote-body font-size="{$footnote.font.size}">
-      <xsl:apply-templates/>
-    </fo:footnote-body>
-  </fo:footnote>
+  <xsl:choose>
+    <xsl:when test="ancestor::tgroup">
+      <fo:inline baseline-shift="super" font-size="90%">
+        <xsl:apply-templates select="." mode="footnote.number"/>
+      </fo:inline>
+    </xsl:when>
+    <xsl:otherwise>
+      <fo:footnote>
+        <fo:inline baseline-shift="super" font-size="90%">
+          <xsl:apply-templates select="." mode="footnote.number"/>
+        </fo:inline>
+        <fo:footnote-body font-family="{$body.font.family}"
+                          font-size="{$footnote.font.size}">
+          <xsl:apply-templates/>
+        </fo:footnote-body>
+      </fo:footnote>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="footnoteref">
 </xsl:template>
 
 <xsl:template match="footnote" mode="footnote.number">
-  <xsl:number level="any" format="1"/>
+  <xsl:choose>
+    <xsl:when test="ancestor::tgroup">
+      <xsl:number level="any" from="tgroup" format="a"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:variable name="pfoot" select="preceding::footnote"/>
+      <xsl:variable name="ptfoot" select="preceding::table//footnote
+                                          |preceding::informaltable//footnote"/>
+      <xsl:number value="count($pfoot) - count($ptfoot) + 1" format="1"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<xsl:template match="*" mode="footnote.body.number">
+  <xsl:variable name="footnote.mark">
+    <fo:inline baseline-shift="super" font-size="90%">
+      <xsl:apply-templates select="ancestor::footnote" mode="footnote.number"/>
+    </fo:inline>
+  </xsl:variable>
+
+  <xsl:variable name="fo">
+    <xsl:apply-templates select="."/>
+  </xsl:variable>
+
+  <xsl:variable name="fo-nodes" select="exsl:node-set($fo)"/>
+
+  <xsl:choose>
+    <xsl:when test="$fo-nodes//fo:block">
+      <xsl:apply-templates select="$fo-nodes" mode="insert.fo.fnum">
+        <xsl:with-param name="mark" select="$footnote.mark"/>
+      </xsl:apply-templates>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:apply-templates select="$fo-nodes" mode="insert.fo.text">
+        <xsl:with-param name="mark" select="$footnote.mark"/>
+      </xsl:apply-templates>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <!-- ==================================================================== -->
   </fo:block>
 </xsl:template>
 
+<xsl:template match="footnote" name="process.footnote" mode="table.footnote.mode">
+  <xsl:choose>
+    <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
+      <fo:block>
+        <xsl:apply-templates/>
+      </fo:block>
+    </xsl:when>
+
+    <xsl:when test="function-available('exsl:node-set')">
+      <fo:block>
+        <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
+        <xsl:apply-templates select="*[position() &gt; 1]"/>
+      </fo:block>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:message>
+        <xsl:text>Warning: footnote number may not be generated </xsl:text>
+        <xsl:text>correctly; </xsl:text>
+        <xsl:value-of select="local-name(*[1])"/>
+        <xsl:text> unexpected as first child of footnote.</xsl:text>
+      </xsl:message>
+      <fo:block>
+        <xsl:apply-templates/>
+      </fo:block>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>
index e61245d08d6364c93edcf1120486da268864a0da..afbb85e46f555395cf0ff2b4484f86558c8d1940 100644 (file)
     </fo:table-and-caption>
   </xsl:variable>
 
+  <xsl:variable name="footnotes">
+    <xsl:if test=".//footnote">
+      <fo:block>
+        <xsl:apply-templates select=".//footnote" mode="table.footnote.mode"/>
+      </fo:block>
+    </xsl:if>
+  </xsl:variable>
+
   <xsl:choose>
     <xsl:when test="@orient='land'">
       <fo:block-container reference-orientation="90">
             </xsl:choose>
           </xsl:attribute>
           <xsl:copy-of select="$table.content"/>
+          <xsl:copy-of select="$footnotes"/>
         </fo:block>
       </fo:block-container>
     </xsl:when>
           </xsl:choose>
         </xsl:attribute>
         <xsl:copy-of select="$table.content"/>
+        <xsl:copy-of select="$footnotes"/>
       </fo:block>
     </xsl:otherwise>
   </xsl:choose>
     </fo:table>
   </xsl:variable>
 
+  <xsl:variable name="footnotes">
+    <xsl:if test=".//footnote">
+      <fo:block font-family="{$body.font.family}"
+                font-size="{$footnote.font.size}">
+        <xsl:apply-templates select=".//footnote" mode="table.footnote.mode"/>
+      </fo:block>
+    </xsl:if>
+  </xsl:variable>
+
   <xsl:choose>
     <xsl:when test="@orient='land'">
       <fo:block-container reference-orientation="90">
             </xsl:choose>
           </xsl:attribute>
           <xsl:copy-of select="$table.content"/>
+          <xsl:copy-of select="$footnotes"/>
         </fo:block>
       </fo:block-container>
     </xsl:when>
           </xsl:choose>
         </xsl:attribute>
         <xsl:copy-of select="$table.content"/>
+        <xsl:copy-of select="$footnotes"/>
       </fo:block>
     </xsl:otherwise>
   </xsl:choose>