-
Notifications
You must be signed in to change notification settings - Fork 2
/
myhtml.xsl
1858 lines (1656 loc) · 64 KB
/
myhtml.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" ?>
<!DOCTYPE xsl:stylesheet>
<!--*
* support for xHTML-like tags
* - link tags/support can be found in links.xsl
*
* Note there's some pretty ugly use of XSLT here.
* Some of this can be removed once we use CSS (since handling
* the style info can be done by that)
*
*-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:func="http://exslt.org/functions"
xmlns:djb="http://hea-www.harvard.edu/~dburke/xsl/"
xmlns:extfuncs="http://hea-www.harvard.edu/~dburke/xsl/extfuncs"
extension-element-prefixes="exsl func djb extfuncs">
<!--* Change this if the filename changes *-->
<xsl:variable name="hack-import-myhtml" select="extfuncs:register-import-dependency('myhtml.xsl')"/>
<!--*
* unwanted HTML tags
*-->
<!--* i to em *-->
<xsl:template match="i|I">
<xsl:message terminate="yes">
Please convert all <<xsl:value-of select="name()"/>> tags to <em>
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template>
<!--* b to strong *-->
<xsl:template match="b|B">
<xsl:message terminate="yes">
Please convert all <<xsl:value-of select="name()"/>> tags to <strong>
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template>
<!--* uppercase tags *-->
<xsl:template match="CAPTION|CENTER|DIV|HR|P|SUB|SUP|TABLE|TR|TD|IMG">
<xsl:message terminate="yes">
Please convert <<xsl:value-of select="name()"/>> tags to lowercase
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template> <!--* UPPERCASE tags *-->
<!--*
* trying to remove the use of these templates, but it is not fully possible
*-->
<xsl:template name="start-tag">
<xsl:text disable-output-escaping="yes"><</xsl:text>
</xsl:template>
<xsl:template name="end-tag">
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:template>
<xsl:template name="add-quote">
<xsl:text disable-output-escaping="yes">"</xsl:text>
</xsl:template>
<!--*
* for some reason I used to want the output to contain
* rather than   - I believe that I saw differences with
* certain browsers. I have just tried netscape4.76s and it
* deals with   correctly. So I am changing to use the
* code point for the nbsp rather than the entity (or whatever
* the terminology is)
*
<xsl:template name="add-nbsp">
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</xsl:template>
*
*-->
<xsl:template name="add-nbsp"> </xsl:template>
<!--*
* Parameters:
* contents, node set, required
* this is the processed content of the link
*
* processes the following attributes of the context node:
* em, tt, strong
* in that order
*
*-->
<xsl:template name="add-text-styles">
<xsl:param name="contents" select="''"/>
<!--*
* removed this check since it is better done in the context
* of the parent node (I could not easily see how to handle
* cases like <cxclink href='...'><img src='...'/></cxclink>
* here, whereas you can in the cxclink tag
*
<xsl:if test="$contents = '' and count($contents) = 0">
<xsl:message terminate="yes">
ERROR: add-text-styles called with contents=""
context node=<xsl:value-of select="name()"/>
</xsl:message>
</xsl:if>
*
*-->
<!--*
* loop through the recognised attributes
* (it strikes me there may be a better way of doing this)
*-->
<xsl:call-template name="add-text-styles-em">
<xsl:with-param name="contents" select="$contents"/>
</xsl:call-template>
</xsl:template> <!--* add-text-styles *-->
<xsl:template name="add-text-styles-em">
<xsl:param name="contents" select="''"/>
<xsl:choose>
<xsl:when test="@em=1">
<em>
<xsl:call-template name="add-text-styles-tt">
<xsl:with-param name="contents" select="$contents"/>
</xsl:call-template>
</em>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="add-text-styles-tt">
<xsl:with-param name="contents" select="$contents"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* add-text-styles-em *-->
<xsl:template name="add-text-styles-tt">
<xsl:param name="contents" select="''"/>
<xsl:choose>
<xsl:when test="@tt=1">
<span class="tt">
<xsl:call-template name="add-text-styles-strong">
<xsl:with-param name="contents" select="$contents"/>
</xsl:call-template>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="add-text-styles-strong">
<xsl:with-param name="contents" select="$contents"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* add-text-styles-tt *-->
<xsl:template name="add-text-styles-strong">
<xsl:param name="contents" select="''"/>
<xsl:choose>
<xsl:when test="@strong=1">
<strong>
<xsl:copy-of select="$contents"/>
</strong>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$contents"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* add-text-styles-strong *-->
<!--*
* lists:
* we allow ul and ol (type=A, a, I, i, or 1)
* and introduce <list> with an
* attribute of type (undef => ul, otherwise ol type A, a, or 1)
*
* Since we don't have a DTD we explicitly look for non li tags (other
* than empty text nodes) within it [unless in a threadindex],
* and if we are within a p block (which, as of CIAO 3.1, is a fatal
* error)
*
*-->
<xsl:template match="list">
<!--* should be in DTD *-->
<xsl:if test="boolean(ancestor::p)">
<xsl:message terminate="yes">
ERROR: this document contains a list element within a p block,
which is not allowed
</xsl:message>
</xsl:if>
<xsl:if test="name(//*) != 'threadindex' and
(count(child::*[name()!='li']) != 0 or count(text()[normalize-space(.)!='']) != 0)">
<xsl:message terminate="yes">
ERROR: this document contains a list element that contains tags other than li
(or text other than whitespace),
which is not allowed
</xsl:message>
</xsl:if>
<!--* this could be cleverer *-->
<xsl:choose>
<xsl:when test="string(@type)='A' or string(@type)='a' or
string(@type)='I' or string(@type)='i' or
string(@type)='1'">
<ol type="{@type}">
<xsl:apply-templates/>
</ol>
</xsl:when>
<xsl:when test="boolean(@type)">
<xsl:message terminate="yes">
ERROR list tag with unknown type='<xsl:value-of select="@type"/>'
</xsl:message>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* list *-->
<xsl:template match="li">
<li>
<xsl:apply-templates/>
</li>
</xsl:template> <!--* li *-->
<!--* do not allow ul, use list instead *-->
<xsl:template match="ul|UL">
<xsl:message terminate="yes">
Please convert all <<xsl:value-of select="name()"/>> tags to list (no type attribute)
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template> <!--* ul|UL *-->
<!--* do not allow ol, use list instead *-->
<xsl:template match="ol|OL">
<xsl:message terminate="yes">
Please convert all <<xsl:value-of select="name()"/>> tags to list
<xsl:choose>
<xsl:when test="boolean(@type)">
- use the attribute type="<xsl:value-of select="@type"/>" for this tag
</xsl:when>
<xsl:otherwise>
- add add the attribute type="1" or type="A" for this tag
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template> <!--* ol *-->
<!--*
* add a "new" icon
* - see also the updated template
* - uses the "package" variable depth to work
* out where the image actually is
* - if the day attribute is supplied also adds in the date
* using (29 June 2002) format where
* day=29 month=June year=2
* actual output format depends on where the tag is being
* used: thread index => big, bold
* otherwise => small
*-->
<xsl:template match="new">
<xsl:call-template name="add-image">
<xsl:with-param name="src" select="'imgs/new.gif'"/>
<xsl:with-param name="alt" select="'New'"/>
</xsl:call-template>
<xsl:if test="boolean(@day)"><xsl:call-template name="add-date"/></xsl:if>
</xsl:template>
<!--*
* add an "updated" icon
* - see the new template for usage/comments
*-->
<xsl:template match="updated">
<xsl:call-template name="add-image">
<xsl:with-param name="src" select="'imgs/updated.gif'"/>
<xsl:with-param name="alt" select="'Updated'"/>
</xsl:call-template>
<xsl:if test="boolean(@day)"><xsl:call-template name="add-date"/></xsl:if>
</xsl:template>
<!--*
* add the supplied date within brackets, at a font size of -1
* It uses the day, month, and year attributes of the context node.
* @day and @month are printed out as-is whereas @year is:
* if @year < 2000, add 2000 to it
* if @year >= 2000, leave as is
*
* This introduces a "year 4000" problem, but does allow legacy doucments
* to work, plus I'd be really worried if this code was still being used
* in the year 4000 *;)
*
* actual output format depends on where the tag is being used:
* thread index => big, bold
* otherwise => small
* - I'm beginning to think that the 'smarts' built into this
* routine should be removed - i.e. make the template that calls
* this one do the extra work (since it knows the context).
* Have separated out the logic so that we can do this better
* (added the calculate-date-from-attributes template, which I think
* should be in helper.xsl but leave in here for now)
*-->
<xsl:template name="calculate-date-from-attributes">
<xsl:variable name="year"><xsl:choose>
<xsl:when test="@year >= 2000"><xsl:value-of select="@year"/></xsl:when>
<xsl:otherwise><xsl:value-of select="2000+@year"/></xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:value-of select="concat(@day,' ',substring(@month,1,3),' ',$year)"/>
</xsl:template> <!--* name=calculate-date-from-attributes *-->
<xsl:template name="add-date">
<xsl:variable name="text"><xsl:call-template name="calculate-date-from-attributes"/></xsl:variable>
<!--* add a spacer *-->
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="name(//*)='threadindex'">(<strong><xsl:value-of select="$text"/></strong>)</xsl:when>
<xsl:otherwise><span class="date">(<xsl:value-of select="$text"/>)</span></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--*
* handle p tags: we have to handle possible text attributes
* which are a not-well-thought-out system for associating
* styles/short-cuts to some block elements.
*
* This IS a mess - would be much easier with CSS!
*
* also want to allow align attribute to be copied over
*
*-->
<xsl:template match="p">
<xsl:variable name="contents"><xsl:apply-templates/></xsl:variable>
<p>
<xsl:if test="boolean(@align)"><xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute></xsl:if>
<xsl:if test="boolean(@class)"><xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute></xsl:if>
<xsl:if test="boolean(@id)"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
<xsl:if test="boolean(@style)"><xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute></xsl:if>
<xsl:choose>
<xsl:when test="@text='header'"><span class="pheader"><xsl:copy-of select="$contents"/></span></xsl:when>
<xsl:when test="@text='note'"><span class="qlinkbar"><xsl:copy-of select="$contents"/></span></xsl:when>
<xsl:otherwise><xsl:copy-of select="$contents"/></xsl:otherwise>
</xsl:choose>
</p>
</xsl:template> <!--* match=p *-->
<!--*
* allow img tags:
*-->
<xsl:template match="img">
<xsl:if test="boolean(@src)=false()">
<xsl:message terminate="yes">
Error: img tags must have a src attribute
</xsl:message>
</xsl:if>
<xsl:if test="boolean(@alt)=false()">
<xsl:message terminate="yes">
Error: img tags must have an alt attribute
</xsl:message>
</xsl:if>
<xsl:copy-of select="."/>
</xsl:template> <!--* img *-->
<!--*
* handle screen tags
*
* they either have an attribute of file,
* which means load the text from @file.xml,
* or use their content.
*
*-->
<xsl:template name="add-highlight">
<xsl:param name="contents" select="''"/>
<xsl:param name="language" select="'none'"/>
<!--* yay CSS (although highlight is a poor class name)
*
* So, we have an issue here with the processed text here
* - if there's no processing then we can just copy over
* the text and things like '& <foo>xx</foo>' will
* get converted.
* - if styling is added (i.e. language is not 'none') then
* we need to disable the output escaping, since we want
* tags to be tags (and hope that the actual text will
* have been converted correctly, which it should be...)
*-->
<pre class="highlight"><xsl:choose>
<xsl:when test="$language='none'"><xsl:copy-of select="$contents"/></xsl:when>
<xsl:otherwise><xsl:value-of
select="extfuncs:add-language-styles($language, $contents)"
disable-output-escaping="yes"/></xsl:otherwise>
</xsl:choose></pre>
</xsl:template> <!--* name=add-highlight *-->
<!--*
* The optional attribute wrap is used to select
* the text-wrapping behavior. By default it does not
* wrap (wrap="no") but it can be changed to wrap by setting
* wrap="yes".
*
* Added support for the lang tag. This is used to
* set up the pygmentize call.
*-->
<xsl:template match="screen">
<!--* a check since we've changed name to file *-->
<xsl:if test="boolean(@name)">
<xsl:message terminate="yes">
Error:
a screen tag has been found with a name attribute
(with value '<xsl:value-of select="@name"/>')
-- name must be changed to file
</xsl:message>
</xsl:if>
<!--*
* process the contents of the screen tag into the
* variable contents, which we then send to the
* add-highlight template
*-->
<xsl:variable name="contents"><xsl:choose>
<xsl:when test='. != ""'>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test='boolean(@file)'>
<xsl:apply-templates
select="document(concat($sourcedir,@file,'.xml'))" mode="include"/>
</xsl:when>
</xsl:choose></xsl:variable>
<!-- when @lang is used we add both 'screen' and 'screen-<lang>',
perhaps we should just use the latter but it would mean
more work with the stylesheets? -->
<xsl:variable name="classes"><xsl:choose>
<xsl:when test="boolean(@wrap) and @wrap='yes'">screenwrap</xsl:when>
<xsl:when test="(boolean(@wrap) and @wrap='no') or not(boolean(@wrap))">screen<xsl:if test="boolean(@lang)"> screen-<xsl:value-of select="@lang"/></xsl:if></xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ERROR: invaling wrap attribute in screen tag: wrap=<xsl:value-of select="@wrap"/>
</xsl:message>
</xsl:otherwise></xsl:choose></xsl:variable>
<!-- what is the language -->
<xsl:variable name="language"><xsl:choose>
<xsl:when test="boolean(@lang)"><xsl:value-of select="@lang"/></xsl:when>
<xsl:otherwise>none</xsl:otherwise>
</xsl:choose></xsl:variable>
<div class="{$classes}">
<xsl:call-template name="add-highlight">
<xsl:with-param name="contents" select="$contents"/>
<xsl:with-param name="language" select="$language"/>
</xsl:call-template>
</div>
<!--* <br/> *-->
</xsl:template> <!--* screen *-->
<!--*
* add highlighting around the contents of the
* contents parameter (which can be a node-list)
*
* need to think about what we want highlighting
* - ie how we handle the non-pre-block cases
* - at the moment should be able to place in a
* div (since the old version put them into a table)
*
* NOTE:
* div structure/class names are rather chaotic at the moment
*
*-->
<xsl:template name="add-highlight-pre">
<xsl:param name="contents" select="''"/>
<!--* yay CSS (although highlight is a poor class name) *-->
<pre class="highlight"><xsl:copy-of select="$contents"/></pre>
</xsl:template> <!--* name=add-highlight-pre *-->
<xsl:template name="add-highlight-block">
<xsl:param name="contents" select="''"/>
<!--* yay CSS (although highlighttext is a poor class name) *-->
<div class="highlighttext">
<xsl:copy-of select="$contents"/>
</div>
</xsl:template> <!--* name=add-highlight-block *-->
<!--*
* handle pre blocks
*
* we augment them with a "highlight=1 or 0" attribute. If set to 1
* then we create the text with a grey background
* - need more user-control
*
*-->
<xsl:template match="pre">
<!--* safety check *-->
<xsl:if test="ancestor::p">
<xsl:message terminate="yes">
ERROR: you have a pre block within a p block. This is not allowed.
contents of pre block=
<xsl:apply-templates/>
</xsl:message>
</xsl:if>
<!--* ugly *-->
<xsl:choose>
<xsl:when test="boolean(@highlight) and @highlight='1'">
<xsl:call-template name="add-highlight-pre">
<xsl:with-param name="contents"><xsl:apply-templates/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<pre>
<!-- manually copy over the attributes; ugly that special casing this node -->
<xsl:copy-of select="@*" />
<xsl:apply-templates/>
</pre>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* pre *-->
<!--*
* handle highlight 'blocks'
*
* currently we just wrap the contents in a table
* and set the background. A hack.
*
*-->
<xsl:template match="highlight">
<!--* safety check *-->
<xsl:if test="ancestor::p">
<xsl:message terminate="yes">
ERROR: you have a highlight block within a p block. This is not allowed.
contents of highlight block=
<xsl:apply-templates/>
</xsl:message>
</xsl:if>
<xsl:call-template name="add-highlight-block">
<xsl:with-param name="contents"><xsl:apply-templates/></xsl:with-param>
</xsl:call-template>
</xsl:template> <!--* match=highlight *-->
<!--*
* convert center tags to div ones
* - should we include a warning?
*-->
<xsl:template match="center">
<xsl:message terminate="yes">
Please convert all <center> tags to use CSS.
<xsl:call-template name="newline"/>
</xsl:message>
</xsl:template> <!--* match=center *-->
<!--*
* Support math tags:
*
* *) "equation"
*
* <math>
* <name>...</name>
* <latex>...</latex> (latex formula with NO being/end math values)
* <text>...</text> (plain text representation;
* if not given then we re-use the latex block)
* { <mathml>...</mathml> (MathML version) NOT YET IMPLEMENTED }
* </math>
*
* *) "inline"
*
* <inlinemath>...</inlinemath>
* - at the moment the contents are assumed to be LaTeX format
*
* If $use-mathjax = 1:
* use the MathJax javascript system - http://www.mathjax.org/ -
* for rendering LaTeX, rather than calling out to LaTeX to create
* an image (although this may be required to support users who
* have JavaScript turned off).
* otherwise:
* PNG files are created by the publishing code
*
* Notes:
* - may want to add attributes that are used to control the created formula
*
*-->
<xsl:template match="math">
<!--* DTD-style checks *-->
<xsl:if test="boolean(name)=false() and boolean(latex)=false()">
<xsl:message terminate="yes">
Error: math tag is missing at least one of name or latex
<xsl:value-of select="."/>
</xsl:message>
</xsl:if>
<!--* don't allow in p blocks *-->
<xsl:if test="ancestor::p">
<xsl:message terminate="yes">
Error: a math tag is within a p block. This is
not allowed - try a div node if you need
centering/some control.
</xsl:message>
</xsl:if>
<!-- remove spaces from the name; should really clean up other characters
as it is being used as an id (and possibly a file name) -->
<xsl:variable name="mathname" select="translate(name, ' ', '')"/>
<xsl:choose>
<xsl:when test="$use-mathjax = 1">
<!--*
* We used to (MathJax 2) have a separate preview section but I am
* removing this for now.
*
* TODO: worried about < being converted to <, as seen in the example
* thread (possibly some oddities in how expansion happens, since libXSLT
* seems to have expanded it in x<y but not x < y ...
* Unfortunately, if stick in CDATA then it gets interpreted by the script
* tag. From simple tests it doesn't seem to be a problem.
*
* I did try changing the script to just being a div, adding \[ and \]
* around the value-of select, to turn on the LaTeX support in MathJax,
* but then it did not hide the MathJax_Preview section, so have
* decided to leave this as is for now.
*-->
<xsl:choose>
<xsl:when test="$mathname = ''">
<span class="MathJax-span">\[
<xsl:value-of select="latex"/>
\]</span>
</xsl:when>
<xsl:otherwise>
<span id="{$mathname}" class="MathJax-span">\[
<xsl:value-of select="latex"/>
\]</span>
</xsl:otherwise>
</xsl:choose>
<!--
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:value-of select="latex"/>
<xsl:text disable-output-escaping="yes">]]</xsl:text>
<xsl:text disable-output-escaping="yes">></xsl:text>
-->
</xsl:when>
<xsl:otherwise>
<!--*
* create the latex document
* - could allow the fg/bg colors to be set with attributes
* - apparently xsl:document will nest
* - need to remove leading/trailing whitespace so that
* latex doesn't complain
*-->
<xsl:document href="{concat($sourcedir,$mathname,'.tex')}" method="text">
\documentclass{article}
\usepackage{color}
\pagestyle{empty}
\pagecolor{white}
\begin{document}
\begin{eqnarray*}
{\color{black}
<xsl:value-of select="normalize-space(latex)"/>
}
\end{eqnarray*}
\end{document}
</xsl:document>
<img id="{$mathname}" src="{$mathname}.png"><xsl:attribute name="alt"><xsl:choose>
<xsl:when test="boolean(text)"><xsl:value-of select="text"/></xsl:when>
<xsl:otherwise><xsl:value-of select="normalize-space(latex)"/></xsl:otherwise>
</xsl:choose></xsl:attribute></img>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* match=math *-->
<!-- There is no attempt to expand the contents; they are just passed straight through -->
<xsl:template match="inlinemath">
<xsl:value-of select="concat('\(', ., '\)')"/>
</xsl:template> <!--* match=inlinemath *-->
<!--*
* create a SSI statement in the output file
* that gives the last-modified date of the file
*
* the tag contents are the name of the file
*
* Parameters:
* NONE
*
*-->
<xsl:template match="flastmod">
<xsl:comment>#flastmod file="<xsl:value-of select="."/>"</xsl:comment>
</xsl:template> <!--* match=flastmod *-->
<!--*
* to indicate when a bit of text is associated with a bug:
* this is a stop-gap measure until we come up with proper
* markup for bugs
*
* It ignores the contents (which are assumed to be the bug number)
*-->
<xsl:template match="bugnum"/>
<!-- strip out the intro tag -->
<xsl:template match="intro">
<xsl:apply-templates/>
</xsl:template>
<!--*
* from Chris Stawarz's download-script code
* - mangled since we now have to interpret all
* the tags that Chris was able to use
*
* The styleing for this now uses CSS grids to layout the
* sections.
*-->
<xsl:template match="scriptlist">
<!-- make the navigation links -->
<div style="text-align: center;">
<p>
<xsl:for-each select="category">
<a href="{concat('#',translate(@name,' ',''))}"><xsl:value-of select="@name"/></a>
<xsl:if test="position() != last()"><xsl:text> | </xsl:text></xsl:if>
</xsl:for-each> <!-- select="category" -->
</p>
</div>
<xsl:for-each select="category">
<h3 class="scriptsection"
id="{translate(@name,' ','')}"><xsl:value-of select="@name"/></h3>
<xsl:if test="boolean(intro)">
<div class="scriptintro">
<xsl:apply-templates select="intro"/>
</div>
</xsl:if>
<xsl:for-each select="script">
<xsl:variable name="classname">scriptitem<xsl:choose>
<xsl:when test="thread">3</xsl:when>
<xsl:otherwise>2</xsl:otherwise>
</xsl:choose></xsl:variable>
<div class="{$classname}">
<div class="scriptname"><strong><xsl:apply-templates select="name" mode="scripts"/></strong></div>
<div class="scriptinfo"><xsl:apply-templates select="desc" mode="scripts"/></div>
<xsl:if test="thread">
<div class="scriptthread">
<xsl:text>Thread: </xsl:text> <xsl:apply-templates select="thread" mode="scripts"/>
</div>
</xsl:if>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:template> <!-- match=scriptlist -->
<xsl:template match="name|desc|thread" mode="scripts">
<xsl:apply-templates/>
</xsl:template> <!-- match=name|desc|thread mode=scripts -->
<xsl:template name="get-month">
<xsl:param name="month"/>
<xsl:choose>
<xsl:when test="$month = '1'">Jan</xsl:when>
<xsl:when test="$month = '2'">Feb</xsl:when>
<xsl:when test="$month = '3'">Mar</xsl:when>
<xsl:when test="$month = '4'">Apr</xsl:when>
<xsl:when test="$month = '5'">May</xsl:when>
<xsl:when test="$month = '6'">Jun</xsl:when>
<xsl:when test="$month = '7'">Jul</xsl:when>
<xsl:when test="$month = '8'">Aug</xsl:when>
<xsl:when test="$month = '9'">Sep</xsl:when>
<xsl:when test="$month = '10'">Oct</xsl:when>
<xsl:when test="$month = '11'">Nov</xsl:when>
<xsl:when test="$month = '12'">Dec</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ERROR: unable to understand month value of <xsl:value-of select="$month"/>
for script=<xsl:value-of select="@name"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!-- name="get-month" -->
<!-- * Docbook-like admonitions; rather than have separate tags use a single
* tag and use an attribute to determine the type of admonition.
*
* Valid values for @type are
* caution important note tip warning
* or the type attribute can be left out.
*
* I had originally followed the docbook style sheet and used
* the background-image CSS attribute on the div.*-inner block
* to set the icon. However, this is likely ignored by the
* media print (browser option), so explicitly adding the
* image.
*-->
<xsl:variable name="allowed-annotations" select="' caution important note tip warning '"/>
<xsl:template match="admonition[@type]">
<xsl:if test="not(contains($allowed-annotations, concat(' ', @type, ' ')))">
<xsl:message terminate="yes">
ERROR: admonition found with unsupported type=<xsl:value-of select="@type"/>
allowed values: <xsl:value-of select="$allowed-annotations" />
</xsl:message>
</xsl:if>
<div>
<xsl:attribute name="class">admonition <xsl:value-of select="@type"/></xsl:attribute>
<div>
<xsl:attribute name="class"><xsl:value-of select="concat(@type, '-inner')"/></xsl:attribute>
<xsl:call-template name="add-admonition-image"/>
<!-- Title handling should be cleaned up -->
<xsl:choose>
<xsl:when test="boolean(title)">
<xsl:apply-templates select="title" mode="admonition"/>
</xsl:when>
<xsl:otherwise>
<div class="title">
<span class="title">
<xsl:choose>
<xsl:when test="@type='caution'">Caution</xsl:when>
<xsl:when test="@type='important'">Important</xsl:when>
<xsl:when test="@type='note'">Note</xsl:when>
<xsl:when test="@type='tip'">Tip</xsl:when>
<xsl:when test="@type='warning'">Warning</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
Internal error: unexpected type=<xsl:value-of select="@type"/> when processing
admonition block with no title.
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</span>
</div>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="*[name()!='title']"/>
</div>
</div>
</xsl:template> <!-- match=admonition/@type -->
<xsl:template match="admonition">
<div class="admonition">
<xsl:apply-templates select="title" mode="admonition"/>
<xsl:apply-templates select="*[name()!='title']"/>
</div>
</xsl:template> <!-- match=admonition -->
<xsl:template match="title" mode="admonition">
<div class="title">
<span class="title"><xsl:apply-templates/></span>
</div>
</xsl:template> <!-- match=title mode=admonition -->
<!--* Add an an image tag for the admonition -->
<xsl:template name="add-admonition-image">
<xsl:if test="boolean(@type)">
<!--*
* TODO: do we want to add a class to this?
*-->
<xsl:call-template name="add-image">
<xsl:with-param name="src" select="concat('imgs/', @type,'.png')"/>
<xsl:with-param name="alt" select="translate(@type, 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:call-template>
</xsl:if>
</xsl:template> <!-- name=add-admonition-image -->
<!--*
* The figure environment, moved from threads.
*
* Since there is no support for auto-generating a table-of-contents
* for the general-purpose pages, the TOC code is left in thread_common.xsl.
*-->
<!--*
* Handle figlink tags.
* - no contents -> use "Figure <num>" (even if have @nonumber tag)
* - contents and no @nonumber attribute -> append " (Figure <num>)"
* - otherwise -> contents
*
* Actually, only include the figure number for threads, even if
* the @nonumber tag is not given.
*
* NOTE:
* check on empty contents as normalize-space(.)='' is not ideal
* but should work (would probably only fail if we used an empty tag like
* <figlink><foo/></figlink> which is unlikely to happen)
*-->
<xsl:template match="figlink[boolean(@id)=false]">
<xsl:message terminate="yes">
ERROR: figlink tag found with no id attribute
contents=<xsl:value-of select="."/>
</xsl:message>
</xsl:template>
<xsl:template match="figlink[(boolean(@nonumber) or name(//*) != 'thread') and normalize-space(.)!='']">
<xsl:call-template name="check-fig-id-exists">
<xsl:with-param name="id" select="@id"/>
</xsl:call-template>
<a href="{concat('#',@id)}"><xsl:apply-templates/></a>
</xsl:template>
<xsl:template match="figlink[normalize-space(.)='']">
<xsl:call-template name="check-fig-id-exists">
<xsl:with-param name="id" select="@id"/>
</xsl:call-template>
<xsl:if test="name(//*) != 'thread'">
<xsl:message terminate="yes">
ERROR: figlink element can not be empty in a non-thread page.
</xsl:message>
</xsl:if>
<xsl:variable name="pos" select="djb:get-figure-number(@id)"/>
<a href="{concat('#',@id)}"><xsl:value-of select="concat('Figure ',$pos)"/></a>
</xsl:template>
<xsl:template match="figlink">
<xsl:call-template name="check-fig-id-exists">
<xsl:with-param name="id" select="@id"/>
</xsl:call-template>
<xsl:variable name="pos" select="djb:get-figure-number(@id)"/>
<a href="{concat('#',@id)}"><xsl:apply-templates/><xsl:value-of select="concat(' (Figure ',$pos,')')"/></a>
</xsl:template>
<!--*
* This is called when processing figlink tags.
*-->
<xsl:template name="check-fig-id-exists">
<xsl:param name="id" select="''"/>
<xsl:if test="$id = ''">
<xsl:message terminate="yes">
ERROR: check-fig-id-exists called with an empty id argument.
</xsl:message>
</xsl:if>
<xsl:variable name="nmatches" select="count(//figure[@id=$id])"/>
<xsl:choose>
<xsl:when test="$nmatches=1"/>
<xsl:when test="$nmatches=0">
<xsl:message terminate="yes">
ERROR: there is no figure with an id of '<xsl:value-of select="$id"/>'.
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ERROR: there are multiple (<xsl:value-of select="$nmatches"/>) figures with an id of '<xsl:value-of select="$id"/>'.
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* name=check-fig-id-exists *-->
<!--*
* helper routine to get the number of the figure.
* TODO: this only really works for single-page
* documents, like the thread environment where it
* originated, and not multi-page ones like
* dictionaries
*-->
<func:function name="djb:get-figure-number">
<xsl:param name="id" select="''"/>
<xsl:if test="$id=''">
<xsl:message terminate="yes">
ERROR: djb:get-figure-number called with no argument
</xsl:message>
</xsl:if>
<func:result><xsl:value-of select="exsl:node-set($figlist)/figure[@id=$id]/@pos"/></func:result>
</func:function>
<!--* This is used to map from @id to figure number *-->
<xsl:variable name="figlist">
<xsl:for-each select="//figure">
<figure id="{@id}" pos="{position()}"/>
</xsl:for-each>
</xsl:variable>