1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
5                version='1.0'>
6
7<!-- ********************************************************************
8     $Id: refentry.xsl,v 1.31 2006/04/25 03:12:09 xmldoc Exp $
9     ********************************************************************
10
11     This file is part of the XSL DocBook Stylesheet distribution.
12     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13     and other information.
14
15     ******************************************************************** -->
16
17<!-- ==================================================================== -->
18
19<xsl:template match="reference">
20   <xsl:if test="not(partintro)">
21    <xsl:variable name="id">
22      <xsl:call-template name="object.id"/>
23    </xsl:variable>
24    <xsl:variable name="master-reference">
25      <xsl:call-template name="select.pagemaster"/>
26    </xsl:variable>
27
28    <fo:page-sequence hyphenate="{$hyphenate}"
29                      master-reference="{$master-reference}">
30      <xsl:attribute name="language">
31        <xsl:call-template name="l10n.language"/>
32      </xsl:attribute>
33      <xsl:attribute name="format">
34        <xsl:call-template name="page.number.format">
35          <xsl:with-param name="master-reference" select="$master-reference"/>
36        </xsl:call-template>
37      </xsl:attribute>
38
39      <xsl:attribute name="initial-page-number">
40        <xsl:call-template name="initial.page.number">
41          <xsl:with-param name="master-reference" select="$master-reference"/>
42        </xsl:call-template>
43      </xsl:attribute>
44
45      <xsl:attribute name="force-page-count">
46        <xsl:call-template name="force.page.count">
47          <xsl:with-param name="master-reference" select="$master-reference"/>
48        </xsl:call-template>
49      </xsl:attribute>
50
51      <xsl:attribute name="hyphenation-character">
52        <xsl:call-template name="gentext">
53          <xsl:with-param name="key" select="'hyphenation-character'"/>
54        </xsl:call-template>
55      </xsl:attribute>
56      <xsl:attribute name="hyphenation-push-character-count">
57        <xsl:call-template name="gentext">
58          <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
59        </xsl:call-template>
60      </xsl:attribute>
61      <xsl:attribute name="hyphenation-remain-character-count">
62        <xsl:call-template name="gentext">
63          <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
64        </xsl:call-template>
65      </xsl:attribute>
66
67      <xsl:apply-templates select="." mode="running.head.mode">
68        <xsl:with-param name="master-reference" select="$master-reference"/>
69      </xsl:apply-templates>
70      <xsl:apply-templates select="." mode="running.foot.mode">
71        <xsl:with-param name="master-reference" select="$master-reference"/>
72      </xsl:apply-templates>
73
74      <fo:flow flow-name="xsl-region-body">
75        <xsl:call-template name="set.flow.properties">
76          <xsl:with-param name="element" select="local-name(.)"/>
77          <xsl:with-param name="master-reference" select="$master-reference"/>
78        </xsl:call-template>
79
80        <fo:block id="{$id}">
81          <xsl:call-template name="reference.titlepage"/>
82        </fo:block>
83        <!-- Create one page sequence if no pagebreaks needed -->
84        <xsl:if test="$refentry.pagebreak = 0">
85          <xsl:apply-templates select="refentry"/>
86        </xsl:if>
87      </fo:flow>
88    </fo:page-sequence>
89  </xsl:if>
90  <xsl:apply-templates select="partintro"/>
91  <xsl:if test="$refentry.pagebreak != 0">
92    <xsl:apply-templates select="refentry"/>
93  </xsl:if>
94</xsl:template>
95
96<xsl:template match="reference" mode="reference.titlepage.mode">
97  <xsl:call-template name="reference.titlepage"/>
98</xsl:template>
99
100<xsl:template match="reference/partintro">
101  <xsl:variable name="id">
102    <xsl:call-template name="object.id">
103      <xsl:with-param name="object" select="ancestor::reference"/>
104    </xsl:call-template>
105  </xsl:variable>
106  <xsl:variable name="master-reference">
107    <xsl:call-template name="select.pagemaster"/>
108  </xsl:variable>
109
110  <fo:page-sequence hyphenate="{$hyphenate}"
111                    master-reference="{$master-reference}">
112    <xsl:attribute name="language">
113      <xsl:call-template name="l10n.language"/>
114    </xsl:attribute>
115    <xsl:attribute name="format">
116      <xsl:call-template name="page.number.format">
117        <xsl:with-param name="master-reference" select="$master-reference"/>
118      </xsl:call-template>
119    </xsl:attribute>
120
121    <xsl:attribute name="initial-page-number">
122      <xsl:call-template name="initial.page.number">
123        <xsl:with-param name="master-reference" select="$master-reference"/>
124      </xsl:call-template>
125    </xsl:attribute>
126
127    <xsl:attribute name="force-page-count">
128      <xsl:call-template name="force.page.count">
129        <xsl:with-param name="master-reference" select="$master-reference"/>
130      </xsl:call-template>
131    </xsl:attribute>
132
133    <xsl:attribute name="hyphenation-character">
134      <xsl:call-template name="gentext">
135        <xsl:with-param name="key" select="'hyphenation-character'"/>
136      </xsl:call-template>
137    </xsl:attribute>
138    <xsl:attribute name="hyphenation-push-character-count">
139      <xsl:call-template name="gentext">
140        <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
141      </xsl:call-template>
142    </xsl:attribute>
143    <xsl:attribute name="hyphenation-remain-character-count">
144      <xsl:call-template name="gentext">
145        <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
146      </xsl:call-template>
147    </xsl:attribute>
148
149    <xsl:apply-templates select="." mode="running.head.mode">
150      <xsl:with-param name="master-reference" select="$master-reference"/>
151    </xsl:apply-templates>
152    <xsl:apply-templates select="." mode="running.foot.mode">
153      <xsl:with-param name="master-reference" select="$master-reference"/>
154    </xsl:apply-templates>
155
156    <fo:flow flow-name="xsl-region-body">
157      <xsl:call-template name="set.flow.properties">
158        <xsl:with-param name="element" select="local-name(.)"/>
159        <xsl:with-param name="master-reference" select="$master-reference"/>
160      </xsl:call-template>
161      <fo:block id="{$id}">
162        <xsl:apply-templates select=".." mode="reference.titlepage.mode"/>
163      </fo:block>
164      <xsl:if test="title">
165        <xsl:call-template name="partintro.titlepage"/>
166      </xsl:if>
167      <xsl:apply-templates/>
168      <!-- Create one page sequence if no pagebreaks needed -->
169      <xsl:if test="$refentry.pagebreak = 0">
170        <xsl:apply-templates select="../refentry"/>
171      </xsl:if>
172    </fo:flow>
173  </fo:page-sequence>
174</xsl:template>
175
176<xsl:template match="reference/docinfo|refentry/refentryinfo"></xsl:template>
177<xsl:template match="reference/title"></xsl:template>
178<xsl:template match="reference/subtitle"></xsl:template>
179
180<!-- ==================================================================== -->
181
182<xsl:template match="refentry">
183  <xsl:variable name="id">
184    <xsl:call-template name="object.id"/>
185  </xsl:variable>
186
187  <xsl:variable name="master-reference">
188    <xsl:call-template name="select.pagemaster"/>
189  </xsl:variable>
190
191  <xsl:variable name="refentry.content">
192    <fo:block id="{$id}">
193      <xsl:apply-templates/>
194    </fo:block>
195  </xsl:variable>
196
197  <xsl:choose>
198    <xsl:when test="not(parent::*) or 
199                    (parent::reference and $refentry.pagebreak != 0) or 
200                    parent::part">
201      <!-- make a page sequence -->
202      <fo:page-sequence hyphenate="{$hyphenate}"
203                        master-reference="{$master-reference}">
204        <xsl:attribute name="language">
205          <xsl:call-template name="l10n.language"/>
206        </xsl:attribute>
207        <xsl:attribute name="format">
208          <xsl:call-template name="page.number.format">
209            <xsl:with-param name="master-reference" select="$master-reference"/>
210          </xsl:call-template>
211        </xsl:attribute>
212
213        <xsl:attribute name="initial-page-number">
214          <xsl:call-template name="initial.page.number">
215            <xsl:with-param name="master-reference" select="$master-reference"/>
216          </xsl:call-template>
217        </xsl:attribute>
218
219        <xsl:attribute name="force-page-count">
220          <xsl:call-template name="force.page.count">
221            <xsl:with-param name="master-reference" select="$master-reference"/>
222          </xsl:call-template>
223        </xsl:attribute>
224
225        <xsl:attribute name="hyphenation-character">
226          <xsl:call-template name="gentext">
227            <xsl:with-param name="key" select="'hyphenation-character'"/>
228          </xsl:call-template>
229        </xsl:attribute>
230        <xsl:attribute name="hyphenation-push-character-count">
231          <xsl:call-template name="gentext">
232            <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
233          </xsl:call-template>
234        </xsl:attribute>
235        <xsl:attribute name="hyphenation-remain-character-count">
236          <xsl:call-template name="gentext">
237            <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
238          </xsl:call-template>
239        </xsl:attribute>
240
241        <xsl:apply-templates select="." mode="running.head.mode">
242          <xsl:with-param name="master-reference" select="$master-reference"/>
243        </xsl:apply-templates>
244        <xsl:apply-templates select="." mode="running.foot.mode">
245          <xsl:with-param name="master-reference" select="$master-reference"/>
246        </xsl:apply-templates>
247
248        <fo:flow flow-name="xsl-region-body">
249          <xsl:call-template name="set.flow.properties">
250            <xsl:with-param name="element" select="local-name(.)"/>
251            <xsl:with-param name="master-reference" select="$master-reference"/>
252          </xsl:call-template>
253
254          <xsl:copy-of select="$refentry.content"/>
255        </fo:flow>
256      </fo:page-sequence>
257    </xsl:when>
258    <xsl:otherwise>
259      <fo:block>
260        <xsl:if test="$refentry.pagebreak != 0">
261          <xsl:attribute name="break-before">page</xsl:attribute>
262        </xsl:if>
263        <xsl:copy-of select="$refentry.content"/>
264      </fo:block>
265    </xsl:otherwise>
266  </xsl:choose>
267</xsl:template>
268
269<xsl:template match="refmeta">
270</xsl:template>
271
272<xsl:template match="manvolnum">
273  <xsl:if test="$refentry.xref.manvolnum != 0">
274    <xsl:text>(</xsl:text>
275    <xsl:apply-templates/>
276    <xsl:text>)</xsl:text>
277  </xsl:if>
278</xsl:template>
279
280<xsl:template match="refmiscinfo">
281</xsl:template>
282
283<xsl:template match="refentrytitle">
284  <xsl:call-template name="inline.charseq"/>
285</xsl:template>
286
287<xsl:template match="refnamediv">
288  <xsl:variable name="id">
289    <xsl:call-template name="object.id"/>
290  </xsl:variable>
291
292  <fo:block id="{$id}">
293
294    <!-- if refentry.generate.name is non-zero, then we need to generate a -->
295    <!-- localized "Name" subheading for this refnamdiv (unless it has a -->
296    <!-- preceding sibling that is a refnamediv, in which case we have already -->
297    <!-- generated a "Name" subheading, so we don't need to do it again -->
298    <xsl:if test="$refentry.generate.name != 0">
299        <xsl:choose>
300          <xsl:when test="preceding-sibling::refnamediv">
301            <!-- no generated title on secondary refnamedivs! -->
302          </xsl:when>
303          <xsl:otherwise>
304            <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
305                      xsl:use-attribute-sets="refnamediv.titlepage.recto.style"
306                      font-family="{$title.fontset}">
307              <!-- Contents of what is now the format.refentry.subheading -->
308              <!-- template were formerly intended to be used only to -->
309              <!-- process those subsections of Refentry that have "real" -->
310              <!-- title children. So as a kludge to get around the fact -->
311              <!-- that the template still basically "expects" to be -->
312              <!-- processing that kind of a node, when we call the -->
313              <!-- template to process generated titles, we must call it -->
314              <!-- with values for the "offset" and "section" parameters -->
315              <!-- that are different from the default values in the -->
316              <!-- format.refentry.subheading template itself. Because -->
317              <!-- those defaults are the values appropriate for processing -->
318              <!-- "real" title nodes. -->
319              <xsl:call-template name="format.refentry.subheading">
320                <xsl:with-param name="section" select="self::*"/>
321                <xsl:with-param name="offset" select="1"/>
322                <xsl:with-param name="gentext.key" select="'RefName'"/>
323              </xsl:call-template>
324            </fo:block>
325          </xsl:otherwise>
326        </xsl:choose>
327      </xsl:if>
328
329      <xsl:if test="$refentry.generate.title != 0">
330  <xsl:variable name="section.level">
331    <xsl:call-template name="refentry.level">
332      <xsl:with-param name="node" select="ancestor::refentry"/>
333    </xsl:call-template>
334  </xsl:variable>
335
336  <xsl:variable name="reftitle">
337        <xsl:choose>
338          <xsl:when test="../refmeta/refentrytitle">
339            <xsl:apply-templates select="../refmeta/refentrytitle"/>
340          </xsl:when>
341          <xsl:otherwise>
342            <xsl:apply-templates select="refname[1]"/>
343          </xsl:otherwise>
344        </xsl:choose>
345  </xsl:variable>
346
347  <!-- xsl:use-attribute-sets takes only a Qname, not a variable -->
348    <xsl:choose>
349      <xsl:when test="preceding-sibling::refnamediv">
350	<!-- no title on secondary refnamedivs! -->
351      </xsl:when>
352      <xsl:when test="$section.level = 1">
353        <fo:block xsl:use-attribute-sets="refentry.title.properties">
354          <fo:block xsl:use-attribute-sets="section.title.level1.properties">
355            <xsl:value-of select="$reftitle"/>
356          </fo:block>
357        </fo:block>
358      </xsl:when>
359      <xsl:when test="$section.level = 2">
360        <fo:block xsl:use-attribute-sets="refentry.title.properties">
361          <fo:block xsl:use-attribute-sets="section.title.level2.properties">
362            <xsl:value-of select="$reftitle"/>
363          </fo:block>
364        </fo:block>
365      </xsl:when>
366      <xsl:when test="$section.level = 3">
367        <fo:block xsl:use-attribute-sets="refentry.title.properties">
368          <fo:block xsl:use-attribute-sets="section.title.level3.properties">
369            <xsl:value-of select="$reftitle"/>
370          </fo:block>
371        </fo:block>
372      </xsl:when>
373      <xsl:when test="$section.level = 4">
374        <fo:block xsl:use-attribute-sets="refentry.title.properties">
375          <fo:block xsl:use-attribute-sets="section.title.level4.properties">
376            <xsl:value-of select="$reftitle"/>
377          </fo:block>
378        </fo:block>
379      </xsl:when>
380      <xsl:when test="$section.level = 5">
381        <fo:block xsl:use-attribute-sets="refentry.title.properties">
382          <fo:block xsl:use-attribute-sets="section.title.level5.properties">
383            <xsl:value-of select="$reftitle"/>
384          </fo:block>
385        </fo:block>
386      </xsl:when>
387      <xsl:otherwise>
388        <fo:block xsl:use-attribute-sets="refentry.title.properties">
389          <fo:block xsl:use-attribute-sets="section.title.level6.properties">
390            <xsl:value-of select="$reftitle"/>
391          </fo:block>
392        </fo:block>
393      </xsl:otherwise>
394    </xsl:choose>
395    </xsl:if>
396
397    <fo:block>
398      <xsl:if test="not(following-sibling::refnamediv)">
399	<xsl:attribute name="space-after">1em</xsl:attribute>
400      </xsl:if>
401      <xsl:apply-templates/>
402    </fo:block>
403  </fo:block>
404</xsl:template>
405
406<xsl:template match="refname">
407  <xsl:if test="not(preceding-sibling::refdescriptor)">
408    <xsl:apply-templates/>
409    <xsl:if test="following-sibling::refname">
410      <xsl:text>, </xsl:text>
411    </xsl:if>
412  </xsl:if>
413</xsl:template>
414
415<xsl:template match="refpurpose">
416  <xsl:text> </xsl:text>
417  <xsl:call-template name="dingbat">
418    <xsl:with-param name="dingbat">em-dash</xsl:with-param>
419  </xsl:call-template>
420  <xsl:text> </xsl:text>
421  <xsl:apply-templates/>
422</xsl:template>
423
424<xsl:template match="refdescriptor">
425  <xsl:apply-templates/>
426</xsl:template>
427
428<xsl:template match="refclass">
429  <xsl:if test="$refclass.suppress = 0">
430  <fo:block font-weight="bold">
431    <xsl:if test="@role">
432      <xsl:value-of select="@role"/>
433      <xsl:text>: </xsl:text>
434    </xsl:if>
435    <xsl:apply-templates/>
436  </fo:block>
437  </xsl:if>
438</xsl:template>
439
440<xsl:template match="refsynopsisdiv">
441  <xsl:variable name="id">
442    <xsl:call-template name="object.id"/>
443  </xsl:variable>
444
445  <fo:block id="{$id}">
446    <xsl:if test="not(refsynopsisdivinfo/title|docinfo/title|info/title|title)">
447      <!-- * if we there is no appropriate title for this Refsynopsisdiv, -->
448      <!-- * then we need to call format.refentry.subheading to generate one -->
449      <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
450                xsl:use-attribute-sets="refsynopsisdiv.titlepage.recto.style"
451                font-family="{$title.fontset}">
452        <!-- Contents of what is now the format.refentry.subheading -->
453        <!-- template were formerly intended to be used only to -->
454        <!-- process those subsections of Refentry that have "real" -->
455        <!-- title children. So as a kludge to get around the fact -->
456        <!-- that the template still basically "expects" to be -->
457        <!-- processing that kind of a node, when we call the -->
458        <!-- template to process generated titles, we must call it -->
459        <!-- with values for the "offset" and "section" parameters -->
460        <!-- that are different from the default values in the -->
461        <!-- format.refentry.subheading template itself. Because -->
462        <!-- those defaults are the values appropriate for processing -->
463        <!-- "real" title nodes. -->
464        <xsl:call-template name="format.refentry.subheading">
465          <xsl:with-param name="section" select="parent::*"/>
466          <xsl:with-param name="offset" select="1"/>
467          <xsl:with-param name="gentext.key" select="'RefSynopsisDiv'"/>
468        </xsl:call-template>
469      </fo:block>
470    </xsl:if>
471    <xsl:call-template name="refsynopsisdiv.titlepage"/>
472    <xsl:apply-templates/>
473  </fo:block>
474</xsl:template>
475
476<xsl:template match="refsection">
477  <xsl:variable name="id">
478    <xsl:call-template name="object.id"/>
479  </xsl:variable>
480
481  <fo:block id="{$id}">
482    <xsl:call-template name="refsection.titlepage"/>
483    <xsl:apply-templates/>
484  </fo:block>
485</xsl:template>
486
487<xsl:template match="refsect1">
488  <xsl:variable name="id">
489    <xsl:call-template name="object.id"/>
490  </xsl:variable>
491
492  <fo:block id="{$id}">
493    <xsl:call-template name="refsect1.titlepage"/>
494    <xsl:apply-templates/>
495  </fo:block>
496</xsl:template>
497
498<xsl:template match="refsect2">
499  <xsl:variable name="id">
500    <xsl:call-template name="object.id"/>
501  </xsl:variable>
502
503  <fo:block id="{$id}">
504    <xsl:call-template name="refsect2.titlepage"/>
505    <xsl:apply-templates/>
506  </fo:block>
507</xsl:template>
508
509<xsl:template match="refsect3">
510  <xsl:variable name="id">
511    <xsl:call-template name="object.id"/>
512  </xsl:variable>
513
514  <fo:block id="{$id}">
515    <xsl:call-template name="refsect3.titlepage"/>
516    <xsl:apply-templates/>
517  </fo:block>
518</xsl:template>
519
520<xsl:template match="refsynopsisdiv/title
521                     |refsection/title
522                     |refsect1/title
523                     |refsect2/title
524                     |refsect3/title">
525  <!-- nop; titlepage.mode instead -->
526</xsl:template>
527
528<xsl:template match="refsynopsisdiv/title
529                     |refsection/title
530                     |refsect1/title
531                     |refsect2/title
532                     |refsect3/title"
533              mode="titlepage.mode"
534              priority="2">
535  <xsl:call-template name="format.refentry.subheading"/>
536</xsl:template>
537
538<xsl:template name="format.refentry.subheading">
539<!-- This template is now called to process generated titles for -->
540<!-- Refnamediv and Refsynopsisdiv, as well as "real" titles for -->
541<!-- Refsynopsisdiv, Refsection, and Refsect[1-3]. -->
542<!-- -->
543<!-- But the contents of this template were formerly intended to be used -->
544<!-- only to process those subsections of Refentry that have "real" title -->
545<!-- children. So as a kludge to get around the fact that the template -->
546<!-- still basically "expects" to be processing that kind of a node, the -->
547<!-- "offset" parameter was added and the "section" variable was changed to -->
548<!-- a parameter so that when called for a generated title on a Refnamediv -->
549<!-- or Refsynopsisdiv, we can call it like this: -->
550<!-- -->
551<!--     <xsl:call-template name="format.refentry.subheading"> -->
552<!--       <xsl:with-param name="section" select="self::*"/> -->
553<!--       <xsl:with-param name="offset" select="1"/> -->
554<!--       <xsl:with-param name="gentext.key" select="'RefName'"/> -->
555<!--     </xsl:call-template> -->
556<!-- -->
557  <xsl:param name="section" select="parent::*"/>
558  <xsl:param name="offset" select="0"/>
559  <xsl:param name="gentext.key"/>
560
561  <fo:block keep-with-next.within-column="always">
562    <xsl:variable name="id">
563      <xsl:call-template name="object.id">
564        <xsl:with-param name="object" select="$section"/>
565      </xsl:call-template>
566    </xsl:variable>
567
568    <xsl:variable name="level">
569      <xsl:call-template name="section.level">
570        <xsl:with-param name="node" select="$section"/>
571      </xsl:call-template>
572    </xsl:variable>
573
574    <xsl:variable name="title">
575      <!-- If we have a non-empty value for the $gentext.key param, then we -->
576      <!-- generate an appropriate title here. Otherwise, we have a real -->
577      <!-- title child, so we copy contents of that to the result tree. -->
578      <xsl:choose>
579        <xsl:when test="$gentext.key != ''">
580          <xsl:call-template name="gentext">
581            <xsl:with-param name="key" select="$gentext.key"/>
582          </xsl:call-template>
583        </xsl:when>
584        <xsl:otherwise>
585          <xsl:apply-templates select="$section" mode="object.title.markup">
586            <xsl:with-param name="allow-anchors" select="1"/>
587          </xsl:apply-templates>
588        </xsl:otherwise>
589      </xsl:choose>
590    </xsl:variable>
591
592    <xsl:if test="$passivetex.extensions != 0">
593      <fotex:bookmark xmlns:fotex="http://www.tug.org/fotex" 
594                      fotex-bookmark-level="{$level + 2 + $offset}" 
595                      fotex-bookmark-label="{$id}">
596        <xsl:value-of select="$title"/>
597      </fotex:bookmark>
598    </xsl:if>
599
600    <xsl:if test="$axf.extensions != 0">
601      <xsl:attribute name="axf:outline-level">
602        <xsl:value-of select="count(ancestor::*)-1 + $offset"/>
603      </xsl:attribute>
604      <xsl:attribute name="axf:outline-expand">false</xsl:attribute>
605      <xsl:attribute name="axf:outline-title">
606        <xsl:value-of select="$title"/>
607      </xsl:attribute>
608    </xsl:if>
609
610    <xsl:call-template name="section.heading">
611      <xsl:with-param name="level" select="$level + $offset"/>
612      <xsl:with-param name="title" select="$title"/>
613    </xsl:call-template>
614  </fo:block>
615</xsl:template>
616
617<!-- ==================================================================== -->
618
619</xsl:stylesheet>
620