forked from docbook/xslt20-stylesheets
/
xref.xsl
1101 lines (951 loc) · 38.6 KB
/
xref.xsl
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
xmlns:f="http://docbook.org/xslt/ns/extension"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:m="http://docbook.org/xslt/ns/mode"
xmlns:mp="http://docbook.org/xslt/ns/mode/private"
xmlns:t="http://docbook.org/xslt/ns/template"
xmlns:u="http://nwalsh.com/xsl/unittests#"
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="db doc f fn h m mp t u xlink xs"
version="2.0">
<!-- Use internal variable for olink xlink role for consistency -->
<xsl:variable
name="xolink.role">http://docbook.org/xlink/role/olink</xsl:variable>
<!-- ============================================================ -->
<xsl:template match="db:anchor">
<fo:inline>
<xsl:call-template name="t:id"/>
</fo:inline>
</xsl:template>
<!-- ============================================================ -->
<xsl:template match="db:xref" name="t:xref">
<xsl:param name="xhref" select="@xlink:href"/>
<!-- is the @xlink:href a local idref link? -->
<xsl:param name="xlink.idref"
select="if (f:xpointer-idref($xhref) != '')
then f:xpointer-idref($xhref)
else ''"/>
<xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
<xsl:param name="linkend.targets" select="key('id',@linkend)"/>
<xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
<xsl:call-template name="t:check-id-unique">
<xsl:with-param name="linkend"
select="if ($xlink.idref != '')
then $xlink.idref
else @linkend"/>
</xsl:call-template>
<xsl:variable name="xrefstyle">
<xsl:choose>
<xsl:when test="@role and not(@xrefstyle)
and $use.role.as.xrefstyle">
<xsl:value-of select="@role"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@xrefstyle"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="t:simple-xlink">
<xsl:with-param name="content">
<fo:inline xsl:use-attribute-sets="xref.properties">
<xsl:choose>
<xsl:when test="@endterm">
<xsl:variable name="etargets" select="key('id',@endterm)"/>
<xsl:choose>
<xsl:when test="not($etargets)">
<xsl:message>
<xsl:text>Endterm points to nonexistent ID: </xsl:text>
<xsl:value-of select="@endterm"/>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$etargets[1]" mode="m:endterm"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$target/@xreflabel">
<xsl:call-template name="t:xref-xreflabel">
<xsl:with-param name="target" select="$target"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$target">
<!-- FIXME: why? -->
<xsl:if test="not(parent::db:citation)">
<xsl:apply-templates select="$target" mode="m:xref-to-prefix"/>
</xsl:if>
<xsl:apply-templates select="$target" mode="m:xref-to">
<xsl:with-param name="referrer" select="."/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
</xsl:apply-templates>
<xsl:if test="not(parent::db:citation)">
<xsl:apply-templates select="$target" mode="m:xref-to-suffix"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>ERROR: xref linking to </xsl:text>
<xsl:value-of select="@linkend|@xlink:href"/>
<xsl:text> has no generated link text.</xsl:text>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:otherwise>
</xsl:choose>
</fo:inline>
</xsl:with-param>
</xsl:call-template>
<!-- Add standard page reference? -->
<xsl:choose>
<xsl:when test="not($target)">
<!-- page numbers only for local targets -->
</xsl:when>
<xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
and contains($xrefstyle, 'nopage')">
<!-- negative xrefstyle in instance turns it off -->
</xsl:when>
<!-- positive xrefstyle already handles it -->
<xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:')
and (contains($xrefstyle, 'page')
or contains($xrefstyle, 'Page')))
and ($insert.xref.page.number = 'yes'
or $insert.xref.page.number = '1')
or $target/self::db:para">
<xsl:apply-templates select="$target" mode="m:page-citation">
<xsl:with-param name="id" select="$target/@xml:id"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- ============================================================ -->
<!-- Handled largely like an xref -->
<!-- To be done: add support for begin, end, and units attributes -->
<xsl:template match="db:biblioref" name="t:biblioref">
<xsl:variable name="target" select="key('id',@linkend)[1]"/>
<xsl:variable name="xrefstyle">
<xsl:choose>
<xsl:when test="@role and not(@xrefstyle)
and $use.role.as.xrefstyle">
<xsl:value-of select="@role"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@xrefstyle"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="t:check-id-unique">
<xsl:with-param name="linkend" select="@linkend"/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="not($target)">
<xsl:text>???</xsl:text>
</xsl:when>
<xsl:when test="@endterm">
<fo:basic-link internal-destination="{@linkend}"
xsl:use-attribute-sets="xref.properties">
<xsl:variable name="etargets" select="key('id',@endterm)"/>
<xsl:choose>
<xsl:when test="not($etargets)">
<xsl:message>
<xsl:text>Endterm points to nonexistent ID: </xsl:text>
<xsl:value-of select="@endterm"/>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$etargets[1]" mode="m:endterm"/>
</xsl:otherwise>
</xsl:choose>
</fo:basic-link>
</xsl:when>
<xsl:when test="$target/@xreflabel">
<fo:basic-link internal-destination="{@linkend}"
xsl:use-attribute-sets="xref.properties">
<xsl:call-template name="t:xref-xreflabel">
<xsl:with-param name="target" select="$target"/>
</xsl:call-template>
</fo:basic-link>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(parent::db:citation)">
<xsl:apply-templates select="$target" mode="m:xref-to-prefix"/>
</xsl:if>
<fo:basic-link internal-destination="{@linkend}"
xsl:use-attribute-sets="xref.properties">
<xsl:apply-templates select="$target" mode="m:xref-to">
<xsl:with-param name="referrer" select="."/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
</xsl:apply-templates>
</fo:basic-link>
<xsl:if test="not(parent::db:citation)">
<xsl:apply-templates select="$target" mode="m:xref-to-suffix"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- ==================================================================== -->
<xsl:template match="*" mode="m:endterm">
<!-- Process the children of the endterm element -->
<xsl:variable name="endterm">
<xsl:apply-templates/>
</xsl:variable>
<xsl:apply-templates select="$endterm" mode="mp:remove-ids"/>
</xsl:template>
<xsl:template match="*" mode="mp:remove-ids">
<xsl:copy>
<xsl:copy-of select="@*[name(.) != 'id']"/>
<xsl:apply-templates mode="mp:remove-ids"/>
</xsl:copy>
</xsl:template>
<!--- ==================================================================== -->
<xsl:template match="*" mode="m:xref-to-prefix"/>
<xsl:template match="*" mode="m:xref-to-suffix"/>
<xsl:template match="*" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:if test="$verbose != 0">
<xsl:message>
<xsl:text>Don't know what gentext to create for xref to: "</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>"</xsl:text>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="db:title" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<!-- for title, xref to the parent (parent of the info, that is) -->
<xsl:apply-templates select="../.." mode="m:xref-to">
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:abstract|db:article|db:bibliodiv|db:bibliomset
|db:biblioset|db:blockquote|db:calloutlist|db:colophon
|db:constraintdef|db:formalpara|db:glossdiv|db:indexdiv
|db:itemizedlist|db:legalnotice|db:msg|db:msgexplan|db:msgmain
|db:msgrel|db:msgset|db:msgsub|db:orderedlist|db:partintro
|db:productionset|db:qandadiv|db:refsynopsisdiv|db:segmentedlist
|db:set|db:setindex|db:sidebar|db:toc|db:variablelist"
mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<!-- catch-all for things with (possibly optional) titles -->
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:caution|db:important|db:note|db:tip|db:warning"
mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<!-- catch-all for things with (possibly optional) titles -->
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:author|db:editor|db:othercredit|db:personname"
mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:call-template name="t:person-name"/>
</xsl:template>
<xsl:template match="db:authorgroup" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:call-template name="t:person-name-list"/>
</xsl:template>
<xsl:template match="db:figure|db:example|db:table|db:equation" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:procedure" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:task" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:cmdsynopsis" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select=".//db:command[1]" mode="m:xref"/>
</xsl:template>
<xsl:template match="db:funcsynopsis" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select=".//db:function[1]" mode="m:xref"/>
</xsl:template>
<xsl:template match="db:dedication|db:preface|db:chapter|db:appendix"
mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:bibliography|db:glossary|db:index" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:biblioentry|db:bibliomixed" mode="m:xref-to-prefix">
<xsl:text>[</xsl:text>
</xsl:template>
<xsl:template match="db:biblioentry|db:bibliomixed" mode="m:xref-to-suffix">
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="db:biblioentry|db:bibliomixed" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:value-of select="f:biblioentry-label(.)"/>
</xsl:template>
<xsl:template match="db:glossentry" mode="m:xref-to">
<xsl:choose>
<xsl:when test="$glossentry.show.acronym = 'primary'">
<xsl:choose>
<xsl:when test="db:acronym|db:abbrev">
<xsl:apply-templates select="(db:acronym|db:abbrev)[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="db:glossterm[1]" mode="m:xref-to"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="db:glossterm[1]" mode="m:xref-to"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="db:glossterm" mode="m:xref-to">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="db:listitem" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:section|db:simplesect
|db:sect1|db:sect2|db:sect3|db:sect4|db:sect5
|db:refsect1|db:refsect2|db:refsect3|db:refsection"
mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
<!-- What about "in Chapter X"? -->
</xsl:template>
<xsl:template match="db:bridgehead" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
<!-- What about "in Chapter X"? -->
</xsl:template>
<xsl:template match="db:qandaset|db:qandadiv" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:qandaentry" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="db:question[1]" mode="m:xref-to">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:question|db:answer" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:part|db:reference" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:refentry" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:choose>
<xsl:when test="db:refmeta/db:refentrytitle">
<xsl:apply-templates select="db:refmeta/db:refentrytitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="db:refnamediv/db:refname[1]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="db:refmeta/db:manvolnum"/>
</xsl:template>
<xsl:template match="db:refnamediv" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="db:refname[1]" mode="m:xref-to">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:refname" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates mode="m:xref-to">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:step" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:value-of select="f:gentext(.,'Step')"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="." mode="m:number"/>
</xsl:template>
<xsl:template match="db:varlistentry" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="db:term[1]" mode="m:xref-to">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:varlistentry/db:term" mode="m:xref-to">
<xsl:param name="verbose" select="1"/>
<!-- to avoid the comma that will be generated if there are several terms -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="db:co" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="db:callout-bug"/>
</xsl:template>
<xsl:template match="db:area|db:areaset" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<!-- FIXME:
<xsl:call-template name="t:callout-bug">
<xsl:with-param name="db:conum">
<xsl:apply-templates select="." mode="db:conumber"/>
</xsl:with-param>
</xsl:call-template>
-->
<xsl:text>X</xsl:text>
</xsl:template>
<xsl:template match="db:book" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="m:object-xref-markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="db:para" mode="m:xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose"/>
<xsl:variable name="context" select="(ancestor::db:simplesect
|ancestor::db:section
|ancestor::db:sect1
|ancestor::db:sect2
|ancestor::db:sect3
|ancestor::db:sect4
|ancestor::db:sect5
|ancestor::db:refsection
|ancestor::db:refsect1
|ancestor::db:refsect2
|ancestor::db:refsect3
|ancestor::db:chapter
|ancestor::db:appendix
|ancestor::db:preface
|ancestor::db:partintro
|ancestor::db:dedication
|ancestor::db:colophon
|ancestor::db:bibliography
|ancestor::db:index
|ancestor::db:glossary
|ancestor::db:glossentry
|ancestor::db:listitem
|ancestor::db:varlistentry)[last()]"/>
<xsl:apply-templates select="$context" mode="m:xref-to">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:template>
<!-- ==================================================================== -->
<xsl:template match="db:link" name="t:link">
<xsl:param name="linkend" select="@linkend"/>
<xsl:param name="targets" select="key('id',$linkend)"/>
<xsl:param name="target" select="$targets[1]"/>
<!-- FIXME: handle <link xlink:href="#foo"/> -->
<xsl:variable name="xrefstyle">
<xsl:choose>
<xsl:when test="@role and not(@xrefstyle)
and $use.role.as.xrefstyle">
<xsl:value-of select="@role"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@xrefstyle"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="t:simple-xlink">
<xsl:with-param name="content">
<fo:inline xsl:use-attribute-sets="xref.properties">
<xsl:choose>
<xsl:when test="not(empty(child::node()))">
<!-- If it has content, use it -->
<xsl:apply-templates/>
</xsl:when>
<!-- look for an endterm -->
<xsl:when test="@endterm">
<xsl:variable name="etargets" select="key('id',@endterm)"/>
<xsl:choose>
<xsl:when test="not($etargets)">
<xsl:message>
<xsl:text>Endterm points to nonexistent ID: </xsl:text>
<xsl:value-of select="@endterm"/>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$etargets[1]" mode="m:endterm"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Use the xlink:href if no other text -->
<xsl:when test="@xlink:href">
<xsl:call-template name="t:hyphenate-url">
<xsl:with-param name="url" select="@xlink:href"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>Link element has no content and no endterm. </xsl:text>
<xsl:text>Nothing to show in the link to </xsl:text>
<xsl:value-of select="$target"/>
</xsl:message>
<xsl:text>???</xsl:text>
</xsl:otherwise>
</xsl:choose>
</fo:inline>
</xsl:with-param>
</xsl:call-template>
<!-- Add standard page reference? -->
<xsl:choose>
<!-- page numbering on link only enabled for @linkend -->
<!-- There is no link element in DB5 with xlink:href -->
<xsl:when test="not($linkend)">
<!-- must have been an xlink:href -->
<xsl:call-template name="t:hyperlink-url-display">
<xsl:with-param name="url" select="@xlink:href"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
and contains($xrefstyle, 'nopage')">
<!-- negative xrefstyle in instance turns it off -->
</xsl:when>
<xsl:when test="(starts-with(normalize-space($xrefstyle), 'select:')
and $insert.link.page.number = 'maybe'
and (contains($xrefstyle, 'page')
or contains($xrefstyle, 'Page')))
or ($insert.link.page.number = 'yes'
or $insert.link.page.number = '1')
or $target/self::db:para">
<xsl:apply-templates select="$target" mode="m:page-citation">
<xsl:with-param name="id" select="$linkend"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="t:hyperlink-url-display">
<!-- This template is called for all external hyperlinks;
it determines whether the URL for the hyperlink is displayed,
and how to display it (either inline or as a numbered footnote). -->
<xsl:param name="url"/>
<xsl:if test="not(empty(child::node()))
and string(.) != $url
and $ulink.show">
<!-- * Display the URL for this hyperlink only if it is non-empty, -->
<!-- * and the value of its content is not a URL that is the same as -->
<!-- * URL it links to, and if ulink.show is non-zero. -->
<xsl:choose>
<xsl:when test="$ulink.footnotes and not(ancestor::db:footnote)">
<!-- * ulink.show and ulink.footnote are both non-zero; that -->
<!-- * means we display the URL as a footnote (instead of inline) -->
<fo:footnote>
<xsl:call-template name="t:ulink-footnote-number"/>
<fo:footnote-body xsl:use-attribute-sets="footnote.properties">
<fo:block>
<xsl:call-template name="t:ulink-footnote-number"/>
<xsl:text> </xsl:text>
<fo:basic-link external-destination="url({$url})">
<xsl:value-of select="$url"/>
</fo:basic-link>
</fo:block>
</fo:footnote-body>
</fo:footnote>
</xsl:when>
<xsl:otherwise>
<!-- * ulink.show is non-zero, but ulink.footnote is not; that -->
<!-- * means we display the URL inline -->
<fo:inline hyphenate="false" font-style="normal">
<!-- * put square brackets around the URL -->
<xsl:text> [</xsl:text>
<fo:basic-link external-destination="url({$url})">
<xsl:call-template name="t:hyphenate-url">
<xsl:with-param name="url" select="$url"/>
</xsl:call-template>
</fo:basic-link>
<xsl:text>]</xsl:text>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="t:ulink-footnote-number">
<fo:inline xsl:use-attribute-sets="footnote.mark.properties">
<xsl:choose>
<xsl:when test="$fo.processor = 'fop'">
<xsl:attribute name="vertical-align">super</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="baseline-shift">super</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="fnum">
<!-- * Determine the footnote number to display for this hyperlink, -->
<!-- * by counting all foonotes, ulinks, and any elements that have -->
<!-- * an xlink:href attribute that meets the following criteria: -->
<!-- * -->
<!-- * - the content of the element is not a URI that is the same -->
<!-- * URI as the value of the href attribute -->
<!-- * - the href attribute is not an internal ID reference (does -->
<!-- * not start with a hash sign) -->
<!-- * - the href is not part of an olink reference (the element -->
<!-- * - does not have an xlink:role attribute that indicates it is -->
<!-- * an olink, and the href does not contain a hash sign) -->
<!-- * - the element either has no xlink:type attribute or has -->
<!-- * an xlink:type attribute whose value is 'simple' -->
<!-- FIXME: list in @from is probably not complete -->
<xsl:number level="any"
from="db:chapter|db:appendix|db:preface|db:article
|db:refentry|db:bibliography[not(parent::db:article)]"
count="db:footnote[not(@label)][not(ancestor::db:tgroup)]
|db:link[node()][@xlink:href != .][not(ancestor::db:footnote)]
|*[node()][@xlink:href][not(@xlink:href = .)][not(starts-with(@xlink:href,'#'))]
[not(contains(@xlink:href,'#') and @xlink:role = $xolink.role)]
[not(@xlink:type) or @xlink:type='simple']
[not(ancestor::db:footnote)]"
format="1"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="string-length($footnote.number.symbols) >= $fnum">
<xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="$fnum" format="{$footnote.number.format}"/>
</xsl:otherwise>
</xsl:choose>
</fo:inline>
</xsl:template>
<xsl:template name="t:hyphenate-url">
<xsl:param name="url" select="''"/>
<xsl:choose>
<xsl:when test="$ulink.hyphenate = ''">
<xsl:value-of select="$url"/>
</xsl:when>
<xsl:when test="string-length($url) > 1">
<xsl:variable name="char" select="substring($url, 1, 1)"/>
<xsl:value-of select="$char"/>
<xsl:if test="contains($ulink.hyphenate.chars, $char)">
<!-- Do not hyphen in-between // -->
<xsl:if test="not($char = '/' and substring($url,2,1) = '/')">
<xsl:copy-of select="$ulink.hyphenate"/>
</xsl:if>
</xsl:if>
<!-- recurse to the next character -->
<xsl:call-template name="t:hyphenate-url">
<xsl:with-param name="url" select="substring($url, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- FIXME: support db:olink -->
<!-- ==================================================================== -->
<xsl:template name="t:title-xref">
<xsl:param name="target" select="."/>
<xsl:choose>
<xsl:when test="$target/self::db:figure
or $target/self::db:example
or $target/self::db:equation
or $target/self::db:table
or $target/self::db:dedication
or $target/self::db:preface
or $target/self::db:bibliography
or $target/self::db:glossary
or $target/self::db:index
or $target/self::db:setindex
or $target/self::db:colophon">
<xsl:call-template name="gentext-startquote"/>
<xsl:text>FIXME:</xsl:text>
<!--
<xsl:apply-templates select="$target" mode="m:title-markup"/>
-->
<xsl:call-template name="gentext-endquote"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>FIXME:</xsl:text>
<!--
<fo:inline font-style="italic">
<xsl:apply-templates select="$target" mode="m:title-markup"/>
</fo:inline>
-->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="t:number-xref">
<xsl:param name="target" select="."/>
<xsl:apply-templates select="$target" mode="m:label-markup"/>
</xsl:template>
<!-- ==================================================================== -->
<xsl:template name="t:xref-xreflabel">
<!-- called to process an xreflabel...you might use this to make -->
<!-- xreflabels come out in the right font for different targets, -->
<!-- for example. -->
<xsl:param name="target" select="."/>
<xsl:value-of select="$target/@xreflabel"/>
</xsl:template>
<!-- ==================================================================== -->
<xsl:template match="db:title" mode="m:xref">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="db:command" mode="m:xref">
<xsl:call-template name="t:inline-boldseq"/>
</xsl:template>
<xsl:template match="db:function" mode="m:xref">
<xsl:call-template name="t:inline-monoseq"/>
</xsl:template>
<xsl:template match="*" mode="m:page-citation">
<xsl:param name="id" select="'???'"/>
<fo:basic-link internal-destination="{$id}"
xsl:use-attribute-sets="xref.properties">
<fo:inline keep-together.within-line="always">
<xsl:call-template name="substitute-markup">
<xsl:with-param name="template">
<xsl:call-template name="gentext-template">
<xsl:with-param name="name" select="'page.citation'"/>
<xsl:with-param name="context" select="'xref'"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</fo:inline>
</fo:basic-link>
</xsl:template>
<xsl:template match="*" mode="m:pagenumber-markup">
<fo:page-number-citation ref-id="{f:node-id(.)}"/>
</xsl:template>
<!-- ============================================================ -->
<doc:mode name="m:insert-title-markup" xmlns="http://docbook.org/ns/docbook">
<refpurpose>Mode for inserting title markup</refpurpose>
<refdescription>
<para>This mode is used to insert title markup. Any element processed
in this mode should generate its title.</para>
</refdescription>
</doc:mode>
<xsl:template match="*" mode="m:insert-title-markup">
<xsl:param name="purpose"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="title"/>
<xsl:choose>
<xsl:when test="$purpose = 'xref' and db:info/db:titleabbrev">
<xsl:text>FIXME:</xsl:text>
<!--
<xsl:apply-templates select="." mode="m:titleabbrev-markup"/>
-->
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$title"/>