footnote.xsl coverage = 48/198 (24.24%)

  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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?xml version='1.0'?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    exclude-result-prefixes="exsl" version='1.0'>

<!--############################################################################
    XSLT Stylesheet DocBook -> LaTeX
    ############################################################################ -->
<xsl:param name="footnote.as.endnote" select="0"/>
<xsl:param name="endnotes.heading.style" select="'select:title'"/>
<xsl:param name="endnotes.heading.groups"/>
<xsl:param name="endnotes.heading.command"/>
<xsl:param name="endnotes.counter.resetby" select="'part chapter'"/>

<xsl:attribute-set name="endnotes.properties.default">
  <xsl:attribute name="package">endnotes</xsl:attribute>

  <!-- No header: endnotes are embedded in another section -->
  <xsl:attribute name="heading">\mbox{}\par</xsl:attribute>

  <!-- Show end notes as a numbered list -->
  <xsl:attribute name="font-size">\normalsize</xsl:attribute>
  <xsl:attribute name="note-format">%
  \leftskip=1.8em\noindent
  \makebox[0pt][r]{\theenmark.~~\rule{0pt}{\baselineskip}}\ignorespaces
  </xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="endnotes.properties"
                   use-attribute-sets="endnotes.properties.default"/>

<!-- ==================================================================== -->

<xsl:template match="footnote">
  <xsl:choose>
  <!-- in forbidden areas, only put the footnotemark. footnotetext will
       follow in the next possible area (foottext mode) -->
  <xsl:when test="ancestor::term|
                  ancestor::title">
    <xsl:text>\footnotemark{}</xsl:text>
  </xsl:when>
  <xsl:otherwise>
    <xsl:text>\footnote{</xsl:text>
    <xsl:call-template name="label.id">
      <xsl:with-param name="inline" select="1"/>
    </xsl:call-template>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- Table cells are forbidden for footnotes -->
<xsl:template match="footnote[ancestor::entry]">
  <xsl:text>\footnotemark{}</xsl:text>
</xsl:template>

<xsl:template match="footnoteref">
  <!-- Works only with footmisc -->
  <xsl:text>\footref{</xsl:text>
  <xsl:value-of select="@linkend"/>
  <xsl:text>}</xsl:text>
</xsl:template>

<!-- display the text of the footnotes contained in this element -->
<xsl:template match="*" mode="foottext">
  <xsl:variable name="foot" select="descendant::footnote"/>
  <xsl:if test="count($foot)&gt;0">
    <xsl:text>\addtocounter{footnote}{-</xsl:text>
    <xsl:value-of select="count($foot)"/>
    <xsl:text>}</xsl:text>
    <xsl:apply-templates select="$foot" mode="foottext"/>
  </xsl:if>
</xsl:template>

<xsl:template match="footnote" mode="foottext">
  <xsl:text>\stepcounter{footnote}&#10;</xsl:text>
  <xsl:text>\footnotetext{</xsl:text>
  <xsl:apply-templates/>
  <xsl:call-template name="label.id"/>
  <xsl:text>}</xsl:text>
</xsl:template>

<!-- in a programlisting do as normal but in tex-escaped pattern -->
<xsl:template match="footnote" mode="latex.programlisting">
  <xsl:param name="co-tagin" select="'&lt;:'"/>
  <xsl:param name="probe" select="0"/>

  <xsl:call-template name="verbatim.embed">
    <xsl:with-param name="co-taging" select="$co-tagin"/>
    <xsl:with-param name="probe" select="$probe"/>
  </xsl:call-template>
</xsl:template>


<xsl:template match="*" mode="toc.skip">
  <xsl:apply-templates mode="toc.skip"/>
</xsl:template>

<!-- escape characters as usual -->
<xsl:template match="text()" mode="toc.skip">
  <xsl:apply-templates select="."/>
</xsl:template>

<!-- in this mode the footnotes must vanish -->
<xsl:template match="footnote" mode="toc.skip"/>

<!-- ==================================================================== -->

<xsl:template name="footnote.setup">
  <xsl:if test="$footnote.as.endnote=1">
    <xsl:text>\makeatletter&#10;</xsl:text>
    <xsl:call-template name="endnotes.setup"/>
    <xsl:text>\let\footnote=\endnote&#10;</xsl:text>
    <xsl:text>\let\footnotetext=\endnotetext&#10;</xsl:text>
    <xsl:text>\let\footnotemark=\endnotemark&#10;</xsl:text>
    <xsl:text>\let\c@footnote=\c@endnote&#10;</xsl:text>
    <xsl:text>\makeatother&#10;</xsl:text>
    <!-- Endnotes now uses the footnote counter: prevent from chapter reset -->
    <xsl:if test="(not(contains($endnotes.heading.groups,'chapter'))
                   or not(contains($endnotes.counter.resetby, 'chapter')))
                   and count(//chapter)!=0 ">
      <xsl:text>\usepackage{chngcntr}&#10;</xsl:text>
      <xsl:text>\counterwithout{footnote}{chapter}&#10;</xsl:text>
    </xsl:if>
  </xsl:if>
</xsl:template>

<!-- Default setup, to remove if already defined in a latex style, or to
     override if another formatting or package is required -->

<xsl:template name="endnotes.setup">
  <xsl:variable name="endnotesetup">
    <endnotesetup xsl:use-attribute-sets="endnotes.properties"/>
  </xsl:variable>
    
  <xsl:apply-templates select="exsl:node-set($endnotesetup)/*"/>
</xsl:template>

<xsl:template match="endnotesetup">
  <xsl:variable name="package">
    <xsl:choose>
    <xsl:when test="@package"><xsl:value-of select="@package"/></xsl:when>
    <xsl:otherwise>endnotes</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:text>\usepackage{</xsl:text>
  <xsl:value-of select="$package"/>
  <xsl:text>}&#10;</xsl:text>

  <xsl:if test="@heading">
    <xsl:text>\def\enoteheading{</xsl:text>
    <xsl:value-of select="@heading"/>
    <xsl:text>}&#10;</xsl:text>
  </xsl:if>

  <xsl:if test="@font-size">
    <xsl:text>\def\enotesize{</xsl:text>
    <xsl:value-of select="@font-size"/>
    <xsl:text>}&#10;</xsl:text>
  </xsl:if>

  <xsl:if test="@note-format">
    <xsl:text>\def\enoteformat{</xsl:text>
    <xsl:value-of select="@note-format"/>
    <xsl:text>}&#10;</xsl:text>
  </xsl:if>
</xsl:template>

<!-- ==================================================================== -->

<!-- Just append the endnotes to the other content -->
<xsl:template match="index" mode="endnotes">
  <xsl:apply-templates select="*"/>
  <xsl:if test="$footnote.as.endnote=1">
    <xsl:text>\theendnotes&#10;</xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template match="*" mode="endnotes"/>

<!-- By default only these elements are known to be endnotes groups -->
<xsl:template match="chapter|part" mode="endnotes">
  <xsl:call-template name="endnotes.add.header"/>
</xsl:template>

<xsl:template name="endnotes.add.header">
  <xsl:param name="verbose" select="1"/>
  <xsl:param name="reset-counter">
    <xsl:choose>
    <xsl:when test="contains($endnotes.counter.resetby,local-name(.))">
      <xsl:value-of select="1"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="0"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:param>

  <xsl:variable name="endnotes.section"
                select="//index[@type='endnotes'][1]/parent::*"/>

  <xsl:if test="$verbose=2">
    <xsl:message>Endnotes sections found: <xsl:value-of
               select="count($endnotes.section)"/></xsl:message>
  </xsl:if>

  <xsl:if test="$footnote.as.endnote=1 and 
                contains($endnotes.heading.groups, local-name(.)) and
                count($endnotes.section)!=0 and count(descendant::footnote)!=0">

    <xsl:variable name="level">
      <xsl:call-template name="get.sect.level">
        <xsl:with-param name="n" select="$endnotes.section"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:if test="$verbose=2">
      <xsl:message>
         <xsl:text>Endnotes headings level: </xsl:text>
         <xsl:value-of select="$level+1"/></xsl:message>
    </xsl:if>

    <!-- Use xref templates to format the title with xrefstyle features -->
    <xsl:variable name="title">
      <xsl:call-template name="xref.nolink">
        <xsl:with-param name="string">
          <xsl:apply-templates select="." mode="object.xref.markup">
            <xsl:with-param name="purpose" select="'xref'"/>
            <xsl:with-param name="xrefstyle" select="$endnotes.heading.style"/>
            <xsl:with-param name="referrer" select="."/>
            <xsl:with-param name="verbose" select="$verbose"/>
          </xsl:apply-templates>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:variable>

    <!-- Use a defined heading command, or compute one from section level -->
    <xsl:variable name="heading">
      <xsl:choose>
      <xsl:when test="$endnotes.heading.command!=''">
        <xsl:value-of
                select="concat($endnotes.heading.command, '{', $title, '}')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="maketitle">
          <xsl:with-param name="level" select="$level+1"/>
          <xsl:with-param name="allnum" select="'0'"/>
          <xsl:with-param name="num" select="'0'"/>
          <xsl:with-param name="title" select="$title"/>
          <xsl:with-param name="with-label" select="0"/>
        </xsl:call-template>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:if test="$reset-counter!=0">
      <xsl:text>\setcounter{endnote}{0}</xsl:text>
    </xsl:if>
    <xsl:text>\addtoendnotes{\protect</xsl:text>
    <xsl:value-of select="$heading"/>
    <xsl:text>}&#10;</xsl:text>

  </xsl:if>
</xsl:template>

</xsl:stylesheet>