forked from codingo/BibWord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BibWord_Stylesheet.XSL
3246 lines (2917 loc) · 140 KB
/
BibWord_Stylesheet.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"?>
<!--
Stylesheet for Microsoft Word 2007/2008/2010 Bibliography formatting.
Author(s): Yves Dhondt (yves.dhondt@gmail.com)
Copyright: Copyright (c) 2009 Yves Dhondt
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->
<xsl:stylesheet version="1.0"
xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!-- Variable containing all necessary data for a certain style of bibliography. -->
<xsl:variable name="data">
<general>
<stylename>A BibWord Citation and Bibliograpy Style</stylename>
<version>2009.11.28</version>
<author>Yves Dhondt (yves.dhondt@gmail.com)</author>
<description>An implementation of a style.</description>
<URL>http://bibword.codeplex.com/updateStyle?id=123</URL>
<comments>
This is version 2.8 of the BibWord stylesheet.
</comments>
<display_errors>yes</display_errors>
<citation_as_link>no</citation_as_link>
</general>
<importantfields>
<source type="Book">
<b:ImportantField>b:Author/b:Author/b:NameList</b:ImportantField>
<b:ImportantField>b:Author/b:Editor/b:NameList</b:ImportantField>
<b:ImportantField>b:Title</b:ImportantField>
<b:ImportantField>b:Edition</b:ImportantField>
<b:ImportantField>b:Volume</b:ImportantField>
<b:ImportantField>b:Year</b:ImportantField>
<b:ImportantField>b:City</b:ImportantField>
<b:ImportantField>b:Publisher</b:ImportantField>
</source>
</importantfields>
<citation>
<openbracket>[</openbracket>
<closebracket>]</closebracket>
<separator>,</separator>
<noauthor>-Artist-Author-BookAuthor-Compiler-Composer-Conductor-Counsel-Director-Editor-Interviewee-Interviewer-Inventor-Performer-ProducerName-Translator-Writer-</noauthor>
<notitle>-Title-AlbumTitle-BookTitle-BroadcastTitle-InternetSiteTitle-PeriodicalTitle-PublicationTitle-ShortTitle-</notitle>
<noyear>-Year-YearAccessed-"n.d."-</noyear>
<source type="Placeholder">
<format>[%Tag%]</format>
</source>
<source type="Book">
<format>{%CitationPrefix%}%RefOrder%{, vol. %CitationVolume%}{, %CitationPages:p. :pp. %}{%CitationSuffix%}</format>
</source>
</citation>
<footnotecitation>
<openbracket>[</openbracket>
<closebracket>]</closebracket>
<separator>,</separator>
<noauthor>-Artist-Author-BookAuthor-Compiler-Composer-Conductor-Counsel-Director-Editor-Interviewee-Interviewer-Inventor-Performer-ProducerName-Translator-Writer-</noauthor>
<notitle>-Title-AlbumTitle-BookTitle-BroadcastTitle-InternetSiteTitle-PeriodicalTitle-PublicationTitle-ShortTitle-</notitle>
<noyear>-Year-YearAccessed-"n.d."-</noyear>
<source type="Placeholder">
<format>[%Tag%]</format>
</source>
<source type="Book">
<format>{%CitationPrefix%}{%Author:2|Editor:3|"[Anonymous]"%.}{ %Title|ShortTitle%.{ %Edition:o% ed.}{ Vol %Volume%.}}{ %City%{ (%StateProvince%)}{: %Publisher%{; %Year%}}}{ %Publisher%{; %Year%}}{ %Year%}.{, %CitationPages:p. :pp. %}{%CitationSuffix%}</format>
</source>
</footnotecitation>
<bibliography>
<columns>2</columns>
<source type="Placeholder">
<column id="1">
<halign>left</halign>
<valign>top</valign>
<format>%RefOrder%</format>
</column>
<column id="2">
<halign>left</halign>
<valign>top</valign>
<format>[[%Tag%]]</format>
</column>
</source>
<source type="Book">
<column id="1">
<halign>left</halign>
<valign>top</valign>
<format>%RefOrder%</format>
</column>
<column id="2">
<halign>left</halign>
<valign>top</valign>
<format>{%Author:2|Editor:3|"[Anonymous]"%.}{ %Title|ShortTitle%.{ %Edition:o% ed.}{ Vol %Volume%.}}{ %City%{ (%StateProvince%)}{: %Publisher%{; %Year%}}}{ %Publisher%{; %Year%}}{ %Year%}.</format>
</column>
</source>
</bibliography>
<namelists>
<list name="sort" id="0">
<single_prefix></single_prefix>
<multi_prefix></multi_prefix>
<corporate>{%Corporate%}</corporate>
<first_person>{%Last|First%}</first_person>
<other_persons>{%Last|First%}</other_persons>
<separator_between_if_two> </separator_between_if_two>
<separator_between_if_more_than_two> </separator_between_if_more_than_two>
<separator_before_last></separator_before_last>
<max_number_of_persons_to_display>500</max_number_of_persons_to_display>
<number_of_persons_to_display_if_more_than_max>500</number_of_persons_to_display_if_more_than_max>
<overflow></overflow>
<single_suffix></single_suffix>
<multi_suffix></multi_suffix>
</list>
<list name="citation" id="1">
<single_prefix></single_prefix>
<multi_prefix></multi_prefix>
<corporate>{%Corporate%}</corporate>
<first_person>{%Last|First%}{ %First:a%}{%Middle:a%}</first_person>
<other_persons>{%Last|First%}{ %First:a%}{%Middle:a%}</other_persons>
<separator_between_if_two> and </separator_between_if_two>
<separator_between_if_more_than_two>, </separator_between_if_more_than_two>
<separator_before_last>, and </separator_before_last>
<max_number_of_persons_to_display>2</max_number_of_persons_to_display>
<number_of_persons_to_display_if_more_than_max>1</number_of_persons_to_display_if_more_than_max>
<overflow> et al.</overflow>
<single_suffix></single_suffix>
<multi_suffix></multi_suffix>
</list>
<list name="author" id="2">
<single_prefix></single_prefix>
<multi_prefix></multi_prefix>
<corporate>{%Corporate%}</corporate>
<first_person>{%Last|First%}{ %First:a%}{%Middle:a%}</first_person>
<other_persons>{%Last|First%}{ %First:a%}{%Middle:a%}</other_persons>
<separator_between_if_two>, </separator_between_if_two>
<separator_between_if_more_than_two>, </separator_between_if_more_than_two>
<separator_before_last>, and </separator_before_last>
<max_number_of_persons_to_display>12</max_number_of_persons_to_display>
<number_of_persons_to_display_if_more_than_max>10</number_of_persons_to_display_if_more_than_max>
<overflow>, et al.</overflow>
<single_suffix></single_suffix>
<multi_suffix></multi_suffix>
</list>
<list name="editor" id="3">
<single_prefix></single_prefix>
<multi_prefix></multi_prefix>
<corporate>{%Corporate%}</corporate>
<first_person>{%Last|First%}{ %First:a%}{%Middle:a%}</first_person>
<other_persons>{%Last|First%}{ %First:a%}{%Middle:a%}</other_persons>
<separator_between_if_two>, </separator_between_if_two>
<separator_between_if_more_than_two>, </separator_between_if_more_than_two>
<separator_before_last>, </separator_before_last>
<max_number_of_persons_to_display>10</max_number_of_persons_to_display>
<number_of_persons_to_display_if_more_than_max>10</number_of_persons_to_display_if_more_than_max>
<overflow>, et al.</overflow>
<single_suffix>, editor</single_suffix>
<multi_suffix>, editors</multi_suffix>
</list>
</namelists>
<strings>
<months>
<month number="1">Jan</month>
<month number="2">Feb</month>
<month number="3">Mar</month>
<month number="4">Apr</month>
<month number="5">May</month>
<month number="6">Jun</month>
<month number="7">Jul</month>
<month number="8">Aug</month>
<month number="9">Sep</month>
<month number="10">Oct</month>
<month number="11">Nov</month>
<month number="12">Dec</month>
</months>
<sourcetypes>
<sourcetype type="Art">Art</sourcetype>
<sourcetype type="ArticleInAPeriodical">Article</sourcetype>
<sourcetype type="Book">Book</sourcetype>
<sourcetype type="BookSection">Book Section</sourcetype>
<sourcetype type="Case">Case</sourcetype>
<sourcetype type="ConferenceProceedings">Conference Proceedings</sourcetype>
<sourcetype type="DocumentFromInternetSite">Electronic Document</sourcetype>
<sourcetype type="ElectronicSource">Electronic Source</sourcetype>
<sourcetype type="Film">Film</sourcetype>
<sourcetype type="InternetSite">Web Site</sourcetype>
<sourcetype type="Interview">Interview</sourcetype>
<sourcetype type="JournalArticle">Journal Article</sourcetype>
<sourcetype type="Misc">Miscellaneous</sourcetype>
<sourcetype type="Patent">Patent</sourcetype>
<sourcetype type="Performance">Performance</sourcetype>
<sourcetype type="Report">Report</sourcetype>
<sourcetype type="SoundRecording">Sound Recording</sourcetype>
</sourcetypes>
</strings>
<extensions>
<source type="Book">
<yearsuffix>{%Author:0%}{%Year%}</yearsuffix>
</source>
</extensions>
</xsl:variable>
<!-- Indicates that all output will be in the HTML format. -->
<xsl:output method="html" encoding="utf-8"/>
<!-- Handle the different types of input documents. -->
<xsl:template match="/">
<xsl:choose>
<!-- Gets the name of the style as it will be displayed in Word 2007 / 2010. -->
<xsl:when test="b:StyleName">
<xsl:value-of select="msxsl:node-set($data)/general/stylename"/>
</xsl:when>
<!-- Gets the version information for the style in Word 2007 / 2010. -->
<xsl:when test="b:Version">
<xsl:value-of select="msxsl:node-set($data)/general/version"/>
</xsl:when>
<!-- Sets a version number in Word 2013. -->
<xsl:when test="b:XslVersion">
<xsl:choose>
<xsl:when test="msxsl:node-set($data)/general/version2013">
<xsl:value-of select="msxsl:node-set($data)/general/version2013"/>
</xsl:when>
<xsl:otherwise>
<!-- Fallback method : use a dummy version number of 1. -->
<xsl:text>1</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Set the name of the style in Word 2013. -->
<xsl:when test="b:StyleNameLocalized">
<xsl:value-of select="msxsl:node-set($data)/general/stylename"/>
</xsl:when>
<!-- Gets a description of the style. (Word 2008 or later) -->
<xsl:when test="b:Description">
<xsl:value-of select="msxsl:node-set($data)/general/description"/>
</xsl:when>
<!-- Gets the URL for updates. (Word 2008 or later) -->
<xsl:when test="b:UpdateURL">
<xsl:value-of select="msxsl:node-set($data)/general/URL"/>
</xsl:when>
<!-- Retrieve the most important fields for a certain type of citation. -->
<xsl:when test="b:GetImportantFields">
<xsl:variable name="type" select="b:GetImportantFields/b:SourceType"/>
<b:ImportantFields>
<xsl:copy-of select="msxsl:node-set($data)/importantfields/source[@type = $type]/*"/>
</b:ImportantFields>
</xsl:when>
<!-- Formats a citation for display. -->
<xsl:when test="b:Citation">
<xsl:choose>
<xsl:when test="msxsl:node-set($data)/citation">
<xsl:call-template name="format-citation"/>
</xsl:when>
<xsl:otherwise>
<!-- Fallback method. -->
<xsl:call-template name="format-footnote-citation"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Formats a footnote citation for display (Word 2008 or later). -->
<xsl:when test="b:FootnoteCitation">
<xsl:choose>
<xsl:when test="msxsl:node-set($data)/footnotecitation">
<xsl:call-template name="format-footnote-citation"/>
</xsl:when>
<xsl:otherwise>
<!-- Fallback method. -->
<xsl:call-template name="format-citation"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Formats a bibliography for display. -->
<xsl:when test="b:Bibliography">
<xsl:call-template name="format-bibliography"/>
</xsl:when>
<!-- Add a b:BibOrder element to b:Source elements (not used by Word, BibWord specific!). -->
<xsl:when test="b:BibWord">
<xsl:call-template name="bibword-extensions"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- Formats the citation. -->
<xsl:template name="format-citation">
<!-- Generate an XML node-set from the formatting data. -->
<xsl:variable name="params" select="msxsl:node-set($data)"/>
<html xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p>
<!-- Display the open bracket if this is the first citation. -->
<xsl:if test="/b:Citation/b:FirstAuthor">
<xsl:value-of select="$params/citation/openbracket" disable-output-escaping="yes"/>
</xsl:if>
<!-- Not handled: MinAuthors, SameAuthors, RepeatedAuthor. -->
<xsl:variable name="citation">
<!-- Get the format string. -->
<xsl:variable name="format">
<xsl:variable name="type" select="/b:Citation/b:Source/b:Type"/>
<xsl:variable name="sourcetype" select="/b:Citation/b:Source/b:SourceType"/>
<xsl:choose>
<!-- If there is no source type, its a placeholder. -->
<xsl:when test="string-length($sourcetype) = 0 and string-length(msxsl:node-set($data)/citation/source[@type = 'Placeholder']/format) > 0">
<xsl:value-of select="msxsl:node-set($data)/citation/source[@type = 'Placeholder']/format"/>
</xsl:when>
<!-- Go for the type element if available. -->
<xsl:when test="string-length($type) > 0 and string-length(msxsl:node-set($data)/citation/source[@type = $type]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/citation/source[@type = $type]/format"/>
</xsl:when>
<!-- Else go for the source type element if available. -->
<xsl:when test="string-length(msxsl:node-set($data)/citation/source[@type = $sourcetype]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/citation/source[@type = $sourcetype]/format"/>
</xsl:when>
<!-- Else display error message. -->
<xsl:otherwise>
<xsl:if test="msxsl:node-set($data)/general/display_errors = 'yes'">
<xsl:text><b>Unsupported </xsl:text>
<xsl:if test="string-length($type) > 0">
<xsl:text>type (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>) and </xsl:text>
</xsl:if>
<xsl:text>source type (</xsl:text>
<xsl:value-of select="$sourcetype"/>
<xsl:text>) for source </xsl:text>
<xsl:value-of select="/b:Citation/b:Source/b:Tag"/>
<xsl:text>.</b></xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Extend the source. -->
<xsl:variable name="extendedSource">
<b:Source>
<xsl:copy-of select="/b:Citation/b:Source/*"/>
<!-- For processing the \f parameter. -->
<b:CitationPrefix>
<xsl:value-of select="/b:Citation/b:PagePrefix"/>
</b:CitationPrefix>
<!-- For processing the \s parameter. -->
<b:CitationSuffix>
<xsl:value-of select="/b:Citation/b:PageSuffix"/>
</b:CitationSuffix>
<!-- For processing the \p parameter. -->
<b:CitationPages>
<xsl:value-of select="/b:Citation/b:Pages"/>
</b:CitationPages>
<!-- For processing the \v parameter. -->
<b:CitationVolume>
<xsl:value-of select="/b:Citation/b:Volume"/>
</b:CitationVolume>
</b:Source>
</xsl:variable>
<xsl:call-template name="format-source">
<xsl:with-param name="format" select="$format"/>
<xsl:with-param name="source" select="msxsl:node-set($extendedSource)/b:Source"/>
<xsl:with-param name="disallowed">
<!-- Do not display the authors of the work. -->
<xsl:if test="/b:Citation/b:NoAuthor">
<xsl:value-of select="msxsl:node-set($data)/citation/noauthor"/>
</xsl:if>
<!-- Do not display the title of the work. -->
<xsl:if test="/b:Citation/b:NoTitle">
<xsl:value-of select="msxsl:node-set($data)/citation/notitle"/>
</xsl:if>
<!-- Do not display the year the work was written or accessed in. -->
<xsl:if test="/b:Citation/b:NoYear">
<xsl:value-of select="msxsl:node-set($data)/citation/noyear"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$params/general/citation_as_link = 'yes'">
<a href="#{/b:Citation/b:Source/b:Tag}">
<xsl:value-of select="$citation" disable-output-escaping="yes"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$citation" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
<!-- end citation -->
<!-- Display the group separator if this is not the last citation. -->
<xsl:if test="not(/b:Citation/b:LastAuthor)">
<xsl:value-of select="$params/citation/separator" disable-output-escaping="yes"/>
</xsl:if>
<!-- Display the close bracket if this is the last citation. -->
<xsl:if test="/b:Citation/b:LastAuthor">
<xsl:value-of select="$params/citation/closebracket" disable-output-escaping="yes"/>
</xsl:if>
</p>
</body>
</html>
</xsl:template>
<!-- Formats the footnote citation. -->
<xsl:template name="format-footnote-citation">
<!-- Generate an XML node-set from the formatting data. -->
<xsl:variable name="params" select="msxsl:node-set($data)"/>
<html xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p class="MsoBibliography">
<!-- Display the open bracket if this is the first citation. -->
<xsl:if test="/b:FootnoteCitation/b:FirstAuthor">
<xsl:value-of select="$params/footnotecitation/openbracket" disable-output-escaping="yes"/>
</xsl:if>
<!-- Not handled: MinAuthors, SameAuthors, RepeatedAuthor. -->
<xsl:variable name="citation">
<!-- Get the format string. -->
<xsl:variable name="format">
<xsl:variable name="type" select="/b:FootnoteCitation/b:Source/b:Type"/>
<xsl:variable name="sourcetype" select="/b:FootnoteCitation/b:Source/b:SourceType"/>
<xsl:choose>
<!-- If there is no source type, its a placeholder. -->
<xsl:when test="string-length($sourcetype) = 0 and string-length(msxsl:node-set($data)/footnotecitation/source[@type = 'Placeholder']/format) > 0">
<xsl:value-of select="msxsl:node-set($data)/footnotecitation/source[@type = 'Placeholder']/format"/>
</xsl:when>
<!-- Go for the type element if available. -->
<xsl:when test="string-length($type) > 0 and string-length(msxsl:node-set($data)/footnotecitation/source[@type = $type]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/footnotecitation/source[@type = $type]/format"/>
</xsl:when>
<!-- Else go for the source type element if available. -->
<xsl:when test="string-length(msxsl:node-set($data)/footnotecitation/source[@type = $sourcetype]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/footnotecitation/source[@type = $sourcetype]/format"/>
</xsl:when>
<!-- Else display error message. -->
<xsl:otherwise>
<xsl:if test="msxsl:node-set($data)/general/display_errors = 'yes'">
<xsl:text><b>Unsupported </xsl:text>
<xsl:if test="string-length($type) > 0">
<xsl:text>type (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>) and </xsl:text>
</xsl:if>
<xsl:text>source type (</xsl:text>
<xsl:value-of select="$sourcetype"/>
<xsl:text>) for source </xsl:text>
<xsl:value-of select="/b:FootnoteCitation/b:Source/b:Tag"/>
<xsl:text>.</b></xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Extend the source. -->
<xsl:variable name="extendedSource">
<b:Source>
<xsl:copy-of select="/b:FootnoteCitation/b:Source/*"/>
<!-- For processing the \f parameter. -->
<b:FootnoteCitationPrefix>
<xsl:value-of select="/b:FootnoteCitation/b:PagePrefix"/>
</b:FootnoteCitationPrefix>
<!-- For processing the \s parameter. -->
<b:FootnoteCitationSuffix>
<xsl:value-of select="/b:FootnoteCitation/b:PageSuffix"/>
</b:FootnoteCitationSuffix>
<!-- For processing the \p parameter. -->
<b:FootnoteCitationPages>
<xsl:value-of select="/b:FootnoteCitation/b:Pages"/>
</b:FootnoteCitationPages>
<!-- For processing the \v parameter. -->
<b:FootnoteCitationVolume>
<xsl:value-of select="/b:FootnoteCitation/b:Volume"/>
</b:FootnoteCitationVolume>
</b:Source>
</xsl:variable>
<xsl:call-template name="format-source">
<xsl:with-param name="format" select="$format"/>
<xsl:with-param name="source" select="msxsl:node-set($extendedSource)/b:Source"/>
<xsl:with-param name="disallowed">
<!-- Do not display the authors of the work. -->
<xsl:if test="/b:FootnoteCitation/b:NoAuthor">
<xsl:value-of select="msxsl:node-set($data)/citation/noauthor"/>
</xsl:if>
<!-- Do not display the title of the work. -->
<xsl:if test="/b:FootnoteCitation/b:NoTitle">
<xsl:value-of select="msxsl:node-set($data)/citation/notitle"/>
</xsl:if>
<!-- Do not display the year the work was written or accessed in. -->
<xsl:if test="/b:FootnoteCitation/b:NoYear">
<xsl:value-of select="msxsl:node-set($data)/citation/noyear"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$citation" disable-output-escaping="yes"/>
<!-- end citation -->
<!-- Display the group separator if this is not the last citation. -->
<xsl:if test="not(/b:FootnoteCitation/b:LastAuthor)">
<xsl:value-of select="$params/citation/separator" disable-output-escaping="yes"/>
</xsl:if>
<!-- Display the close bracket if this is the last citation. -->
<xsl:if test="/b:FootnoteCitation/b:LastAuthor">
<xsl:value-of select="$params/citation/closebracket" disable-output-escaping="yes"/>
</xsl:if>
</p>
</body>
</html>
</xsl:template>
<!-- Formats the bibliography. -->
<xsl:template name="format-bibliography">
<!-- Extends the b:Source elements of the b:Bibliography element with a b:SortKey. -->
<xsl:variable name="extendedBib">
<!-- Create a b:Bibliography element. -->
<b:Bibliography>
<!-- Extend all the b:Source elements with a sortkey. -->
<xsl:for-each select="/b:Bibliography/b:Source">
<b:Source>
<!-- Copy the content of the b:Source. -->
<xsl:copy-of select="./*"/>
<!-- Add a sorting key. -->
<xsl:call-template name="create-sortkey">
<xsl:with-param name="source" select="."/>
</xsl:call-template>
</b:Source>
</xsl:for-each>
<!-- With the exception of the b:Source elements, copy all elements (not really used by the stylesheets). -->
<!--<xsl:for-each select="/b:Bibliography/*">
<xsl:if test="local-name() != 'Source'">
<xsl:element name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:if>
</xsl:for-each>-->
</b:Bibliography>
</xsl:variable>
<html xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
p.MsoBibliography
</style>
</head>
<body>
<xsl:choose>
<!-- If there is more than one column, use a table layout. -->
<xsl:when test="msxsl:node-set($data)/bibliography/columns > 1">
<xsl:call-template name="format-bibliography-as-table">
<xsl:with-param name="bibNodeSet" select="msxsl:node-set($extendedBib)"/>
</xsl:call-template>
</xsl:when>
<!-- Otherwise use a paragraph layout. -->
<xsl:otherwise>
<xsl:call-template name="format-bibliography-as-paragraphs">
<xsl:with-param name="bibNodeSet" select="msxsl:node-set($extendedBib)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>
<!-- Formats a bibliography as a series of paragraphs. -->
<xsl:template name="format-bibliography-as-paragraphs">
<xsl:param name="bibNodeSet"/>
<xsl:for-each select="$bibNodeSet/b:Bibliography/b:Source">
<xsl:sort select="b:SortKey" data-type="text"/>
<p class="MsoBibliography">
<!-- Get the format string. -->
<xsl:variable name="format">
<xsl:variable name="type" select="./b:Type"/>
<xsl:variable name="sourcetype" select="./b:SourceType"/>
<xsl:choose>
<!-- If there is no source type, its a placeholder. -->
<xsl:when test="string-length($sourcetype) = 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = 'Placeholder']/column[@id = '1']/format) > 0">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = 'Placeholder']/column[@id = '1']/format"/>
</xsl:when>
<!-- Go for the type element if available. -->
<xsl:when test="string-length($type) > 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = $type]/column[@id = '1']/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = $type]/column[@id = '1']/format"/>
</xsl:when>
<!-- Else go for the source type element if available. -->
<xsl:when test="string-length(msxsl:node-set($data)/bibliography/source[@type = $sourcetype]/column[@id = '1']/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = $sourcetype]/column[@id = '1']/format"/>
</xsl:when>
<!-- Else display error message. -->
<xsl:otherwise>
<xsl:if test="msxsl:node-set($data)/general/display_errors = 'yes'">
<xsl:text><b>Unsupported </xsl:text>
<xsl:if test="string-length($type) > 0">
<xsl:text>type (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>) and </xsl:text>
</xsl:if>
<xsl:text>source type (</xsl:text>
<xsl:value-of select="$sourcetype"/>
<xsl:text>) for source </xsl:text>
<xsl:value-of select="./b:Tag"/>
<xsl:text>.</b></xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Format the source. -->
<xsl:variable name="paragraphX">
<xsl:call-template name="format-source">
<xsl:with-param name="format" select="$format"/>
<xsl:with-param name="source" select="."/>
</xsl:call-template>
</xsl:variable>
<!-- Convert the formatted source to html. -->
<xsl:choose>
<xsl:when test="msxsl:node-set($data)/general/citation_as_link = 'yes'">
<a name="{./b:Tag}">
<xsl:value-of select="$paragraphX" disable-output-escaping="yes"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$paragraphX" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:for-each>
</xsl:template>
<!-- Formats a bibliography as a table. -->
<xsl:template name="format-bibliography-as-table">
<xsl:param name="bibNodeSet"/>
<!-- Empty paragraph hack for table. -->
<p class="MsoBibliography" style="display:none;">x</p>
<table width="100%">
<xsl:for-each select="$bibNodeSet/b:Bibliography/b:Source">
<xsl:sort select="b:SortKey" data-type="text"/>
<tr>
<xsl:call-template name="format-bibliography-table-column">
<xsl:with-param name="columnId" select="1"/>
<xsl:with-param name="source" select="."/>
</xsl:call-template>
</tr>
</xsl:for-each>
</table>
<!-- Empty paragraph hack for table. -->
<p class="MsoBibliography" style="display:none;">x</p>
</xsl:template>
<!-- Formats a single column in a bibliography. -->
<xsl:template name="format-bibliography-table-column">
<!-- Source to format. -->
<xsl:param name="source"/>
<!-- Id of the column to format. -->
<xsl:param name="columnId"/>
<!-- Generate an XML node-set from the formatting data. -->
<xsl:variable name="params" select="msxsl:node-set($data)"/>
<!-- Get the format string. -->
<xsl:variable name="format">
<xsl:variable name="type" select="./b:Type"/>
<xsl:variable name="sourcetype" select="./b:SourceType"/>
<xsl:choose>
<!-- If there is no source type, its a placeholder. -->
<xsl:when test="string-length($sourcetype) = 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = 'Placeholder']/column[@id = $columnId]/format) > 0">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = 'Placeholder']/column[@id = $columnId]/format"/>
</xsl:when>
<!-- Go for the type element if available. -->
<xsl:when test="string-length($type) > 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = $type]/column[@id = $columnId]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = $type]/column[@id = $columnId]/format"/>
</xsl:when>
<!-- Else go for the source type element if available. -->
<xsl:when test="string-length(msxsl:node-set($data)/bibliography/source[@type = $sourcetype]/column[@id = $columnId]/format) > 0 ">
<xsl:value-of select="msxsl:node-set($data)/bibliography/source[@type = $sourcetype]/column[@id = $columnId]/format"/>
</xsl:when>
<!-- Else display error message. -->
<xsl:otherwise>
<xsl:if test="msxsl:node-set($data)/general/display_errors = 'yes'">
<xsl:text><b>Unsupported </xsl:text>
<xsl:if test="string-length($type) > 0">
<xsl:text>type (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>) and </xsl:text>
</xsl:if>
<xsl:text>source type (</xsl:text>
<xsl:value-of select="$sourcetype"/>
<xsl:text>) for source </xsl:text>
<xsl:value-of select="./b:Tag"/>
<xsl:text>.</b></xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Not really efficient at the moment, but it does the trick so errors can be displayed. -->
<xsl:variable name="type">
<xsl:variable name="temp" select="$source/b:Type"/>
<xsl:variable name="temp2" select="$source/b:SourceType"/>
<xsl:choose>
<xsl:when test="string-length($temp2) = 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = $temp2]/column[@id = $columnId]/format) > 0 ">
<xsl:value-of select="'Placeholder'"/>
</xsl:when>
<xsl:when test="string-length($temp) > 0 and string-length(msxsl:node-set($data)/bibliography/source[@type = $temp]/column[@id = $columnId]/format) > 0 ">
<xsl:value-of select="$temp"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$source/b:SourceType"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td align="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/halign}" valign="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/valign}">
<p class="MsoBibliography">
<xsl:variable name="columnX">
<xsl:call-template name="format-source">
<xsl:with-param name="format" select="$format"/>
<xsl:with-param name="source" select="$source"/>
</xsl:call-template>
</xsl:variable>
<!-- Convert the formatted source to html. -->
<xsl:choose>
<xsl:when test="msxsl:node-set($data)/general/citation_as_link = 'yes' and $columnId = 1">
<a name="{$source/b:Tag}">
<xsl:value-of select="$columnX" disable-output-escaping="yes"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$columnX" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</p>
</td>
<!-- Process remaining columns recursively. -->
<xsl:if test="$params/bibliography/columns > $columnId">
<xsl:call-template name="format-bibliography-table-column">
<xsl:with-param name="source" select="$source"/>
<xsl:with-param name="columnId" select="$columnId + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Preprocesses a format string by adding level information to every marker.
'{' and '}' change into '{level}' and '%' changes into '%level%' where
level is the depth in the format string.
This will allow for faster processing by the formatting templates. -->
<xsl:template name="preprocess-format-string">
<!-- String to process. -->
<xsl:param name="string"/>
<!-- Adds balanced brackets around the entire string to help others. -->
<xsl:text>{0}</xsl:text>
<xsl:call-template name="preprocess-format-string-part-2">
<xsl:with-param name="string" select="$string"/>
</xsl:call-template>
<!-- Adds balanced brackets around the entire string to help others. -->
<xsl:text>{0}</xsl:text>
</xsl:template>
<!-- Recursively called helper function for the preprocess-format-string template. -->
<xsl:template name="preprocess-format-string-part-2">
<!-- Remaining string. -->
<xsl:param name="string"/>
<!-- Current level. -->
<xsl:param name="level" select="0"/>
<xsl:if test="string-length($string) > 0">
<!-- Get the first character of the remaining string. -->
<xsl:variable name="firstChar" select="substring($string, 1, 1)"/>
<xsl:choose>
<!-- A new level is reached. -->
<xsl:when test="$firstChar = '{'">
<!-- Calculate the next level. -->
<xsl:variable name="nextLevel" select="$level + 1"/>
<!-- Display a conditional processing marker. -->
<xsl:text>{</xsl:text>
<xsl:value-of select="$nextLevel"/>
<xsl:text>}</xsl:text>
<!-- Recursively process the rest of the string. -->
<xsl:call-template name="preprocess-format-string-part-2">
<xsl:with-param name="string" select="substring($string, 2)"/>
<xsl:with-param name="level" select="$nextLevel"/>
</xsl:call-template>
</xsl:when>
<!-- The current level is finished. -->
<xsl:when test="$firstChar = '}'">
<!-- Display a conditional processing marker. -->
<xsl:text>{</xsl:text>
<xsl:value-of select="$level"/>
<xsl:text>}</xsl:text>
<!-- Recursively process the rest of the string. -->
<xsl:call-template name="preprocess-format-string-part-2">
<xsl:with-param name="string" select="substring($string, 2)"/>
<xsl:with-param name="level" select="$level - 1"/>
</xsl:call-template>
</xsl:when>
<!-- A variable at the current level starts. -->
<xsl:when test="$firstChar = '%'">
<!-- Display a variable processing marker (start of variable). -->
<xsl:text>%</xsl:text>
<xsl:value-of select="$level"/>
<xsl:text>%</xsl:text>
<!-- Display the variable (no use in parsing character by character).-->
<xsl:value-of select="substring-before(substring($string, 2), '%')"/>
<!-- Display a variable processing marker (end of variable). -->
<xsl:text>%</xsl:text>
<xsl:value-of select="$level"/>
<xsl:text>%</xsl:text>
<!-- Recursively process the rest of the string. -->
<xsl:call-template name="preprocess-format-string-part-2">
<xsl:with-param name="string" select="substring-after(substring($string, 2), '%')"/>
<xsl:with-param name="level" select="$level"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- Display the first character -->
<xsl:value-of select="$firstChar"/>
<!-- Recursively process the rest of the string. -->
<xsl:call-template name="preprocess-format-string-part-2">
<xsl:with-param name="string" select="substring($string, 2)"/>
<xsl:with-param name="level" select="$level"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- Formats a b:Source element. -->
<xsl:template name="format-source">
<!-- The b:Source element to format. -->
<xsl:param name="source"/>
<!-- The format in which to display the b:Source element. -->
<xsl:param name="format"/>
<!-- b:Source child elements which can not be used (-name1-name2).-->
<xsl:param name="disallowed"/>
<xsl:call-template name="clean-punctuation">
<xsl:with-param name="string">
<xsl:call-template name="format-source-part-2">
<xsl:with-param name="source" select="$source"/>
<xsl:with-param name="format">
<xsl:call-template name="preprocess-format-string">
<xsl:with-param name="string" select="$format"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="used" select="$disallowed"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- Helper function for format-source. This function recursively
resolves the highest level of the first conditional branch of
the format string. It will return the entire string with at
least one less conditional branch.
-->
<xsl:template name="format-source-part-2">
<!-- The b:Source element to format. -->
<xsl:param name="source"/>
<!-- The preprocessed format in which to display the b:Source element. -->
<xsl:param name="format"/>
<!-- b:Source child elements which can not be used (-name1-name2-).-->
<xsl:param name="used"/>
<xsl:choose>
<!-- Check if there is still conditional processing to do. -->
<xsl:when test="contains($format, '{')">
<!-- Get the first level to process. -->
<xsl:variable name="level" select="substring-before(substring-after($format, '{'), '}')"/>
<!-- Retrieve the delimeters of the level to process. -->
<xsl:variable name="delim" select="concat('{', $level,'}')"/>
<xsl:variable name="current">
<xsl:call-template name="format-source-part-3">
<!-- The current source. -->
<xsl:with-param name="source" select="$source"/>
<!-- Retrieve the part that has to be processed during this run. -->
<xsl:with-param name="format" select="substring-before(substring-after($format, $delim), $delim)"/>
<!-- List of variables which can no longer be used. -->
<xsl:with-param name="used" select="$used"/>
<!-- Level of variables to process during this run. -->
<xsl:with-param name="level" select="$level"/>
</xsl:call-template>
</xsl:variable>
<!-- Part before the part that was processed in this run. -->
<xsl:value-of select="substring-before($format, $delim)"/>
<!-- Recursively process the entire string. -->
<xsl:call-template name="format-source-part-2">
<!-- The same old source. -->
<xsl:with-param name="source" select="$source"/>
<!-- The format string of which one condition is removed. -->
<xsl:with-param name="format">
<!-- Result of the part processed in this run. As it can still contain
lower level conditional formatting, it has to be reprocessed. -->
<xsl:value-of select="msxsl:node-set($current)/output"/>
<!-- Part after the part that was processed in this run. -->
<xsl:value-of select="substring-after(substring-after($format, $delim), $delim)"/>
</xsl:with-param>
<!-- Updated used containing now also the variables used in this run. -->
<xsl:with-param name="used" select="concat($used, msxsl:node-set($current)/used)"/>
</xsl:call-template>
</xsl:when>
<!-- Otherwise, print the entire leftover string. -->
<xsl:otherwise>
<xsl:value-of select="$format"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>