Debian Codegraph @

xsl/biblio.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
4 <!--############################################################################
5 XSLT Stylesheet DocBook -> LaTeX
6 ############################################################################ -->
7 <xsl:param name="bibliography.tocdepth">5</xsl:param>
8 <xsl:param name="bibliography.numbered">1</xsl:param>
9 <xsl:param name="biblioentry.numbered" select="0"/>
10
11 <!-- ################
12 # biblio setup #
13 ################ -->
14
15 <xsl:template name="biblio.setup">
16 <xsl:if test="$latex.biblio.style!='' and //bibliography">
17 <xsl:text>\bibliographystyle{</xsl:text>
18 <xsl:value-of select="$latex.biblio.style"/>
19 <xsl:text>}&#10;</xsl:text>
20 </xsl:if>
21 </xsl:template>
22
23
24 <!-- ##################
25 # biblio section #
26 ################## -->
27
28 <xsl:template name="biblio.insert.title">
29 <xsl:param name="level" select="0"/>
30
31 <xsl:variable name="title.node" select="(title|bibliographyinfo/title)[1]"/>
32 <xsl:variable name="title.text">
33 <xsl:choose>
34 <xsl:when test="ancestor::article">
35 <xsl:text>\refname</xsl:text>
36 </xsl:when>
37 <xsl:otherwise>
38 <xsl:text>\bibname</xsl:text>
39 </xsl:otherwise>
40 </xsl:choose>
41 </xsl:variable>
42
43 <xsl:choose>
44 <xsl:when test="self::bibliography and number($bibliography.numbered) = 0">
45 <!-- The unumbered section is only for the top level bibliography heading -->
46 <xsl:call-template name="section.unnumbered.begin">
47 <xsl:with-param name="tocdepth" select="number($bibliography.tocdepth)"/>
48 <xsl:with-param name="level" select="$level"/>
49 <xsl:with-param name="title" select="$title.text"/>
50 <xsl:with-param name="titlenode" select="$title.node"/>
51 </xsl:call-template>
52 </xsl:when>
53 <xsl:when test="$title.node">
54 <!-- Numbered section from a <title> node -->
55 <xsl:call-template name="makeheading">
56 <xsl:with-param name="level" select="$level"/>
57 <xsl:with-param name="allnum" select="'1'"/>
58 <xsl:with-param name="title" select="$title.node"/>
59 </xsl:call-template>
60 </xsl:when>
61 <xsl:otherwise>
62 <!-- Numbered section from a generated title -->
63 <xsl:call-template name="maketitle">
64 <xsl:with-param name="level" select="$level"/>
65 <xsl:with-param name="allnum" select="'1'"/>
66 <xsl:with-param name="title" select="$title.text"/>
67 </xsl:call-template>
68 </xsl:otherwise>
69 </xsl:choose>
70 </xsl:template>
71
72 <xsl:template name="biblio.section.end">
73 <xsl:if test="self::bibliography and number($bibliography.numbered) = 0">
74 <!-- Only the unumbered section requires to restore section counters -->
75 <xsl:call-template name="section.unnumbered.end">
76 <xsl:with-param name="tocdepth" select="number($bibliography.tocdepth)"/>
77 </xsl:call-template>
78 </xsl:if>
79 </xsl:template>
80
81 <!-- we can have a list of entries to process, or a bibtex file -->
82 <xsl:template name="biblioentry.process">
83 <xsl:param name="level"/>
84 <xsl:choose>
85 <xsl:when test="count(bibioentry|bibliomixed)=1 and
86 bibliomixed[processing-instruction('bibtex')]">
87 <xsl:call-template name="bibtex.process">
88 <xsl:with-param name="level" select="$level"/>
89 </xsl:call-template>
90 </xsl:when>
91 <xsl:otherwise>
92 <xsl:call-template name="bibentries.process">
93 <xsl:with-param name="level" select="$level"/>
94 </xsl:call-template>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:template>
98
99 <xsl:template name="bibentries.process">
100 <xsl:param name="level"/>
101
102 <xsl:text>\begin{btSect}{}&#10;</xsl:text>
103
104 <!-- display the heading -->
105 <xsl:if test="$level &gt;= 0">
106 <xsl:call-template name="biblio.insert.title">
107 <xsl:with-param name="level" select="$level"/>
108 </xsl:call-template>
109 </xsl:if>
110
111 <xsl:text>\begin{bibgroup}&#10;</xsl:text>
112 <xsl:text>\begin{thebibliography}{</xsl:text>
113 <xsl:value-of select="$latex.bibwidelabel"/>
114 <xsl:text>}&#10;</xsl:text>
115 <xsl:if test="biblioentry">
116 <xsl:choose>
117 <xsl:when test="$latex.biblio.output ='cited'">
118 <xsl:apply-templates select="biblioentry" mode="bibliography.cited">
119 <xsl:sort select="./abbrev"/>
120 <xsl:sort select="./@xreflabel"/>
121 <xsl:sort select="./@id"/>
122 </xsl:apply-templates>
123 </xsl:when>
124 <xsl:otherwise>
125 <xsl:apply-templates select="biblioentry">
126 <xsl:sort select="./abbrev"/>
127 <xsl:sort select="./@xreflabel"/>
128 <xsl:sort select="./@id"/>
129 </xsl:apply-templates>
130 </xsl:otherwise>
131 </xsl:choose>
132 </xsl:if>
133 <xsl:if test="bibliomixed">
134 <xsl:apply-templates select="bibliomixed"/>
135 </xsl:if>
136 <xsl:text>&#10;\end{thebibliography}&#10;</xsl:text>
137 <xsl:text>\end{bibgroup}&#10;</xsl:text>
138 <xsl:if test="$level &gt;= 0">
139 <xsl:call-template name="biblio.section.end"/>
140 </xsl:if>
141 <xsl:text>\end{btSect}&#10;</xsl:text>
142 </xsl:template>
143
144
145 <!-- ################
146 # bibtex files #
147 ################ -->
148
149 <xsl:template name="bibtex.process">
150 <xsl:param name="level"/>
151
152 <!-- take all the details from the bibtex PI -->
153 <xsl:variable name="bibfiles">
154 <xsl:call-template name="pi.bibtex_bibfiles">
155 <xsl:with-param name="node" select="bibliomixed"/>
156 </xsl:call-template>
157 </xsl:variable>
158 <xsl:variable name="bibstyle">
159 <xsl:call-template name="pi.bibtex_bibstyle">
160 <xsl:with-param name="node" select="bibliomixed"/>
161 </xsl:call-template>
162 </xsl:variable>
163 <xsl:variable name="print">
164 <xsl:call-template name="pi.bibtex_mode">
165 <xsl:with-param name="node" select="bibliomixed"/>
166 </xsl:call-template>
167 </xsl:variable>
168
169 <xsl:text>\begin{btSect}</xsl:text>
170
171 <!-- specific style to apply? -->
172 <xsl:if test="$bibstyle!=''">
173 <xsl:text>[</xsl:text>
174 <xsl:value-of select="$bibstyle"/>
175 <xsl:text>]</xsl:text>
176 </xsl:if>
177
178 <!-- the bibtex files to use (fallback to global parameter) -->
179 <xsl:text>{</xsl:text>
180 <xsl:choose>
181 <xsl:when test="$bibfiles!=''">
182 <xsl:value-of select="$bibfiles"/>
183 </xsl:when>
184 <xsl:otherwise>
185 <xsl:value-of select="$latex.bibfiles"/>
186 </xsl:otherwise>
187 </xsl:choose>
188 <xsl:text>}&#10;</xsl:text>
189
190 <!-- display the heading -->
191 <xsl:if test="$level &gt;= 0">
192 <xsl:call-template name="biblio.insert.title">
193 <xsl:with-param name="level" select="$level"/>
194 </xsl:call-template>
195 </xsl:if>
196
197 <!-- things before the entries -->
198 <xsl:apply-templates select="*[not(self::bibliomixed)]"/>
199
200 <!-- the entries to show depend on the print mode -->
201 <xsl:choose>
202 <xsl:when test="$print='cited'">
203 <xsl:text>\btPrintCited&#10;</xsl:text>
204 </xsl:when>
205 <xsl:when test="$print='notcited'">
206 <xsl:text>\btPrintNotCited&#10;</xsl:text>
207 </xsl:when>
208 <xsl:when test="$print='all'">
209 <xsl:text>\btPrintAll&#10;</xsl:text>
210 </xsl:when>
211 <xsl:when test="$latex.biblio.output='cited'">
212 <xsl:text>\btPrintCited&#10;</xsl:text>
213 </xsl:when>
214 <xsl:when test="$latex.biblio.output='notcited'">
215 <xsl:text>\btPrintNotCited&#10;</xsl:text>
216 </xsl:when>
217 <xsl:otherwise>
218 <xsl:text>\btPrintAll&#10;</xsl:text>
219 </xsl:otherwise>
220 </xsl:choose>
221
222 <xsl:if test="$level &gt;= 0">
223 <xsl:call-template name="biblio.section.end"/>
224 </xsl:if>
225
226 <xsl:text>\end{btSect}&#10;</xsl:text>
227 </xsl:template>
228
229
230 <!-- ################
231 # bibliography #
232 ################ -->
233
234 <xsl:template match="bibliography">
235 <!--
236 <xsl:message>Processing Bibliography</xsl:message>
237 <xsl:message><xsl:text>Output Mode: </xsl:text>
238 <xsl:value-of select="$latex.biblio.output"/>
239 </xsl:message>
240 -->
241 <xsl:text>% ------------------------------------------- &#10;</xsl:text>
242 <xsl:text>% Bibliography&#10;</xsl:text>
243 <xsl:text>% ------------------------------------------- &#10;</xsl:text>
244
245 <!-- get the section level -->
246 <xsl:variable name="level">
247 <xsl:call-template name="get.sect.level"/>
248 </xsl:variable>
249
250 <xsl:choose>
251 <xsl:when test="biblioentry|bibliomixed">
252 <!-- process the entries -->
253 <xsl:call-template name="biblioentry.process">
254 <xsl:with-param name="level" select="$level"/>
255 </xsl:call-template>
256 </xsl:when>
257 <xsl:otherwise>
258 <!-- no entries here, only a section block -->
259 <xsl:call-template name="biblio.insert.title">
260 <xsl:with-param name="level" select="$level"/>
261 </xsl:call-template>
262 </xsl:otherwise>
263 </xsl:choose>
264 <xsl:apply-templates select="bibliodiv"/>
265
266 <!-- close the opened section block -->
267 <xsl:if test="not(biblioentry|bibliomixed)">
268 <xsl:call-template name="biblio.section.end"/>
269 </xsl:if>
270 </xsl:template>
271
272 <xsl:template match="bibliography/title"/>
273 <xsl:template match="bibliography/subtitle"/>
274 <xsl:template match="bibliography/titleabbrev"/>
275
276 <!-- ###############
277 # bibliodiv #
278 ############### -->
279
280 <xsl:template match="bibliodiv">
281 <xsl:variable name="level">
282 <xsl:call-template name="get.sect.level">
283 <xsl:with-param name="n" select="parent::bibliography"/>
284 </xsl:call-template>
285 </xsl:variable>
286 <xsl:call-template name="biblioentry.process">
287 <xsl:with-param name="level" select="$level+1"/>
288 </xsl:call-template>
289 </xsl:template>
290
291 <xsl:template match="bibliodiv/title"/>
292
293 <!-- ###############
294 # bibliolist #
295 ############### -->
296
297 <xsl:template match="bibliolist">
298 <xsl:call-template name="biblioentry.process">
299 <xsl:with-param name="level" select="'-1'"/>
300 </xsl:call-template>
301 </xsl:template>
302
303 <xsl:template match="bibliodiv/title"/>
304
305 <!-- ###############
306 # biblioentry #
307 ############### -->
308
309 <xsl:template match="biblioentry" mode="bibliography.cited">
310 <xsl:param name="bibid" select="@id"/>
311 <xsl:param name="ab">
312 <xsl:call-template name="bibitem.label"/>
313 </xsl:param>
314 <xsl:variable name="nx" select="//xref[@linkend=$bibid]"/>
315 <xsl:variable name="nc" select="//citation[text()=$ab]"/>
316 <xsl:if test="count($nx) &gt; 0 or count($nc) &gt; 0">
317 <xsl:call-template name="biblioentry.output"/>
318 </xsl:if>
319 </xsl:template>
320
321 <xsl:template match="biblioentry" mode="bibliography.all">
322 <xsl:call-template name="biblioentry.output"/>
323 </xsl:template>
324
325 <xsl:template match="biblioentry">
326 <xsl:call-template name="biblioentry.output"/>
327 </xsl:template>
328
329 <xsl:template match="biblioentry/title">
330 <xsl:text>\emph{</xsl:text>
331 <xsl:apply-templates/>
332 <xsl:text>}</xsl:text>
333 </xsl:template>
334
335 <!-- biblioentry engine -->
336
337 <xsl:template name="bibitem.label">
338 <xsl:choose>
339 <xsl:when test="@xreflabel">
340 <xsl:value-of select="normalize-space(@xreflabel)"/>
341 </xsl:when>
342 <xsl:when test="abbrev">
343 <xsl:apply-templates select="abbrev" mode="biblio.label.mode"/>
344 </xsl:when>
345 <xsl:when test="@id">
346 <xsl:value-of select="normalize-space(@id)"/>
347 </xsl:when>
348 </xsl:choose>
349 </xsl:template>
350
351 <!-- The biblio entry ID must follow the label, to match citation text -->
352 <xsl:template name="bibitem.id">
353 <xsl:choose>
354 <xsl:when test="@xreflabel">
355 <xsl:value-of select="normalize-space(@xreflabel)"/>
356 </xsl:when>
357 <xsl:when test="abbrev">
358 <xsl:apply-templates select="abbrev" mode="biblio.label.mode"/>
359 </xsl:when>
360 <xsl:when test="@id">
361 <xsl:value-of select="normalize-space(@id)"/>
362 </xsl:when>
363 <xsl:otherwise>
364 <xsl:value-of select="generate-id()"/>
365 </xsl:otherwise>
366 </xsl:choose>
367 </xsl:template>
368
369 <xsl:template match="abbrev" mode="biblio.label.mode">
370 <xsl:value-of select="."/>
371 </xsl:template>
372
373
374 <xsl:template name="bibitem">
375 <xsl:variable name="tag">
376 <xsl:call-template name="bibitem.label"/>
377 </xsl:variable>
378 <xsl:text>&#10;</xsl:text>
379 <xsl:text>\bibitem</xsl:text>
380 <xsl:if test="$tag != '' and $biblioentry.numbered = 0">
381 <xsl:text>[</xsl:text>
382 <xsl:call-template name="normalize-scape">
383 <xsl:with-param name="string" select="$tag"/>
384 </xsl:call-template>
385 <xsl:text>]</xsl:text>
386 </xsl:if>
387 <xsl:text>{</xsl:text>
388 <xsl:call-template name="bibitem.id"/>
389 <xsl:text>}</xsl:text>
390 <!-- Add labels, in case of xrefs to here -->
391 <xsl:call-template name="label.id">
392 <xsl:with-param name="inline" select="1"/>
393 </xsl:call-template>
394 <xsl:text>&#10;</xsl:text>
395 </xsl:template>
396
397 <xsl:template name="biblioentry.output">
398 <xsl:call-template name="bibitem"/>
399 <!-- first, biblioentry information (if any) -->
400 <xsl:variable name="data" select="subtitle|
401 volumenum|
402 edition|
403 address|
404 copyright|
405 publisher|
406 date|
407 pubdate|
408 pagenums|
409 isbn|
410 issn|
411 biblioid|
412 releaseinfo|
413 pubsnumber"/>
414 <xsl:apply-templates select="author|authorgroup" mode="bibliography.mode"/>
415 <xsl:if test="title">
416 <xsl:if test="author|authorgroup">
417 <xsl:value-of select="$biblioentry.item.separator"/>
418 </xsl:if>
419 <xsl:apply-templates select="title"/>
420 </xsl:if>
421 <xsl:if test="$data">
422 <xsl:for-each select="$data">
423 <xsl:value-of select="$biblioentry.item.separator"/>
424 <xsl:apply-templates select="." mode="bibliography.mode"/>
425 </xsl:for-each>
426 <xsl:text>.</xsl:text>
427 </xsl:if>
428 <!-- then, biblioset information (if any) -->
429 <xsl:for-each select="biblioset">
430 <xsl:text>&#10;&#10;</xsl:text>
431 <xsl:apply-templates select="." mode="bibliography.mode"/>
432 </xsl:for-each>
433 <xsl:text>&#10;</xsl:text>
434 </xsl:template>
435
436 <xsl:template match="bibliomixed">
437 <xsl:call-template name="bibitem"/>
438 <xsl:apply-templates select="." mode="bibliography.mode"/>
439 <xsl:text>&#10;</xsl:text>
440 </xsl:template>
441
442 <!-- Text in bibliomixed/bibliomset must be processed as normal (scaped) -->
443 <xsl:template match="text()" mode="bibliography.mode">
444 <xsl:apply-templates select="."/>
445 </xsl:template>
446
447 <!-- by default no specific behaviour -->
448 <xsl:template match="*" mode="bibliography.mode">
449 <xsl:apply-templates mode="bibliography.mode"/>
450 </xsl:template>
451
452 <!-- want hot links -->
453 <xsl:template match="ulink" mode="bibliography.mode">
454 <xsl:apply-templates select="."/>
455 </xsl:template>
456
457 <!-- abbrev not displayed -->
458 <xsl:template match="abbrev" mode="bibliography.mode"/>
459
460 <!-- want latex label anchors -->
461 <xsl:template match="anchor" mode="bibliography.mode">
462 <xsl:apply-templates select="."/>
463 </xsl:template>
464
465
466 <xsl:template match="biblioset" mode="bibliography.mode">
467 <xsl:if test="author|authorgroup">
468 <xsl:apply-templates select="author|authorgroup" mode="bibliography.mode"/>
469 <xsl:value-of select="$biblioentry.item.separator"/>
470 </xsl:if>
471 <xsl:apply-templates select="title|citetitle" mode="bibliography.mode"/>
472 <xsl:for-each select="subtitle|
473 volumenum|
474 edition|
475 address|
476 copyright|
477 publisher|
478 date|
479 pubdate|
480 pagenums|
481 isbn|
482 issn|
483 biblioid|
484 pubsnumber">
485 <xsl:value-of select="$biblioentry.item.separator"/>
486 <xsl:apply-templates select="." mode="bibliography.mode"/>
487 </xsl:for-each>
488 <xsl:text>.</xsl:text>
489 </xsl:template>
490
491 <xsl:template match="biblioset/title|biblioset/citetitle"
492 mode="bibliography.mode">
493 <xsl:variable name="relation" select="../@relation"/>
494 <xsl:choose>
495 <xsl:when test="$relation='article' or @pubwork='article'">
496 <xsl:call-template name="gentext.startquote"/>
497 <xsl:apply-templates/>
498 <xsl:call-template name="gentext.endquote"/>
499 </xsl:when>
500 <xsl:otherwise>
501 <xsl:apply-templates/>
502 </xsl:otherwise>
503 </xsl:choose>
504 </xsl:template>
505
506 <!-- Biblioid depends on its class -->
507 <xsl:template match="biblioid" mode="bibliography.mode">
508 <xsl:choose>
509 <xsl:when test="@class='doi'">
510 <xsl:text>DOI</xsl:text>
511 </xsl:when>
512 <xsl:when test="@class='isbn'">
513 <xsl:text>ISBN</xsl:text>
514 </xsl:when>
515 <xsl:when test="@class='issn'">
516 <xsl:text>ISSN</xsl:text>
517 </xsl:when>
518 <xsl:otherwise>
519 <xsl:message>
520 <xsl:text>The biblioid class '</xsl:text>
521 <xsl:value-of select="@class"/>
522 <xsl:text>' not supported!</xsl:text>
523 </xsl:message>
524 <xsl:value-of select="@class"/>
525 </xsl:otherwise>
526 </xsl:choose>
527 <xsl:text> </xsl:text>
528 <xsl:apply-templates/>
529 </xsl:template>
530
531 <xsl:template match="author" mode="bibliography.mode">
532 <xsl:variable name="authorsstring">
533 <xsl:call-template name="person.name"/>
534 </xsl:variable>
535 <xsl:value-of select="normalize-space($authorsstring)"/>
536 </xsl:template>
537
538 <xsl:template match="authorgroup" mode="bibliography.mode">
539 <xsl:variable name="authorsstring">
540 <xsl:call-template name="person.name.list"/>
541 </xsl:variable>
542 <xsl:value-of select="normalize-space($authorsstring)"/>
543 </xsl:template>
544
545 <xsl:template match="editor" mode="bibliography.mode">
546 <xsl:call-template name="person.name"/>
547 <xsl:value-of select="$biblioentry.item.separator"/>
548 </xsl:template>
549
550 <xsl:template match="copyright" mode="bibliography.mode">
551 <xsl:call-template name="gentext.element.name"/>
552 <xsl:call-template name="gentext.space"/>
553 <xsl:call-template name="dingbat">
554 <xsl:with-param name="dingbat">copyright</xsl:with-param>
555 </xsl:call-template>
556 <xsl:call-template name="gentext.space"/>
557 <xsl:apply-templates select="year" mode="bibliography.mode"/>
558 <xsl:if test="holder">
559 <xsl:call-template name="gentext.space"/>
560 <xsl:apply-templates select="holder" mode="bibliography.mode"/>
561 </xsl:if>
562 </xsl:template>
563
564 <xsl:template match="year" mode="bibliography.mode">
565 <xsl:apply-templates/>
566 <xsl:if test="position()!=last()">
567 <xsl:text>, </xsl:text>
568 </xsl:if>
569 </xsl:template>
570
571 <xsl:template match="publisher" mode="bibliography.mode">
572 <xsl:apply-templates select="publishername" mode="bibliography.mode"/>
573 <xsl:for-each select="address">
574 <xsl:value-of select="$biblioentry.item.separator"/>
575 <xsl:apply-templates select="." mode="bibliography.mode"/>
576 </xsl:for-each>
577 </xsl:template>
578
579
580 <!-- to manage entities correctly (such as &amp;) -->
581 <xsl:template match="subtitle|volumenum|edition|
582 date|pubdate|pagenums|isbn|issn|
583 holder|publishername|releaseinfo|address"
584 mode="bibliography.mode">
585 <xsl:apply-templates/>
586 </xsl:template>
587
588 <!-- suppressed things -->
589 <xsl:template match="printhistory" mode="bibliography.mode"/>
590 <xsl:template match="abstract" mode="bibliography.mode"/>
591 <xsl:template match="authorblurb" mode="bibliography.mode"/>
592
593
594 </xsl:stylesheet>