| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 3 |
version='1.0'> |
| 4 |
|
| 5 |
<!-- ******************************************************************** |
| 6 |
$Id: toc.xsl 6910 2007-06-28 23:23:30Z xmldoc $ |
| 7 |
******************************************************************** |
| 8 |
|
| 9 |
This file is part of the XSL DocBook Stylesheet distribution. |
| 10 |
See ../README or http://docbook.sf.net/release/xsl/current/ for |
| 11 |
copyright and other information. |
| 12 |
|
| 13 |
******************************************************************** --> |
| 14 |
|
| 15 |
<!-- ==================================================================== --> |
| 16 |
|
| 17 |
<xsl:template match="toc"> |
| 18 |
<xsl:choose> |
| 19 |
<xsl:when test="*"> |
| 20 |
<xsl:if test="$process.source.toc != 0"> |
| 21 |
<!-- if the toc isn't empty, process it --> |
| 22 |
<xsl:element name="{$toc.list.type}"> |
| 23 |
<xsl:apply-templates/> |
| 24 |
</xsl:element> |
| 25 |
</xsl:if> |
| 26 |
</xsl:when> |
| 27 |
<xsl:otherwise> |
| 28 |
<xsl:if test="$process.empty.source.toc != 0"> |
| 29 |
<xsl:choose> |
| 30 |
<xsl:when test="parent::section |
| 31 |
or parent::sect1 |
| 32 |
or parent::sect2 |
| 33 |
or parent::sect3 |
| 34 |
or parent::sect4 |
| 35 |
or parent::sect5"> |
| 36 |
<xsl:apply-templates select="parent::*" |
| 37 |
mode="toc.for.section"/> |
| 38 |
</xsl:when> |
| 39 |
<xsl:when test="parent::article"> |
| 40 |
<xsl:apply-templates select="parent::*" |
| 41 |
mode="toc.for.component"/> |
| 42 |
</xsl:when> |
| 43 |
<xsl:when test="parent::book |
| 44 |
or parent::part"> |
| 45 |
<xsl:apply-templates select="parent::*" |
| 46 |
mode="toc.for.division"/> |
| 47 |
</xsl:when> |
| 48 |
<xsl:when test="parent::set"> |
| 49 |
<xsl:apply-templates select="parent::*" |
| 50 |
mode="toc.for.set"/> |
| 51 |
</xsl:when> |
| 52 |
<!-- there aren't any other contexts that allow toc --> |
| 53 |
<xsl:otherwise> |
| 54 |
<xsl:message> |
| 55 |
<xsl:text>I don't know how to make a TOC in this context!</xsl:text> |
| 56 |
</xsl:message> |
| 57 |
</xsl:otherwise> |
| 58 |
</xsl:choose> |
| 59 |
</xsl:if> |
| 60 |
</xsl:otherwise> |
| 61 |
</xsl:choose> |
| 62 |
</xsl:template> |
| 63 |
|
| 64 |
<xsl:template match="tocpart|tocchap |
| 65 |
|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"> |
| 66 |
<xsl:variable name="sub-toc"> |
| 67 |
<xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"> |
| 68 |
<xsl:choose> |
| 69 |
<xsl:when test="$toc.list.type = 'dl'"> |
| 70 |
<dd> |
| 71 |
<xsl:element name="{$toc.list.type}"> |
| 72 |
<xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/> |
| 73 |
</xsl:element> |
| 74 |
</dd> |
| 75 |
</xsl:when> |
| 76 |
<xsl:otherwise> |
| 77 |
<xsl:element name="{$toc.list.type}"> |
| 78 |
<xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/> |
| 79 |
</xsl:element> |
| 80 |
</xsl:otherwise> |
| 81 |
</xsl:choose> |
| 82 |
</xsl:if> |
| 83 |
</xsl:variable> |
| 84 |
|
| 85 |
<xsl:apply-templates select="tocentry[position() != last()]"/> |
| 86 |
|
| 87 |
<xsl:choose> |
| 88 |
<xsl:when test="$toc.list.type = 'dl'"> |
| 89 |
<dt> |
| 90 |
<xsl:apply-templates select="tocentry[position() = last()]"/> |
| 91 |
</dt> |
| 92 |
<xsl:copy-of select="$sub-toc"/> |
| 93 |
</xsl:when> |
| 94 |
<xsl:otherwise> |
| 95 |
<li> |
| 96 |
<xsl:apply-templates select="tocentry[position() = last()]"/> |
| 97 |
<xsl:copy-of select="$sub-toc"/> |
| 98 |
</li> |
| 99 |
</xsl:otherwise> |
| 100 |
</xsl:choose> |
| 101 |
</xsl:template> |
| 102 |
|
| 103 |
<xsl:template match="tocentry|tocfront|tocback"> |
| 104 |
<xsl:choose> |
| 105 |
<xsl:when test="$toc.list.type = 'dl'"> |
| 106 |
<dt> |
| 107 |
<xsl:call-template name="tocentry-content"/> |
| 108 |
</dt> |
| 109 |
</xsl:when> |
| 110 |
<xsl:otherwise> |
| 111 |
<li> |
| 112 |
<xsl:call-template name="tocentry-content"/> |
| 113 |
</li> |
| 114 |
</xsl:otherwise> |
| 115 |
</xsl:choose> |
| 116 |
</xsl:template> |
| 117 |
|
| 118 |
<xsl:template match="tocentry[position() = last()]" priority="2"> |
| 119 |
<xsl:call-template name="tocentry-content"/> |
| 120 |
</xsl:template> |
| 121 |
|
| 122 |
<xsl:template name="tocentry-content"> |
| 123 |
<xsl:variable name="targets" select="key('id',@linkend)"/> |
| 124 |
<xsl:variable name="target" select="$targets[1]"/> |
| 125 |
|
| 126 |
<xsl:choose> |
| 127 |
<xsl:when test="@linkend"> |
| 128 |
<xsl:call-template name="check.id.unique"> |
| 129 |
<xsl:with-param name="linkend" select="@linkend"/> |
| 130 |
</xsl:call-template> |
| 131 |
<a> |
| 132 |
<xsl:attribute name="href"> |
| 133 |
<xsl:call-template name="href.target"> |
| 134 |
<xsl:with-param name="object" select="$target"/> |
| 135 |
</xsl:call-template> |
| 136 |
</xsl:attribute> |
| 137 |
<xsl:apply-templates/> |
| 138 |
</a> |
| 139 |
</xsl:when> |
| 140 |
<xsl:otherwise> |
| 141 |
<xsl:apply-templates/> |
| 142 |
</xsl:otherwise> |
| 143 |
</xsl:choose> |
| 144 |
</xsl:template> |
| 145 |
|
| 146 |
<!-- ==================================================================== --> |
| 147 |
|
| 148 |
<xsl:template match="*" mode="toc.for.section"> |
| 149 |
<xsl:call-template name="section.toc"/> |
| 150 |
</xsl:template> |
| 151 |
|
| 152 |
<xsl:template match="*" mode="toc.for.component"> |
| 153 |
<xsl:call-template name="component.toc"/> |
| 154 |
</xsl:template> |
| 155 |
|
| 156 |
<xsl:template match="*" mode="toc.for.section"> |
| 157 |
<xsl:call-template name="section.toc"/> |
| 158 |
</xsl:template> |
| 159 |
|
| 160 |
<xsl:template match="*" mode="toc.for.division"> |
| 161 |
<xsl:call-template name="division.toc"/> |
| 162 |
</xsl:template> |
| 163 |
|
| 164 |
<xsl:template match="*" mode="toc.for.set"> |
| 165 |
<xsl:call-template name="set.toc"/> |
| 166 |
</xsl:template> |
| 167 |
|
| 168 |
<!-- ==================================================================== --> |
| 169 |
|
| 170 |
<xsl:template match="lot|lotentry"> |
| 171 |
</xsl:template> |
| 172 |
|
| 173 |
</xsl:stylesheet> |