aboutsummaryrefslogtreecommitdiffstats
path: root/stylesheets/lfs-xsl/xhtml/lfs-toc.xsl
blob: 36c4ba3fec8c6ad401384638d4f3ed55c690083b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?xml version='1.0' encoding='UTF-8'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/xhtml"
                version="1.0">

  <!-- This stylesheet controls how the TOC are generated -->

    <!-- make.toc:
           Using h3 for TOC title.
           Using ul for TOC list style.
           Removed code for $manual.toc and $qanda.in.toc -->
    <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  <xsl:template name="make.toc">
    <xsl:param name="toc-context" select="."/>
    <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
    <xsl:if test="$nodes">
      <div class="toc">
        <h3>
          <xsl:call-template name="gentext">
            <xsl:with-param name="key">TableofContents</xsl:with-param>
          </xsl:call-template>
        </h3>
        <ul>
          <xsl:apply-templates select="$nodes" mode="toc">
            <xsl:with-param name="toc-context" select="$toc-context"/>
          </xsl:apply-templates>
        </ul>
      </div>
    </xsl:if>
  </xsl:template>

    <!-- subtoc:
           Using ul for TOC list style.
           Removed code for $qanda.in.toc
           Removed code for sect* others than sect1 -->
    <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  <xsl:template name="subtoc">
    <xsl:param name="toc-context" select="."/>
    <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
    <xsl:variable name="subtoc">
      <ul>
        <xsl:apply-templates mode="toc" select="$nodes">
          <xsl:with-param name="toc-context" select="$toc-context"/>
        </xsl:apply-templates>
      </ul>
    </xsl:variable>
    <xsl:variable name="depth">
      <xsl:choose>
        <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="depth.from.context"
                  select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
    <li class="{name(.)}">
      <xsl:call-template name="toc.line">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:call-template>
      <xsl:if test="$toc.section.depth &gt; $depth and count($nodes)&gt;0
                    and $toc.max.depth &gt; $depth.from.context">
        <xsl:copy-of select="$subtoc"/>
      </xsl:if>
    </li>
  </xsl:template>

    <!-- toc.line:
           Adding the h* tags and dropping unneded links.
           This template is a full re-made version of the original one. -->
    <!-- The original template is in {docbook-xsl}/xhtml/autotoc.xsl -->
  <xsl:template name="toc.line">
    <xsl:param name="toc-context" select="."/>
    <xsl:choose>
        <!-- For non dummy sect1 targets, create a link. -->
      <xsl:when test="local-name(.) = 'sect1'">
        <xsl:choose>
          <xsl:when test="@role='dummy'">
            <span class="dummy">
              <xsl:apply-templates select="." mode="titleabbrev.markup"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <a>
              <xsl:attribute name="href">
                <xsl:call-template name="href.target">
                  <xsl:with-param name="context" select="$toc-context"/>
                </xsl:call-template>
              </xsl:attribute>
              <xsl:apply-templates select="." mode="titleabbrev.markup"/>
            </a>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
        <!-- For part, preface, and chapter, use hX and add the label.
             For BLFS, make it a link. -->
      <xsl:when test="local-name(.) = 'part' or local-name(.) = 'preface'
                      or local-name(.) = 'chapter'">
        <xsl:choose>
          <xsl:when test="$book-type = 'blfs'">
            <xsl:apply-templates select="." mode="add.hX">
              <xsl:with-param name="toc-context" select="$toc-context"/>
              <xsl:with-param name="with-link" select="1"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="." mode="add.hX">
              <xsl:with-param name="toc-context" select="$toc-context"/>
              <xsl:with-param name="with-link" select="0"/>
            </xsl:apply-templates>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
        <!-- For appendix , create a link and add the label.
             For BLFS, use hX. -->
      <xsl:when test="local-name(.) = 'appendix'">
        <xsl:choose>
          <xsl:when test="$book-type = 'blfs'">
            <xsl:apply-templates select="." mode="add.hX">
              <xsl:with-param name="toc-context" select="$toc-context"/>
              <xsl:with-param name="with-link" select="1"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="." mode="add.link">
              <xsl:with-param name="toc-context" select="$toc-context"/>
            </xsl:apply-templates>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
        <!-- For other targets like Index, use hX, create a link, and label it. -->
      <xsl:otherwise>
        <xsl:apply-templates select="." mode="add.hX">
          <xsl:with-param name="toc-context" select="$toc-context"/>
          <xsl:with-param name="with-link" select="1"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

    <!-- Self-made template to add hX tags to toc lines. -->
  <xsl:template match="*" mode="add.hX">
    <xsl:param name="toc-context" select="."/>
    <xsl:param name="with-link" select="0"/>
    <xsl:param name="hlevel">
      <xsl:choose>
        <xsl:when test="local-name(.)='chapter' or local-name(.)='preface'">4</xsl:when>
        <xsl:otherwise>3</xsl:otherwise>
      </xsl:choose>
    </xsl:param>
    <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
      <xsl:choose>
        <xsl:when test="$with-link != 0">
          <xsl:apply-templates select="." mode="add.link">
            <xsl:with-param name="toc-context" select="$toc-context"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="." mode="label.and.title"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:template>

    <!-- Self-made template to made toc line a link. -->
  <xsl:template match="*" mode="add.link">
    <xsl:param name="toc-context" select="."/>
    <a>
      <xsl:attribute name="href">
        <xsl:call-template name="href.target">
          <xsl:with-param name="context" select="$toc-context"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="label.and.title"/>
    </a>
  </xsl:template>

    <!-- Self-made template to write the target title and label it. -->
  <xsl:template match="*" mode="label.and.title">
    <xsl:variable name="label">
      <xsl:apply-templates select="." mode="label.markup"/>
    </xsl:variable>
    <xsl:copy-of select="$label"/>
    <xsl:if test="$label != ''">
      <xsl:value-of select="$autotoc.label.separator"/>
    </xsl:if>
    <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  </xsl:template>

</xsl:stylesheet>