-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathahelp_main.xsl
1182 lines (1026 loc) · 39.7 KB
/
ahelp_main.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>
<!--*
* AHELP XML to HTML convertor using XSL Transformations
*
* These are the routines that actually transfrom the ahelp document
* - broken out of ahelp.xsl to make it easier to test
*-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:func="http://exslt.org/functions"
xmlns:exsl="http://exslt.org/common"
xmlns:extfuncs="http://hea-www.harvard.edu/~dburke/xsl/extfuncs"
extension-element-prefixes="date str func exsl extfuncs">
<!--* Change this if the filename changes *-->
<xsl:variable name="hack-import-ahelp_main" select="extfuncs:register-import-dependency('ahelp_main.xsl')"/>
<!--* load in templates *-->
<xsl:include href="ahelp_common.xsl"/>
<!--* parameters to be set by stylesheet processor *-->
<xsl:param name="headtitlepostfix" select='""'/>
<xsl:param name="texttitlepostfix" select='""'/>
<xsl:param name="dname"/>
<xsl:param name="urlbase"/>
<!--*
* create: $outname.html
* We now no-longer need to use the xsl:document trick
* as we only create a single file now, but leave that
* change for later as it requires re-jigging the entire
* publishing setup, not just this stylesheet.
*-->
<xsl:template match="cxchelptopics">
<xsl:variable name="filename"><xsl:value-of select="$outdir"/><xsl:value-of select="$outname"/>.html</xsl:variable>
<xsl:variable name="title">Ahelp: <xsl:value-of select="ENTRY/@key"/> - <xsl:value-of select="$headtitlepostfix"/></xsl:variable>
<!--* output filename to stdout *-->
<xsl:value-of select="$filename"/><xsl:call-template name="newline"/>
<!--* create document *-->
<xsl:document href="{$filename}" method="html" media-type="text/html"
doctype-system="about:legacy-compat"
version="5.0">
<html lang="en-US">
<head>
<!-- Since libxslt adds in a http-equiv line with the charset -->
<!-- <meta charset="UTF-8"/> -->
<title><xsl:value-of select="$title"/></title>
<link rel="canonical" href="{$url}"/>
<!--* use CSS for the navbar *-->
<link rel="stylesheet" title="Default stylesheet for CIAO-related pages" href="{$cssfile}"/>
<link rel="stylesheet" title="Default stylesheet for CIAO-related pages" media="print" href="{$cssprintfile}"/>
<style>
/* highlight only the link to this page in the navbar */
.navbar a[href='<xsl:value-of select="$outname"/>.html'] {
background: #CCCCCC;
}
</style>
<xsl:call-template name="add-sao-metadata">
<xsl:with-param name="title" select="normalize-space($title)"/>
</xsl:call-template>
</head>
<xsl:call-template name="add-body-withnavbar">
<xsl:with-param name="contents">
<xsl:apply-templates select="ENTRY"/>
</xsl:with-param>
<xsl:with-param name="navbar">
<xsl:call-template name="add-navbar">
<xsl:with-param name="navbar" select="'ahelp_index'"/>
</xsl:call-template>
</xsl:with-param>
<!-- TODO: do we want to make this optional? -->
<xsl:with-param name="breadcrumbs" select="true()"/>
<xsl:with-param name="location" select="$filename"/>
<xsl:with-param name="ldepth" select="'2'"/>
</xsl:call-template>
</html>
</xsl:document>
</xsl:template> <!--* match=cxchelptopics *-->
<!--* begin DTD templates *-->
<!--*
* we use a pull-style approach here
*
* DTD Entry:
* <!ELEMENT ENTRY (SYNOPSIS?, SYNTAX?, ADDRESS*, DESC?,
* QEXAMPLELIST?, PARAMLIST?, ADESC*,BUGS?,
* VERSION?, LASTMODIFIED? )>
*
* If PARAMLIST is included and no initial SYNTAX block then
* we generate the syntax line automatically
*
*-->
<xsl:template match="ENTRY">
<xsl:call-template name="add-ahelp-qlinks"/>
<xsl:call-template name="add-page-header"/>
<br/>
<xsl:apply-templates select="SYNOPSIS"/>
<!--*
* SYNTAX handling is a bit complicated in CIAO 3.0
*-->
<xsl:call-template name="handle-entry-syntax"/>
<xsl:apply-templates select="DESC"/>
<xsl:apply-templates select="QEXAMPLELIST"/>
<xsl:apply-templates select="PARAMLIST"/>
<!-- if there are any ADESC blocks then add a separator,
but not between each ADESC block -->
<xsl:if test="count(ADESC) > 0"><hr class="midsep"/></xsl:if>
<xsl:apply-templates select="ADESC"/>
<xsl:if test="$site='ciao'">
<xsl:call-template name="add-relnotes"/>
</xsl:if>
<xsl:apply-templates select="BUGS"/>
<xsl:call-template name="add-seealso"/>
</xsl:template> <!--* match=ENTRY *-->
<!--*
* output another page "header"
*
*-->
<xsl:template name="add-page-header">
<div class="ahelpheader">
<div class="firstcol"><strong>AHELP for <xsl:value-of select="$headtitlepostfix"/></strong></div>
<div class="centercol"><h1 class="ahelp"><xsl:value-of select="@key"/></h1></div>
<div class="lastcol">
Context: <a title="Jump to context list of Ahelp pages"
href="{$depth}index_context.html#{@context}"><xsl:value-of select="@context"/></a>
</div>
</div>
</xsl:template> <!--* name=add-page-header *-->
<!--*
* DTD Entry:
* <!ELEMENT SYNOPSIS (#PCDATA)>
*
* Note:
* . if parent = ENTRY then this is at the top of the page
* so we don't really need an anchor, but let's include one
* anyway
*
* . if parent = PARAM then just wrap in an em block
*
*-->
<xsl:template match="ENTRY/SYNOPSIS">
<h2 id="synopsis">Synopsis</h2>
<p>
<xsl:apply-templates/>
</p>
</xsl:template> <!--* match=ENTRY/SYNOPSIS *-->
<xsl:template match="PARAM/SYNOPSIS" mode="plist">
<p class="ahelpsynopsis">
<em><xsl:apply-templates/></em>
</p>
</xsl:template> <!--* match=PARAM/SYNOPSIS *-->
<xsl:template match="PARAM/SYNOPSIS">
<xsl:message terminate="yes">
Programming error:
For some reason the stylesheet is trying to process the
PARAM/SYNOPSIS node directly (not in mode=plist)
</xsl:message>
</xsl:template>
<!--*
* handle the SYNTAX block at the start of the file
* - in CIAO 3.0 we complicated things by allowing
* the SYNTAX block to be automatically created
* from the PARAMLIST section if it wasn't present.
* WE SHOULD HAVE USED AN ATTRIBUTE ON THE SYNTAX BLOCK TO
* INDICATE THIS
*-->
<xsl:template name="handle-entry-syntax">
<xsl:choose>
<xsl:when test="boolean(SYNTAX)">
<xsl:apply-templates select="SYNTAX"/>
</xsl:when>
<xsl:when test="$nparam != 0">
<xsl:call-template name="create-entry-syntax"/>
</xsl:when>
</xsl:choose>
</xsl:template> <!--* name=handle-entry-syntax *-->
<!--*
* DTD Entry:
* <!ELEMENT SYNTAX (LINE*)>
*
* We ignore any SYNTAX block which contains 1 empty LINE
*
* We handle separately the case of auto-creation of the ENTRY/SYNTAX block
* from the PARAMLIST - see the create-entry-syntax template
*
* Since a SYNTAX block can be within a PARA block we need to
* handle this awkward case (by hacking in start/end para tags).
* To try and avoid artifacts we have a in-para parameter which
* - if set to 1 by the PARA template - causes us to end/start the
* p block
*
*-->
<xsl:template match="SYNTAX">
<xsl:param name="in-para" select="0"/>
<xsl:if test="
not( count(LINE)=1 and normalize-space(LINE[1])='' )
">
<xsl:if test="$in-para = 1">
<!--* UGLY - must be cleaner ways around this *-->
<xsl:call-template name="end-para"/>
</xsl:if>
<div class="ahelpsyntax">
<xsl:if test="parent::ENTRY">
<h2 id="syntax">Syntax</h2>
</xsl:if>
<xsl:call-template name="ahelp-add-highlight">
<xsl:with-param name="contents"><xsl:apply-templates/></xsl:with-param>
</xsl:call-template>
</div> <!--* class=ahelpsyntax *-->
<xsl:if test="$in-para = 1">
<!--* UGLY - must be cleaner ways around this *-->
<xsl:call-template name="start-para"/>
</xsl:if>
</xsl:if>
</xsl:template> <!--* match=SYNTAX *-->
<!--*
* DTD Entry:
* <!ELEMENT LINE (#PCDATA | HREF)* >
*
* Processing this node is complicated since we have to
* strip out whitespace and split the line every $maxlen
* characters (set by XSLT processor)
*
* *** NOTE: ***
*
* we currently don't handle HREF nodes within LINE ones
* - since it makes the normalising rather painful
* - but we do throw a wobbly if it occurs
*
* - we ignore the node if it is empty AND:
* - the first one
* - the last one
*
*-->
<xsl:template match="LINE">
<!--* we don't handle HREF children since it complicates things *-->
<xsl:if test="count(HREF) != 0">
<xsl:message terminate="no">
Warning: have come across at least one HREF node (first has text =
'<xsl:value-of select="HREF[1]"/>')
within a LINE node in document key=<xsl:value-of select="/cxchelptopics/ENTRY/@key"/> context=<xsl:value-of select="/cxchelptopics/ENTRY/@context"/>
Output WILL BE WRONG
</xsl:message>
</xsl:if>
<xsl:variable name="text" select="normalize-space(.)"/>
<xsl:if test="
not( $text='' and ( position()=1 or position()=last() ) )
"><xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template></xsl:if>
</xsl:template> <!--* match=LINE *-->
<!--*
* return - as one line - the command-line generated from the PARAMLIST section
* - could try and make this clever enough to work within maxlen chars and
* to add indentation
*
* Note: in the move to libxml2.6.x from 2.5.x, this routine broke because
* missing attributes no longer default to a value of ''. This means that
* the check @reqd != 'yes' does not succeed if reqd is not present.
*
*-->
<xsl:template name="create-syntax-from-paramlist">
<xsl:value-of select="//ENTRY/@key"/><xsl:text> </xsl:text>
<xsl:for-each select="PARAMLIST/PARAM">
<xsl:if test="position() != 1"><xsl:text> </xsl:text></xsl:if>
<xsl:choose>
<xsl:when test="@reqd = 'yes'"><xsl:value-of select="@name"/></xsl:when>
<xsl:otherwise>[<xsl:value-of select="@name"/>]</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template> <!--* name=create-syntax-from-paramlist *-->
<!--*
* We need to create the SYNTAX section from the PARAMLIST section
* Note: we don't match ahelp's format (which is better)
* of indenting lines after the first one
*-->
<xsl:template name="create-entry-syntax">
<div class="ahelpsyntax">
<h2 id="syntax">Syntax</h2>
<xsl:call-template name="ahelp-add-highlight">
<xsl:with-param name="contents"><xsl:call-template name="normalize-line-node">
<xsl:with-param name="text"><xsl:call-template name="create-syntax-from-paramlist"/></xsl:with-param>
</xsl:call-template></xsl:with-param>
</xsl:call-template>
</div> <!--* class=ahelpsyntax *-->
</xsl:template> <!--* name=create-entry-syntax *-->
<!--*
* Given a piece of string, output the first $maxlen characters
* (or as near as we can make it) without breaking a word
* - breaks within strings are allowed.
*
* A recursive template
*
* Parameters:
* text - string, required
* the string to split up
* currpos - integer
* the current position in the string (defaults to 1)
* lastpos - integer
* the position of the last space (defaults to 0)
*
* nlines - integer
* number of lines created - should only be set by itself
* [used to determine whether to output a new line before the string]
* defaults to 1
*-->
<xsl:template name="normalize-line-node">
<xsl:param name="text" select="''"/>
<xsl:param name="currpos" select="1"/>
<xsl:param name="lastpos" select="0"/>
<xsl:param name="nlines" select="1"/>
<xsl:variable name="slen" select="string-length($text)"/>
<xsl:choose>
<!--*
* stop if there's nothing left: may get a range error on substring calling this case!
* - actually, if nlines = 1 then we have a blank input line, which we want to
* allow [start/end blank lines have been filtered by the SYNTAX templates
*-->
<xsl:when test="$slen = 0">
<xsl:if test="$nlines = 1"><xsl:text>
</xsl:text></xsl:if>
</xsl:when>
<!--*
* if currpos >= length of string we can stop
* (do we need the new-line before it?, we seem to)
*-->
<xsl:when test="$currpos >= $slen">
<xsl:text>
</xsl:text><xsl:value-of select="$text"/>
</xsl:when>
<!--*
* if we've encountered a space, use up to that, otherwise use
* the first $maxlen characters. We repeat again.
*
* Note that, to stop the pre blocks extending over too wide an
* area (at least in konqueror) we do not want to end the line on
* a space. So, that's why we have 2 slightly different
* bits of code. And then add a third to account for the case
* when the $maxlen character is the first space...
*
*-->
<xsl:when test="$currpos = $maxlen">
<xsl:choose>
<xsl:when test="substring($text,$maxlen,1) = ' '">
<!--* the $maxlen character is actually a space *-->
<xsl:text>
</xsl:text><xsl:value-of select="substring($text,1,$maxlen - 1)"/>
<xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="substring($text,$maxlen + 1)"/>
<xsl:with-param name="nlines" select="$nlines + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lastpos = 0">
<!--* there is no space, so use the first $maxlen characters *-->
<xsl:text>
</xsl:text><xsl:value-of select="substring($text,1,$maxlen)"/>
<xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="substring($text,$maxlen + 1)"/>
<xsl:with-param name="nlines" select="$nlines + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!--* use the position of the last space *-->
<xsl:text>
</xsl:text><xsl:value-of select="substring($text,1,$lastpos - 1)"/>
<xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="substring($text,$lastpos + 1)"/>
<xsl:with-param name="nlines" select="$nlines + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($text,$currpos,1) = ' '">
<!--* found a space, so update and repeat the recursion *-->
<xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="lastpos" select="$currpos"/>
<xsl:with-param name="currpos" select="$currpos + 1"/>
<xsl:with-param name="nlines" select="$nlines"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!--*
* no space, update and repeat the recursion
* - different from the space case above (lastpos is not
* updated in this case)
*-->
<xsl:call-template name="normalize-line-node">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="lastpos" select="$lastpos"/>
<xsl:with-param name="currpos" select="$currpos + 1"/>
<xsl:with-param name="nlines" select="$nlines"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* name=normalize-line-node *-->
<!--*
* DTD Entry:
* <!ELEMENT HREF (#PCDATA)>
* <!ATTLIST HREF
* link NMTOKENS #IMPLIED
* >
*
* perhaps we need to rationalise the stylesheet...
*
* We hack the URL and text to convert asc.harvard.edu to cxc.harvard.edu
*
*-->
<!--* HREF block in a PARA element *-->
<xsl:template match="HREF">
<!--* ugh: replace should be done as a function... *-->
<a><xsl:attribute name="href"><xsl:call-template name="hack-href">
<xsl:with-param name="input" select="@link"/>
</xsl:call-template></xsl:attribute><xsl:call-template name="hack-href">
<xsl:with-param name="input" select="normalize-space(string(.))"/>
</xsl:call-template></a>
</xsl:template>
<!--*
* hack a href (or the link contents) to change to the 'new' scheme:
* asc.harvard.edu -> cxc.harvard.edu
* documents_ahelp.html -> ahelp/
* documents_threads.html -> threads/
* documents_manuals.html -> manuals.html
*
* advanced_documents.html -> manuals.html
* http://hea-www.harvard.edu/APEC/ -> http://cxc.harvard.edu/atomdb/
*
* should be done as a function rather than a template
*-->
<xsl:template name="hack-href">
<xsl:param name="input" select="''"/>
<xsl:value-of select="
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace( $input, 'asc.harvard.edu', 'cxc.harvard.edu' ),
'http://hea-www.harvard.edu/APEC/', 'http://cxc.harvard.edu/atomdb/' ),
'documents_ahelp.html', 'ahelp/' ),
'documents_threads.html', 'threads/' ),
'documents_manuals.html', 'manuals.html' ),
'advanced_documents.html', 'manuals.html' )
"/>
</xsl:template> <!--* name=hack-href *-->
<!--*
* DTD Entry:
* <!ELEMENT DESC ((PARA | TABLE | LIST | VERBATIM)*)>
*
* DESC can be a child of ENTRY, PARAM, QEXAMPLE
*
*-->
<xsl:template match="ENTRY/DESC">
<h2 id="description">Description</h2>
<xsl:apply-templates/>
</xsl:template> <!-- match=ENTRY/DESC -->
<xsl:template match="QEXAMPLE/DESC">
<xsl:apply-templates/>
</xsl:template>
<!--* don't do anything unless we're in a special mode *-->
<xsl:template match="PARAM/DESC"/>
<xsl:template match="PARAM/DESC" mode="plist">
<xsl:apply-templates/>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT PARA (#PCDATA | SYNTAX | EQUATION | PASSTHRU
* | XMLONLY | HREF)*>
* <!ATTLIST PARA
* title NMTOKENS #IMPLIED
* >
*
* - add an anchor equal to the anchor (with spaces turned
* into underscores)
*
* We trap the cases of a PARA block containing only a single
* SYNTAX or EQUATION block [should try and catch multiple
* copies as well]
*
* The in-para parameters are only of interest to the SYNTAX
* and EQUATION templates
*-->
<xsl:template match="PARA">
<xsl:choose>
<xsl:when test="count(node()) = 1 and ( name(node()) = 'SYNTAX' or name(node()) = 'EQUATION' )">
<xsl:apply-templates>
<xsl:with-param name="in-para" select="0"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<!--* normal processing *-->
<xsl:if test="boolean(@title)">
<xsl:call-template name="add-title-anchor">
<xsl:with-param name="title" select="@title"/>
</xsl:call-template>
</xsl:if>
<p>
<xsl:apply-templates>
<xsl:with-param name="in-para" select="1"/>
</xsl:apply-templates>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!--* match=PARA *-->
<!--*
* DTD Entry:
* <!ELEMENT EQUATION (#PCDATA | PASSTHRU|XMLONLY)*>
*
* This can only appear within PARA blocks, which means we have
* to jump through a few hoops
*
* I also want consecutive EQUATION blocks to look nice (ie combine
* them), which really complicate things. In fact, I am not convinced
* it is possible. I was hoping to use the preceding-sibling/following-sibling
* axes to see when the set of EQUATION commands starts and ends, but
* it appears that the text nodes in between are not included in this list
* This means I do not know how to reliably determine the start/end
* point of the sets (in particular if there are multiple EQUATION
* blocks, separated by text, within a single PARA block)
*
*-->
<xsl:template match="EQUATION">
<xsl:param name="in-para" select="0"/>
<xsl:if test="$in-para = 1">
<xsl:call-template name="end-para"/>
</xsl:if>
<div class="ahelpequation">
<xsl:call-template name="ahelp-add-highlight">
<xsl:with-param name="contents" select="normalize-space(.)"/>
</xsl:call-template>
</div>
<xsl:if test="$in-para = 1">
<xsl:call-template name="start-para"/>
</xsl:if>
</xsl:template> <!--* match=EQUATION *-->
<!--*
* DTD Entry:
* <!ELEMENT XMLONLY (#PCDATA)>
*
* we process the XMLONLY block since this is for
* XML text!
*
*-->
<xsl:template match="XMLONLY">
<!--* just to flag any instances *-->
<xsl:message terminate="no">
Note: have encountered an XMLONLY block
</xsl:message>
<xsl:value-of select="."/>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT PASSTHRU (#PCDATA) >
*
* we skip the PASSTHRU block since this is for LaTeX-only
* text
*
*-->
<xsl:template match="PASSTHRU"/>
<!--*
* DTD Entry:
* <!ELEMENT TABLE ( CAPTION?, ROW*)>
*
* For CIAO 3.0 changed to have a border of 1 - previously had border = 0
* and added frame="void". Should be done by CSS.
*
* Note: the 'hidden' rule is that the first row of the
* table is taken to be a header row, even there is no
* mark up to suggest this (and it is not always required)
* We follow this 'rule' here.
* Also, if all rows of a column EXCEPT the first are empty
* then we do not display that column.
*-->
<xsl:template match="TABLE">
<!-- true if the column contains data after the first row, false otherwise -->
<xsl:variable name="colflags">
<xsl:for-each select="ROW[1]/DATA">
<xsl:variable name="pos" select="position()"/>
<flag><xsl:value-of select="count(../../ROW[position()!=1]/DATA[position()=$pos and . != ''])!=0"/></flag>
</xsl:for-each>
</xsl:variable>
<!--*
* There is the possibility of an empty table, but more likely one
* with only one row, which we would then consider as empty.
*-->
<xsl:if test="count(exsl:node-set($colflags)/flag[.='true']) = 0">
<xsl:message terminate="yes">
Found a TABLE that is either empty or only contains 1 row!
</xsl:message>
</xsl:if>
<xsl:apply-templates select="CAPTION"/>
<table class="ciaotable">
<xsl:apply-templates select="ROW">
<xsl:with-param name="colflags" select="exsl:node-set($colflags)"/>
</xsl:apply-templates>
</table>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT CAPTION (#PCDATA)>
*
* The size of the caption depends on wheter this is within a
* PARAM block or not (h5 if it is, h4 otherwise)
*
*-->
<xsl:template match="CAPTION">
<xsl:variable name="type"><xsl:choose>
<xsl:when test="ancestor::PARAM">h5</xsl:when>
<xsl:otherwise>h4</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:element name="{$type}"><xsl:apply-templates/></xsl:element>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT ROW (DATA*)>
*
* If this is the first row then we make it a header row
* through some chicanery. We also use a pull approach so that
* we can select which columns to process, given the
* colflags input (a set of <flag>true/false</flag> values,
* one for each column in the header). Note that there could be more or less
* columns than in the header, which we warn about.
*
* I am sure there are far-more elegant methods than the this.
*-->
<xsl:template match="ROW">
<xsl:param name="colflags"/>
<xsl:variable name="expected_ncols" select="count($colflags/flag)"/>
<xsl:variable name="found_ncols" select="count(DATA)"/>
<!--* only warn once per file *-->
<xsl:if test="$found_ncols != $expected_ncols">
<xsl:message>
<xsl:value-of select="concat('WARNING: ROW contains ',$found_ncols,
' DATA elements but expected to find ',$expected_ncols,' of them ',
'(key=',//ENTRY/@key,' context=',//ENTRY/@context,' table caption=',../CAPTION,')')"/>
</xsl:message>
</xsl:if>
<tr>
<xsl:choose>
<xsl:when test="position() = 1">
<xsl:attribute name="class">headerrow</xsl:attribute>
<xsl:for-each select="DATA">
<xsl:variable name="pos" select="position()"/>
<xsl:if test="$colflags/flag[$pos]='true'">
<xsl:apply-templates mode="headerrow" select="."/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="DATA">
<xsl:variable name="pos" select="position()"/>
<xsl:if test="$colflags/flag[$pos]='true'">
<xsl:apply-templates select="."/>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT DATA (#PCDATA)>
*
* since we do not have borders around these tables we
* do not have to ensure that empty cells contain some
* printable text (ie == unicode  ) unlike
* the parameter tables
*
* There really should be something in the mark-up to
* indicate a header element rather than this hack
*-->
<xsl:template match="DATA">
<td><xsl:apply-templates/></td>
</xsl:template>
<xsl:template match="DATA" mode="headerrow">
<th><xsl:apply-templates/></th>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT LIST ( CAPTION?, ITEM* )>
*
*-->
<xsl:template match="LIST">
<xsl:apply-templates select="CAPTION"/>
<ul>
<xsl:apply-templates select="ITEM"/>
</ul>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT ITEM (#PCDATA)>
*
* should we add <p>/</p> around the contents?
*-->
<xsl:template match="ITEM">
<li><xsl:apply-templates/></li>
</xsl:template>
<!--*
* DTD Entry:
* <!ELEMENT VERBATIM (#PCDATA)>
*
* Unlike EQUATION this can not appear within a PARA
*-->
<xsl:template match="VERBATIM">
<div class="ahelpverbatim">
<xsl:call-template name="ahelp-add-highlight">
<xsl:with-param name="contents"><xsl:apply-templates/></xsl:with-param>
</xsl:call-template>
</div>
</xsl:template>
<!--*
* process the examples section
*
* DTD Entry:
* <!ELEMENT QEXAMPLELIST (QEXAMPLE)*>
* <!ELEMENT QEXAMPLE (SYNTAX?, DESC?)>
*
* as with PARAMLIST we do not complain about an empty list
*
* There is a labelling issue here, since we need an anchor
* to jump too for "the start of the examples", and anchors
* for individual examples, but then what do we do when there
* is only one example (and so we don't really want to have
* title=Examples then title=Example 1)
*
* One solution is to remove the anchors for individual examples,
* since they are "fragile" (no guarantee that they'll stay the
* same, but I may have written links to them). I have gone for
* this approach at the moment.
*-->
<xsl:template match="QEXAMPLELIST">
<hr class="midsep"/>
<!-- Oh great, for some reason the stylesheet styles h2 and h3 to have
the same size! -->
<h2 id="examples">Example<xsl:if test="$nexample > 1">s</xsl:if></h2>
<!--* we number each example *-->
<xsl:for-each select="QEXAMPLE">
<!--* anchor rules are slightly different to add-title-anchor template *-->
<!--
<h2 id="example{position()}"><xsl:choose>
<xsl:when test="$nexample=1">Example</xsl:when>
<xsl:otherwise>Example <xsl:value-of select="position()"/></xsl:otherwise>
</xsl:choose></h2>
-->
<xsl:if test="$nexample>1">
<h3>Example <xsl:value-of select="position()"/></h3>
</xsl:if>
<xsl:apply-templates select="SYNTAX"/>
<xsl:apply-templates select="DESC"/>
</xsl:for-each>
</xsl:template> <!--* QEXAMPLELIST *-->
<!--*
* process the parameters section
*
* DTD Entry:
* <!ELEMENT PARAMLIST (PARAM*)>
* <!ELEMENT PARAM ( SYNOPSIS?, DESC? )>
*
* Processing is complicated:
* create the table of parameters
* then the individual list of parameters
*
* note: makes use of the 'global' have-XXX variables defined above
*
*-->
<xsl:template match="PARAMLIST">
<!--* if the paramlist is empty then let it be empty *-->
<hr class="midsep"/>
<h2 id="ptable">Parameters</h2>
<table class="ciaotable">
<thead>
<tr>
<th>name</th> <th>type</th>
<xsl:if test="$have-ftype"><th>ftype</th></xsl:if>
<xsl:if test="$have-def"><th>def</th></xsl:if>
<xsl:if test="$have-min"><th>min</th></xsl:if>
<xsl:if test="$have-max"><th>max</th></xsl:if>
<xsl:if test="$have-units"><th>units</th></xsl:if>
<xsl:if test="$have-reqd"><th>reqd</th></xsl:if>
<xsl:if test="$have-stcks"><th>stacks</th></xsl:if>
<xsl:if test="$have-aname"><th>autoname</th></xsl:if>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="PARAM" mode="ptable"/>
</tbody>
</table>
<br/>
<h2 id="plist">Detailed Parameter Descriptions</h2>
<xsl:apply-templates select="PARAM" mode="plist"/>
</xsl:template> <!--* PARAMLIST *-->
<!--*
* list the parameters as a table
* we add in an to ensure that empty cells
* end up with some content, and so will be
* displayed by netscape.
*
* for almost all columns we only output data if the corresponding
* $have-<name> variable is true
*-->
<xsl:template match="PARAM" mode="ptable">
<tr>
<!--* name - always included *-->
<td><a title="Jump to parameter description" href="#plist.{@name}"><xsl:value-of select="@name"/></a></td>
<!--* type - always included *-->
<xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@type"/></xsl:call-template>
<!--* ftype *-->
<xsl:if test="$have-ftype"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@filetype"/></xsl:call-template></xsl:if>
<!--* def *-->
<xsl:if test="$have-def"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@def"/></xsl:call-template></xsl:if>
<!--* min *-->
<xsl:if test="$have-min"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@min"/></xsl:call-template></xsl:if>
<!--* max *-->
<xsl:if test="$have-max"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@max"/></xsl:call-template></xsl:if>
<!--* units *-->
<xsl:if test="$have-units"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@units"/></xsl:call-template></xsl:if>
<!--* reqd *-->
<xsl:if test="$have-reqd"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@reqd"/></xsl:call-template></xsl:if>
<!--* stacks *-->
<xsl:if test="$have-stcks"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@stacks"/></xsl:call-template></xsl:if>
<!--* autoname *-->
<xsl:if test="$have-aname"><xsl:call-template name="add-param-to-table"><xsl:with-param name="value" select="@autoname"/></xsl:call-template></xsl:if>
</tr>
</xsl:template> <!--* match=PARAM mode=ptable *-->
<!--*
* Parameters:
* value - string
*
* Value of the string to display in the table. Outputs
* if $value is empty/undefined
*-->
<xsl:template name="add-param-to-table">
<xsl:param name="value" select="''"/>
<td>
<xsl:choose>
<xsl:when test="not($value) or $value = ''"><xsl:call-template name="add-nbsp"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
</xsl:choose>
</td>
</xsl:template> <!--* name=add-param-to-table *-->
<!--* show the parameters in a list *-->
<xsl:template match="PARAM" mode="plist">
<!--* follow the parameter name with a list of attributes *-->
<h4 id="plist.{@name}">Parameter=<xsl:value-of select="@name"/>
<span class='plist'><xsl:text> (</xsl:text><xsl:value-of select="@type"/>
<xsl:if test="boolean(@reqd)"><xsl:text> </xsl:text><xsl:choose>
<xsl:when test="@reqd='yes'">required</xsl:when>
<xsl:when test="@reqd='no'">not required</xsl:when>
</xsl:choose></xsl:if>
<xsl:if test="boolean(@filetype)"><xsl:text> </xsl:text>filetype=<xsl:value-of select="@filetype"/></xsl:if>
<xsl:if test="boolean(@def)"><xsl:text> </xsl:text>default=<xsl:value-of select="@def"/></xsl:if>
<xsl:if test="boolean(@min)"><xsl:text> </xsl:text>min=<xsl:value-of select="@min"/></xsl:if>
<xsl:if test="boolean(@max)"><xsl:text> </xsl:text>max=<xsl:value-of select="@max"/></xsl:if>
<xsl:if test="boolean(@units)"><xsl:text> </xsl:text>units=<xsl:value-of select="@units"/></xsl:if>
<xsl:if test="boolean(@stacks)"><xsl:text> </xsl:text>stacks=<xsl:value-of select="@stacks"/></xsl:if>
<xsl:if test="boolean(@autoname)"><xsl:text> </xsl:text>autoname=<xsl:value-of select="@autoname"/></xsl:if>
<xsl:text>)</xsl:text></span></h4>
<!--* perhaps we shouldn't do a select here - ie just process everything? *-->
<xsl:apply-templates select="SYNOPSIS|DESC" mode="plist"/>
<!--* <br/> *-->
</xsl:template> <!--* PARAM mode=plist *-->
<!--*
* DTD Entry:
* <!ELEMENT ADESC (PARA|TABLE|LIST|VERBATIM)*>
* <!ATTLIST ADESC
* title NMTOKENS #IMPLIED
* >
*
*-->
<xsl:template match="ADESC">
<xsl:if test="boolean(@title)">