]> granicus.if.org Git - docbook-dsssl/commitdiff
Support section ToCs
authorNorman Walsh <ndw@nwalsh.com>
Fri, 27 Sep 2002 13:03:15 +0000 (13:03 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Fri, 27 Sep 2002 13:03:15 +0000 (13:03 +0000)
xsl/fo/autotoc.xsl
xsl/fo/sections.xsl

index da8c606a7c7877029d38f861000ff88f00aef957..bf5267b92c5248fbe50ca4acf2a0df4ba7a0db35 100644 (file)
   </xsl:if>
 </xsl:template>
 
+<xsl:template name="section.toc">
+  <xsl:param name="toc-context" select="."/>
+
+  <xsl:variable name="id">
+    <xsl:call-template name="object.id"/>
+  </xsl:variable>
+
+  <xsl:variable name="cid">
+    <xsl:call-template name="object.id">
+      <xsl:with-param name="object" select="$toc-context"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:variable name="nodes"
+                select="section|sect1|sect2|sect3|sect4|sect5|refentry
+                        |bridgehead[$bridgehead.in.toc != 0]"/>
+
+  <xsl:variable name="level">
+    <xsl:call-template name="section.level"/>
+  </xsl:variable>
+
+  <xsl:if test="$nodes">
+    <fo:block id="toc...{$id}"
+              xsl:use-attribute-sets="toc.margin.properties">
+
+      <xsl:call-template name="section.heading">
+        <xsl:with-param name="level" select="$level + 1"/>
+        <xsl:with-param name="title">
+          <fo:block space-after="0.5em">
+            <xsl:call-template name="gentext">
+              <xsl:with-param name="key" select="'TableofContents'"/>
+            </xsl:call-template>
+          </fo:block>
+        </xsl:with-param>
+      </xsl:call-template>
+
+      <xsl:apply-templates select="$nodes" mode="toc">
+        <xsl:with-param name="toc-context" select="$toc-context"/>
+      </xsl:apply-templates>
+    </fo:block>
+  </xsl:if>
+</xsl:template>
+
 <!-- ==================================================================== -->
 
 <xsl:template name="toc.line">
 
   <xsl:call-template name="toc.line"/>
 
+  <xsl:variable name="reldepth"
+                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
+
   <xsl:if test="$toc.section.depth &gt; 2 and sect3">
     <fo:block id="toc.{$cid}.{$id}"
-              start-indent="{count(ancestor::*)*$toc.indent.width}pt">
+              start-indent="{$reldepth*$toc.indent.width}pt">
       <xsl:apply-templates select="sect3" mode="toc">
         <xsl:with-param name="toc-context" select="$toc-context"/>
       </xsl:apply-templates>
 
   <xsl:call-template name="toc.line"/>
 
+  <xsl:variable name="reldepth"
+                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
+
   <xsl:if test="$toc.section.depth &gt; 3 and sect4">
     <fo:block id="toc.{$cid}.{$id}"
-              start-indent="{count(ancestor::*)*$toc.indent.width}pt">
+              start-indent="{$reldepth*$toc.indent.width}pt">
       <xsl:apply-templates select="sect4" mode="toc">
         <xsl:with-param name="toc-context" select="$toc-context"/>
       </xsl:apply-templates>
 
   <xsl:call-template name="toc.line"/>
 
+  <xsl:variable name="reldepth"
+                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
+
   <xsl:if test="$toc.section.depth &gt; 4 and sect5">
     <fo:block id="toc.{$cid}.{$id}"
-              start-indent="{count(ancestor::*)*$toc.indent.width}pt">
+              start-indent="{$reldepth*$toc.indent.width}pt">
       <xsl:apply-templates select="sect5" mode="toc">
         <xsl:with-param name="toc-context" select="$toc-context"/>
       </xsl:apply-templates>
   </xsl:variable>
 
   <xsl:variable name="depth" select="count(ancestor::section) + 1"/>
+  <xsl:variable name="reldepth"
+                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
 
   <xsl:if test="$toc.section.depth &gt;= $depth">
     <xsl:call-template name="toc.line"/>
 
     <xsl:if test="$toc.section.depth &gt; $depth and section">
       <fo:block id="toc.{$cid}.{$id}"
-                start-indent="{count(ancestor::*)*$toc.indent.width}pt">
+                start-indent="{$reldepth*$toc.indent.width}pt">
         <xsl:apply-templates select="section" mode="toc">
           <xsl:with-param name="toc-context" select="$toc-context"/>
         </xsl:apply-templates>
index 6eef811a894359e2f9e85f514c73f01739f4b230..4420adcba5fa048857dab4d0933c23d13f001d03 100644 (file)
 
   <fo:block id="{$id}">
     <xsl:call-template name="section.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and (count(ancestor::section)+1) &lt;= $generate.section.toc.level)
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
     <fo:flow flow-name="xsl-region-body">
       <xsl:call-template name="section.titlepage"/>
+
+      <xsl:variable name="toc.params">
+        <xsl:call-template name="find.path.params">
+          <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+        </xsl:call-template>
+      </xsl:variable>
+
+      <xsl:if test="(contains($toc.params, 'toc')
+                     and (count(ancestor::section)+1) &lt;= $generate.section.toc.level)
+                    or refentry">
+        <xsl:call-template name="section.toc"/>
+      </xsl:if>
+
       <xsl:apply-templates/>
    </fo:flow>
   </fo:page-sequence>
 
   <fo:block id="{$id}">
     <xsl:call-template name="sect1.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and ($generate.section.toc.level &gt;= 1))
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
     <fo:flow flow-name="xsl-region-body">
       <xsl:call-template name="sect1.titlepage"/>
+
+      <xsl:variable name="toc.params">
+        <xsl:call-template name="find.path.params">
+          <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+        </xsl:call-template>
+      </xsl:variable>
+
+      <xsl:if test="(contains($toc.params, 'toc')
+                     and ($generate.section.toc.level &gt;= 1))
+                    or refentry">
+        <xsl:call-template name="section.toc"/>
+      </xsl:if>
+
       <xsl:apply-templates/>
    </fo:flow>
   </fo:page-sequence>
 
   <fo:block id="{$id}">
     <xsl:call-template name="sect2.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and ($generate.section.toc.level &gt;= 2))
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
   <fo:block id="{$id}">
     <xsl:call-template name="sect3.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and ($generate.section.toc.level &gt;= 3))
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
   <fo:block id="{$id}">
     <xsl:call-template name="sect4.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and ($generate.section.toc.level &gt;= 4))
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
   <fo:block id="{$id}">
     <xsl:call-template name="sect5.titlepage"/>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="(contains($toc.params, 'toc')
+                   and ($generate.section.toc.level &gt;= 5))
+                  or refentry">
+      <xsl:call-template name="section.toc"/>
+    </xsl:if>
+
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>