summaryrefslogtreecommitdiff
path: root/xslt/docbook/html/db2html-footnote.xsl
blob: 255b44a6f835359d66bb3a9f01edff756f2e4756 (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
<!--
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License
along with this program; see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>.
-->

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

<!--!!==========================================================================
DocBook to HTML - Footnotes
:Requires: db-chunk db-label

FIXME: Describe this module
-->


<!--**==========================================================================
db2html.footnote.ref
Generates a superscript link to a footnote
$node: The #{footnote} element to process

REMARK: Describe this template
-->
<xsl:template name="db2html.footnote.ref">
  <xsl:param name="node" select="."/>
  <xsl:variable name="anchor">
    <xsl:text>-noteref-</xsl:text>
    <xsl:choose>
      <xsl:when test="$node/@id">
        <xsl:value-of select="$node/@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="generate-id($node)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="href">
    <xsl:text>#</xsl:text>
    <xsl:choose>
      <xsl:when test="$node/@id">
        <xsl:value-of select="$node/@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>-note-</xsl:text>
        <xsl:value-of select="generate-id($node)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <a name="{$anchor}"/>
  <sup>
    <a class="footnote" href="{$href}">
      <xsl:call-template name="db.number">
        <xsl:with-param name="node" select="$node"/>
      </xsl:call-template>
    </a>
  </sup>
</xsl:template>


<!--**==========================================================================
db2html.footnote.note
Generates a footnote
$node: The #{footnote} element to process

REMARK: Describe this template
-->
<xsl:template name="db2html.footnote.note">
  <xsl:param name="node" select="."/>
  <xsl:variable name="anchor">
    <xsl:choose>
      <xsl:when test="$node/@id">
        <xsl:value-of select="$node/@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>-note-</xsl:text>
        <xsl:value-of select="generate-id($node)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="href">
    <xsl:text>#</xsl:text>
    <xsl:text>-noteref-</xsl:text>
    <xsl:choose>
      <xsl:when test="$node/@id">
        <xsl:value-of select="$node/@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="generate-id($node)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <div class="footnote">
    <a name="{$anchor}"/>
    <span class="footnote-number">
      <a class="footnote-ref" href="{$href}">
        <xsl:call-template name="db.number">
          <xsl:with-param name="node" select="$node"/>
        </xsl:call-template>
      </a>
    </span>
    <xsl:apply-templates select="$node/node()"/>
  </div>
</xsl:template>


<!--**==========================================================================
db2html.footnote.footer
Generates a foot containing all the footnotes in the chunk
$node: The division element containing footnotes
$depth_of_chunk: The depth of the containing chunk in the document

REMARK: Describe this template
-->
<xsl:template name="db2html.footnote.footer">
  <xsl:param name="node" select="."/>
  <xsl:param name="depth_of_chunk">
    <xsl:call-template name="db.chunk.depth-of-chunk"/>
  </xsl:param>
  <xsl:variable name="notes" select="$node//footnote" />
  <xsl:if test="count($notes) != 0">
    <xsl:call-template name="db2html.footnote.footer.sibling">
      <xsl:with-param name="node" select="$node"/>
      <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
      <xsl:with-param name="notes" select="$notes"/>
      <xsl:with-param name="pos" select="1"/>
      <xsl:with-param name="div" select="false()"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<!--#* db2html.footnote.footer.sibling -->
<xsl:template name="db2html.footnote.footer.sibling">
  <xsl:param name="node"/>
  <xsl:param name="depth_of_chunk"/>
  <xsl:param name="notes"/>
  <xsl:param name="pos"/>
  <xsl:param name="div"/>
  <xsl:variable name="this" select="$notes[$pos]"/>
  <xsl:variable name="depth">
    <xsl:call-template name="db.chunk.depth-of-chunk">
      <xsl:with-param name="node" select="$this"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="($depth = $depth_of_chunk) and not($div)">
      <div class="footnotes">
        <xsl:call-template name="db2html.footnote.note">
          <xsl:with-param name="node" select="$this"/>
        </xsl:call-template>
        <xsl:if test="$pos &lt; count($notes)">
          <xsl:call-template name="db2html.footnote.footer.sibling">
            <xsl:with-param name="node" select="$node"/>
            <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
            <xsl:with-param name="notes" select="$notes"/>
            <xsl:with-param name="pos" select="$pos + 1"/>
            <xsl:with-param name="div" select="true()"/>
          </xsl:call-template>
        </xsl:if>
      </div>
    </xsl:when>
    <xsl:otherwise>
      <xsl:if test="$depth = $depth_of_chunk">
        <xsl:call-template name="db2html.footnote.note">
          <xsl:with-param name="node" select="$this"/>
        </xsl:call-template>
      </xsl:if>
      <xsl:if test="$pos &lt; count($notes)">
        <xsl:call-template name="db2html.footnote.footer.sibling">
          <xsl:with-param name="node" select="$node"/>
          <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
          <xsl:with-param name="notes" select="$notes"/>
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="div" select="$div"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!--**==========================================================================
db2html.footnote.css
Outputs CSS that controls the appearance of footnotes

REMARK: Describe this template
-->
<xsl:template name="db2html.footnote.css">
<xsl:text>
div.footnotes { font-style: italic; font-size: 0.8em; }
div.footnote { margin-top: 1.44em; }
span.footnote-number { display: inline; padding-right: 0.83em; }
span.footnote-number + p { display: inline; }
a.footnote { text-decoration: none; font-size: 0.8em; }
a.footnote-ref { text-decoration: none; }
</xsl:text>
</xsl:template>


<!-- == Matched Templates == -->

<!-- = footnote = -->
<xsl:template match="footnote">
  <xsl:call-template name="db2html.footnote.ref"/>
</xsl:template>

</xsl:stylesheet>