]> granicus.if.org Git - docbook-dsssl/commitdiff
Support DocBook toc markup
authorNorman Walsh <ndw@nwalsh.com>
Sun, 15 Apr 2001 21:26:52 +0000 (21:26 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Sun, 15 Apr 2001 21:26:52 +0000 (21:26 +0000)
xsl/fo/toc.xsl
xsl/html/toc.xsl

index ea8c93fc792a0d8c614bc4a152441fcc191949d5..3893ccb3b98c41d5d6552e40bd48c52b332fa5ab 100644 (file)
 
 <!-- ==================================================================== -->
 
+<!-- FIXME: in the contexts where <toc> can occur, I think it's always
+     the case that a page-sequence is required. Is that true? -->
+
 <xsl:template match="toc">
+  <xsl:variable name="master-name">
+    <xsl:call-template name="select.pagemaster"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="*">
+      <xsl:if test="$process.source.toc != 0">
+        <!-- if the toc isn't empty, process it -->
+        <fo:page-sequence hyphenate="{$hyphenate}"
+                          master-name="{$master-name}">
+          <xsl:attribute name="language">
+            <xsl:call-template name="l10n.language"/>
+          </xsl:attribute>
+          <xsl:if test="$double.sided != 0">
+            <xsl:attribute name="force-page-count">end-on-even</xsl:attribute>
+          </xsl:if>
+
+          <xsl:apply-templates select="." mode="running.head.mode">
+            <xsl:with-param name="master-name" select="$master-name"/>
+          </xsl:apply-templates>
+          <xsl:apply-templates select="." mode="running.foot.mode">
+            <xsl:with-param name="master-name" select="$master-name"/>
+          </xsl:apply-templates>
+
+          <fo:flow flow-name="xsl-region-body">
+            <fo:block xsl:use-attribute-sets="toc.margin.properties">
+              <xsl:call-template name="table.of.contents.titlepage"/>
+              <xsl:apply-templates/>
+            </fo:block>
+          </fo:flow>
+        </fo:page-sequence>
+      </xsl:if>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:if test="$process.empty.source.toc != 0">
+        <fo:page-sequence hyphenate="{$hyphenate}"
+                          master-name="{$master-name}">
+          <xsl:attribute name="language">
+            <xsl:call-template name="l10n.language"/>
+          </xsl:attribute>
+          <xsl:if test="$double.sided != 0">
+            <xsl:attribute name="force-page-count">end-on-even</xsl:attribute>
+          </xsl:if>
+
+          <xsl:apply-templates select="." mode="running.head.mode">
+            <xsl:with-param name="master-name" select="$master-name"/>
+          </xsl:apply-templates>
+          <xsl:apply-templates select="." mode="running.foot.mode">
+            <xsl:with-param name="master-name" select="$master-name"/>
+          </xsl:apply-templates>
+
+          <fo:flow flow-name="xsl-region-body">
+            <xsl:choose>
+              <xsl:when test="parent::section
+                              or parent::sect1
+                              or parent::sect2
+                              or parent::sect3
+                              or parent::sect4
+                              or parent::sect5">
+                <xsl:apply-templates select="parent::*"
+                                     mode="toc.for.section"/>
+              </xsl:when>
+              <xsl:when test="parent::article">
+                <xsl:apply-templates select="parent::*"
+                                     mode="toc.for.component"/>
+              </xsl:when>
+              <xsl:when test="parent::book
+                              or parent::part">
+                <xsl:apply-templates select="parent::*"
+                                     mode="toc.for.division"/>
+              </xsl:when>
+              <xsl:when test="parent::set">
+                <xsl:apply-templates select="parent::*"
+                                     mode="toc.for.set"/>
+              </xsl:when>
+              <!-- there aren't any other contexts that allow toc -->
+              <xsl:otherwise>
+                <xsl:message>
+                  <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
+                </xsl:message>
+              </xsl:otherwise>
+            </xsl:choose>
+          </fo:flow>
+        </fo:page-sequence>
+      </xsl:if>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="tocpart|tocchap
+                     |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
+  <xsl:apply-templates select="tocentry"/>
+  <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
+    <fo:block start-indent="{count(ancestor::*)*2}pc">
+      <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
+    </fo:block>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="tocentry|tocfront|tocback">
+  <fo:block text-align-last="justify"
+            end-indent="2pc"
+            last-line-end-indent="-2pc">
+    <fo:inline keep-with-next.within-line="always">
+      <xsl:choose>
+        <xsl:when test="@linkend">
+          <fo:basic-link internal-destination="{@linkend}">
+            <xsl:apply-templates/>
+          </fo:basic-link>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </fo:inline>
+
+    <xsl:choose>
+      <xsl:when test="@linkend">
+        <fo:inline keep-together.within-line="always">
+          <xsl:text> </xsl:text>
+          <fo:leader leader-pattern="dots"
+                     keep-with-next.within-line="always"/>
+          <xsl:text> </xsl:text>
+          <fo:basic-link internal-destination="{@linkend}">
+            <xsl:choose>
+              <xsl:when test="@pagenum">
+                <xsl:value-of select="@pagenum"/>
+              </xsl:when>
+              <xsl:otherwise>
+                <fo:page-number-citation ref-id="{@linkend}"/>
+              </xsl:otherwise>
+            </xsl:choose>
+          </fo:basic-link>
+        </fo:inline>
+      </xsl:when>
+      <xsl:when test="@pagenum">
+        <fo:inline keep-together.within-line="always">
+          <xsl:text> </xsl:text>
+          <fo:leader leader-pattern="dots"
+                     keep-with-next.within-line="always"/>
+          <xsl:text> </xsl:text>
+          <xsl:value-of select="@pagenum"/>
+        </fo:inline>
+      </xsl:when>
+      <xsl:otherwise>
+        <!-- just the leaders, what else can I do? -->
+        <fo:inline keep-together.within-line="always">
+          <xsl:text> </xsl:text>
+          <fo:leader leader-pattern="space"
+                     keep-with-next.within-line="always"/>
+        </fo:inline>
+      </xsl:otherwise>
+    </xsl:choose>
+  </fo:block>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<xsl:template match="*" mode="toc.for.section">
+<!--
+  <xsl:call-template name="section.toc"/>
+-->
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.component">
+  <xsl:call-template name="component.toc"/>
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.section">
+<!--
+  <xsl:call-template name="section.toc"/>
+-->
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.division">
+  <xsl:call-template name="division.toc"/>
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.set">
+<!--
+  <xsl:call-template name="set.toc"/>
+-->
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<xsl:template match="lot|lotentry">
 </xsl:template>
 
 </xsl:stylesheet>
index 55d471626bc86388ddcef9a58b35e9ab09f1082d..f33a1a141d81395cfc583d74d2071eb05e9662a3 100644 (file)
 <!-- ==================================================================== -->
 
 <xsl:template match="toc">
+  <xsl:choose>
+    <xsl:when test="*">
+      <xsl:if test="$process.source.toc != 0">
+        <!-- if the toc isn't empty, process it -->
+        <xsl:element name="{$toc.list.type}">
+          <xsl:apply-templates/>
+        </xsl:element>
+      </xsl:if>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:if test="$process.empty.source.toc != 0">
+        <xsl:choose>
+          <xsl:when test="parent::section
+                          or parent::sect1
+                          or parent::sect2
+                          or parent::sect3
+                          or parent::sect4
+                          or parent::sect5">
+            <xsl:apply-templates select="parent::*"
+                                 mode="toc.for.section"/>
+          </xsl:when>
+          <xsl:when test="parent::article">
+            <xsl:apply-templates select="parent::*"
+                                 mode="toc.for.component"/>
+          </xsl:when>
+          <xsl:when test="parent::book
+                          or parent::part">
+            <xsl:apply-templates select="parent::*"
+                                 mode="toc.for.division"/>
+          </xsl:when>
+          <xsl:when test="parent::set">
+            <xsl:apply-templates select="parent::*"
+                                 mode="toc.for.set"/>
+          </xsl:when>
+          <!-- there aren't any other contexts that allow toc -->
+          <xsl:otherwise>
+            <xsl:message>
+              <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
+            </xsl:message>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:if>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
-<xsl:template match="tocpart|tocchap|tocfront|tocback|tocentry">
+<xsl:template match="tocpart|tocchap
+                     |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
+  <xsl:variable name="sub-toc">
+    <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
+      <xsl:choose>
+        <xsl:when test="$toc.list.type = 'dl'">
+          <dd>
+            <xsl:element name="{$toc.list.type}">
+              <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
+            </xsl:element>
+          </dd>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:element name="{$toc.list.type}">
+            <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
+          </xsl:element>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:if>
+  </xsl:variable>
+
+  <xsl:apply-templates select="tocentry[position() != last()]"/>
+
+  <xsl:choose>
+    <xsl:when test="$toc.list.type = 'dl'">
+      <dt>
+        <xsl:apply-templates select="tocentry[position() = last()]"/>
+      </dt>
+      <xsl:copy-of select="$sub-toc"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <li>
+        <xsl:apply-templates select="tocentry[position() = last()]"/>
+        <xsl:copy-of select="$sub-toc"/>
+      </li>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="tocentry|tocfront|tocback">
+  <xsl:choose>
+    <xsl:when test="$toc.list.type = 'dl'">
+      <dt>
+        <xsl:call-template name="tocentry-content"/>
+      </dt>
+    </xsl:when>
+    <xsl:otherwise>
+      <li>
+        <xsl:call-template name="tocentry-content"/>
+      </li>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="tocentry[position() = last()]" priority="2">
+  <xsl:call-template name="tocentry-content"/>
+</xsl:template>
+
+<xsl:template name="tocentry-content">
+  <xsl:variable name="targets" select="id(@linkend)"/>
+  <xsl:variable name="target" select="$targets[1]"/>
+
+  <xsl:choose>
+    <xsl:when test="@linkend">
+      <xsl:call-template name="check.id.unique">
+        <xsl:with-param name="linkend" select="@linkend"/>
+      </xsl:call-template>
+      <a>
+        <xsl:attribute name="href">
+          <xsl:call-template name="href.target">
+            <xsl:with-param name="object" select="$target"/>
+          </xsl:call-template>
+        </xsl:attribute>
+        <xsl:apply-templates/>
+      </a>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:apply-templates/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<xsl:template match="*" mode="toc.for.section">
+  <xsl:call-template name="section.toc"/>
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.component">
+  <xsl:call-template name="component.toc"/>
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.section">
+  <xsl:call-template name="section.toc"/>
+</xsl:template>
+
+<xsl:template match="*" mode="toc.for.division">
+  <xsl:call-template name="division.toc"/>
 </xsl:template>
 
-<xsl:template match="toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
+<xsl:template match="*" mode="toc.for.set">
+  <xsl:call-template name="set.toc"/>
 </xsl:template>
 
 <!-- ==================================================================== -->