This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv3dt-v3pub.xsl
executable file
·2169 lines (1979 loc) · 69.7 KB
/
v3dt-v3pub.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" ?>
<!-- $Id: v3dt-v3pub.xsl,v 1.29.2.3 2005/06/10 12:30:18 gschadow Exp $ -->
<!-- XSL Style sheet, DTD omitted -->
<!DOCTYPE xsl:stylesheet [
<!ENTITY sect "§">
<!ENTITY nbsp " ">
<!ENTITY alpha "α">
<!ENTITY beta "β">
<!ENTITY mu "μ">
<!ENTITY pi "π">
<!ENTITY Pi "Π">
<!ENTITY rho "ρ">
<!ENTITY epsilon "ε">
<!ENTITY Omega "Ω">
<!ENTITY egrave "è">
<!ENTITY eacute "é">
<!ENTITY ouml "ö">
<!ENTITY Aring "Å">
<!ENTITY deg "°">
<!ENTITY box "□">
<!ENTITY middot "·">
<!ENTITY mult "×">
<!ENTITY nbsp " ">
<!ENTITY ndash "–">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY lquo "‘">
<!ENTITY rquo "’">
<!ENTITY langle "‹">
<!ENTITY rangle "›">
<!ENTITY sim "~">
<!ENTITY ssim "≈">
<!ENTITY bullet "•">
<!ENTITY element "∈">
<!ENTITY cap "∩">
<!ENTITY cup "∪">
<!ENTITY emptyset "{}"> <!-- ∅ -->
<!ENTITY % v3pub-locations SYSTEM 'v3pub-locations.ent'>
%v3pub-locations;
<!ENTITY schema 'W3C XML Schema'>
]>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:hl7v3dtMapping='urn::hl7v3dtMapping'
xmlns:hl7="urn:hl7.org"
xmlns:u="http://aurora.regenstrief.org/UCUM"
xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon"
exclude-result-prefixes="xsd hl7 hl7v3dtMapping saxon u"
version='2.0'>
<xsl:import href="xml-verbatim.xsl"/>
<xsl:import href="v3dt-schema.xsl"/>
<xsl:output
method='xml'
indent='no'
encoding='utf-8'/>
<!--
doctype-public='-//W3C//XML specification DTD//EN'/ -->
<xsl:strip-space elements="*"/>
<!-- As always, begin with the identity transform. -->
<xsl:template match="/|@*|node()">
<xsl:param name='stack' select='/..'/>
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name='stack' select='$stack'/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- I MAY NOT NEED THIS ANY LONGER!
Probably an error in saxon-6.5, but I get one funny text node
a constructed table body (for comp summary CS). Text blocks
don't have anything to do in tbodies anyway. -->
<xsl:template match="tbody">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
</xsl:copy>
</xsl:template>
<!-- NON-EXCITING STUFF -->
<xsl:template match='dtimplname'>
<emph>
<xsl:value-of select='ancestor::dtimpl[1]/@shortname'/>
<xsl:apply-templates/>
</emph>
</xsl:template>
<xsl:template match='dtname'>
<emph>
<xsl:value-of select='ancestor::dt[1]/@shortname'/>
<xsl:apply-templates/>
</emph>
</xsl:template>
<xsl:template match='dtimplref' name='makedtimplref'>
<xsl:param name='ref' select='@ref'/>
<xsl:variable name="target" select="//dtimpl[@id=$ref]"/>
<xsl:choose>
<xsl:when test="self::dtimplref/node()">
<termref ref='{$ref}'>
<xsl:apply-templates select='node()'/>
</termref>
</xsl:when>
<xsl:when test="$target/@shortname">
<termref ref='{$ref}'>
<xsl:value-of select="$target/@shortname"/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<WARNING text="Undefined reference" to="{$ref}"
in="{local-name(.)}"/>
</xsl:message>
<xsl:value-of select="$ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match='dtref' name='makedtref'>
<xsl:param name='ref' select='@ref'/>
<xsl:variable name="target" select="//dt[@id=$ref]"/>
<xsl:choose>
<xsl:when test="self::dtref/node()">
<termref ref='{$ref}'>
<xsl:apply-templates select='node()'/>
</termref>
</xsl:when>
<xsl:when test="$target/@shortname">
<termref ref='{$ref}'>
<xsl:value-of select="$target/@shortname"/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<WARNING text="Undefined reference" to="{$ref}"
in="{local-name(.)}"/>
</xsl:message>
<xsl:value-of select="$ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='dtimplRefByName'>
<xsl:param name='name' select='/..'/>
<xsl:param name='ref'
select="//schema[@id=concat('schema-',$name)]/
ancestor::dtimpl[1]/@id"/>
<xsl:choose>
<xsl:when test='$ref'>
<termref ref="{$ref}">
<xsl:value-of select='$name'/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$name'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='DtimplRefByName'>
<xsl:param name='name' select='/..'/>
<xsl:param name='ref'
select="//schema[@id=concat('schema-',$name)]/
ancestor::dt[1]/@id"/>
<xsl:choose>
<xsl:when test='$ref'>
<termref ref="{$ref}">
<xsl:value-of select='$name'/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$name'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='dtRefByName'>
<xsl:param name='name' select='/..'/>
<xsl:param name='ref'
select="//dt[@id=concat('dt-',$name)]/@id"/>
<xsl:choose>
<xsl:when test='$ref'>
<termref ref="{$ref}">
<xsl:value-of select='$name'/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$name'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='DtRefByName'>
<xsl:param name='name' select='/..'/>
<xsl:param name='ref'
select="//dt[@id=concat('dt-',$name)]/@id"/>
<xsl:choose>
<xsl:when test='$ref'>
<termref ref="{$ref}">
<xsl:value-of select='$name'/>
</termref>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$name'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match='compref'>
<xsl:param name='deref' select='//comp[@id=current()/@ref]'/>
<termref ref='{@ref}'>
<xsl:value-of select='$deref/ancestor::dtimpl[1]/@shortname'/>
<xsl:text>.</xsl:text>
<xsl:value-of select='$deref/@shortname'/>
</termref>
</xsl:template>
<xsl:template match='propref'>
<xsl:param name='deref' select='//prop[@id=current()/@ref]'/>
<xsl:variable name="theprop">
<xsl:apply-templates mode="inherit" select="$deref"/>
</xsl:variable>
<termref ref='{@ref}'>
<xsl:value-of select='$deref/ancestor::dt[1]/@shortname'/>
<xsl:text>.</xsl:text>
<xsl:value-of select='$theprop/prop/@shortname'/>
</termref>
</xsl:template>
<xsl:template match='compname'>
<emph>
<xsl:value-of select='ancestor::comp[1]/@shortname'/>
<xsl:apply-templates/>
</emph>
</xsl:template>
<xsl:template match='propname'>
<xsl:variable name="theprop">
<xsl:apply-templates mode="inherit" select="ancestor::prop[1]"/>
</xsl:variable>
<emph>
<xsl:value-of select='$theprop/*/@shortname'/>
<xsl:apply-templates/>
</emph>
</xsl:template>
<xsl:template match='element'>
XML-element <emph><xsl:apply-templates/></emph>
</xsl:template>
<xsl:template match='attr'>
XML-attribute <emph><xsl:apply-templates/></emph>
</xsl:template>
<!-- v3pub don't want <p>s in <lists>s -->
<xsl:template match="list/p">
<xsl:message terminate="yes">
<ERROR text="list contains p-children!">
<xsl:copy-of select=".."/>
</ERROR>
</xsl:message>
</xsl:template>
<!-- MORE INTERESTING THINGS BELOW -->
<!-- figures and UML diagrams -->
<xsl:template match="figure">
<graphic source="graphics/{pixmap/@source}" alt="{caption}"/>
</xsl:template>
<xsl:template match="uml">
<graphic source="graphics/{pixmap/@source}" alt="{caption}"/>
</xsl:template>
<!-- Requirement elements contain normal content that should be indented
and given a coloured background -->
<xsl:template match='requirement'>
<exhibit role="requirement">
<xsl:apply-templates/><xsl:text> </xsl:text>
</exhibit>
</xsl:template>
<!-- Example elements contain unquoted XML that is transformed
into HTML in mode 'xml-verbatim'.
-->
<xsl:template match='example'>
<exhibit role="example" verbatim="yes">
<caption/>
<xsl:apply-templates mode="xml-verbatim" select="node()"/>
</exhibit>
</xsl:template>
<xsl:template match='template'>
<exhibit role="template" verbatim="yes">
<caption/>
<pre><xsl:copy-of select="."/><xsl:text> </xsl:text></pre>
</exhibit>
</xsl:template>
<xsl:template match='exhibit'>
<exhibit role="exhibit">
<xsl:apply-templates select="@*|node()"/>
</exhibit>
</xsl:template>
<!-- The dtimpl template turns a formal dtimpl element
into a section markup.
-->
<xsl:template match='dtimpl'>
<xsl:variable name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name='{$htag}' namespace="">
<xsl:attribute name='id'>
<xsl:value-of select='@id'/>
</xsl:attribute>
<anchor id='{@shortname}'/>
<head>
<xsl:value-of select='@longname'/>
<xsl:text> (</xsl:text>
<xsl:value-of select='@shortname'/>
<xsl:text>)</xsl:text>
<xsl:choose>
<xsl:when test='@restricts'>
<xsl:text> specializes </xsl:text><!-- YES! WE DO MEAN EXTENDS! err, specializes, now -->
<xsl:call-template name='makedtimplref'>
<xsl:with-param name='ref' select='@restricts'/>
</xsl:call-template>
</xsl:when>
<xsl:when test='@extends'>
<xsl:text> specializes </xsl:text>
<xsl:call-template name='makedtimplref'>
<xsl:with-param name='ref' select='@extends'/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</head>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- The dt template turns a formal dt element
into a section markup.
-->
<xsl:template match='dt'>
<xsl:variable name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name='{$htag}' namespace="">
<xsl:attribute name='id'>
<xsl:value-of select='@id'/>
</xsl:attribute>
<anchor id='{@shortname}'/>
<head>
<xsl:value-of select='@longname'/>
<xsl:text> (</xsl:text>
<xsl:value-of select='@shortname'/>
<xsl:text>)</xsl:text>
<xsl:choose>
<xsl:when test='@restricts'>
<xsl:text> specializes </xsl:text><!-- YES IT IS EXTENDS; err, specializes, now -->
<xsl:call-template name='makedtref'>
<xsl:with-param name='ref' select='@restricts'/>
</xsl:call-template>
</xsl:when>
<xsl:when test='@extends'>
<xsl:text> specializes </xsl:text>
<xsl:call-template name='makedtref'>
<xsl:with-param name='ref' select='@extends'/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</head>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- The xmlrep element interjects a subdivision for headed
"XML Representation". This is a hack, because I have
no idea which div# level I'm in here. I really think
div tags should not be numbered, the xpath can figure
it all out.
-->
<xsl:template match='xmlrep'>
<xsl:variable name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- xsl:element name='{$htag}' namespace="" -->
<!-- FIXME: this should really be a section, but shouldn't show
up in the TOC -->
<descriptive name="XML Representation"/>
<xsl:apply-templates/>
<!-- /xsl:element -->
</xsl:template>
<xsl:template match='xmlrep[@display = "false"]'/>
<!-- The properties element interjects a subdivision headed
"Properties". This is a hack, because I have
no idea which div# level I'm in here. I really think
div tags should not be numbered, the xpath can figure
it all out.
-->
<xsl:template match='properties'>
<xsl:variable name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name='{$htag}' namespace="">
<head>
<xsl:text>Properties of </xsl:text>
<xsl:value-of select='ancestor::dt[1]/@longname'/>
<xsl:text> (</xsl:text>
<xsl:value-of select='ancestor::dt[1]/@shortname'/>
<xsl:text>)</xsl:text>
</head>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- The profiles element interjects a subdivision headed
"Specializations". This is a hack, because I have
no idea which div# level I'm in here. I really think
div tags should not be numbered, the xpath can figure
it all out.
-->
<xsl:template match='profiles'>
<xsl:variable name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- xsl:element name='{$htag}' namespace="" -->
<!-- FIXME: this should really be a section, but shouldn't show
up in the TOC -->
<!-- descriptive>
<xsl:attribute name="name" -->
<p><emph role="strong">
Specializations of
<xsl:value-of select='ancestor::dt[1]/@longname'/>
(<xsl:value-of select='ancestor::dt[1]/@shortname'/>)</emph></p>
<!-- /xsl:attribute>
</descriptive -->
<xsl:apply-templates/>
<!-- /xsl:element -->
</xsl:template>
<!-- The comp template turns a formal component definition
into a section markup.
-->
<xsl:template match='comp'>
<xsl:param name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:element name='{$htag}' namespace="">
<xsl:attribute name='id'>
<xsl:value-of select='@id'/>
</xsl:attribute>
<head>
<xsl:value-of select='@longname'/>
<xsl:text> : </xsl:text>
<xsl:call-template name='dtimplRefByName'>
<xsl:with-param name='name' select='@type'/>
</xsl:call-template>
<xsl:if test='@default'>
<xsl:text> (default </xsl:text>
<emph>
<xsl:value-of select='@default'/>
</emph>
<xsl:text>)</xsl:text>
</xsl:if>
</head>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- The prop template turns a formal property definition
into a section markup.
-->
<xsl:template match='prop'>
<xsl:param name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:variable name="this">
<xsl:apply-templates mode="inherit" select="."/>
</xsl:variable>
<xsl:element name='{$htag}' namespace="">
<xsl:attribute name='id'>
<xsl:value-of select='$this/prop/@id'/>
</xsl:attribute>
<head>
<xsl:value-of select='$this/prop/@longname'/>
<!-- FIXME! Cludgy, yuck! -->
<xsl:if test="not($this/prop/@shortname='literal')">
<xsl:text> (</xsl:text>
<xsl:value-of select='$this/prop/@shortname'/>
<xsl:text> : </xsl:text>
<xsl:call-template name='DtRefByName'>
<xsl:with-param name='name' select='$this/prop/@type'/>
</xsl:call-template>
<xsl:if test='$this/prop/@default'>
<xsl:text>, default </xsl:text>
<emph>
<xsl:value-of select='$this/prop/@default'/>
</emph>
</xsl:if>
<xsl:if test='$this/prop/inherited'>
<xsl:text>, </xsl:text>
<xsl:choose>
<xsl:when test="$this/prop/@role='exclude'">
<xsl:text>fixed</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>inherited from </xsl:text>
<termref ref="{$this/prop/inherited/@from}">
<xsl:value-of
select="//dt[@id=$this/prop/inherited/@from]/@shortname"/>
</termref>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:text>)</xsl:text>
</xsl:if>
</head>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- The component template for inherited components.
It's possible for a comp to only refer to a base which
is the full specification that's inherited. In this
case we go down to the ancestor's full definition
of the component, show the variable, and then go back
up. The down-recursion is done in a separate mode 'base'.
The role can be 'exclude' which will drop in another
schema.
-->
<xsl:template match="comp[@base]">
<xsl:param name='done' select='/..'/>
<xsl:param name='role' select='@role'/>
<xsl:param name='id' select='@id'/>
<xsl:param name='htag'>
<xsl:choose>
<xsl:when test='parent::div1'>div2</xsl:when>
<xsl:when test='parent::*/parent::div1'>div3</xsl:when>
<xsl:when test='parent::*/parent::*/parent::div1'>div4</xsl:when>
<xsl:when test='parent::*/parent::*/parent::*/parent::div1'>div5</xsl:when>
<xsl:otherwise>div6</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:apply-templates select='//comp[@id=current()/@base]'
mode='base'>
<xsl:with-param name='done' select='.|$done'/>
<xsl:with-param name='role' select='$role'/>
<xsl:with-param name='id' select='$id'/>
<xsl:with-param name='htag' select='$htag'/>
<xsl:with-param name='current' select='.'/>
</xsl:apply-templates>
<xsl:apply-templates/>
</xsl:template>
<!-- This continues the recursion up to the first definition
of the component.
-->
<xsl:template match="comp[@base]" mode='base'>
<xsl:param name='done' select='/..'/>
<xsl:param name='role' select='/..'/>
<xsl:param name='id' select='/..'/>
<xsl:param name='htag' select='/..'/>
<xsl:param name='current' select='.'/>
<xsl:choose>
<xsl:when test='$done[@id=current()/@id]'>
<xsl:message terminate='yes'>
<xsl:text>CIRCULAR REFERENCE THROUGH </xsl:text>
<xsl:value-of select='@id'/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select='//comp[@id=current()/@base]'
mode='base'>
<xsl:with-param name='done' select='.|$done'/>
<xsl:with-param name='role' select='$role'/>
<xsl:with-param name='id' select='$id'/>
<xsl:with-param name='htag' select='$htag'/>
<xsl:with-param name='current' select='.'/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- This terminates the up-recursion chasing the final base
of the component.
-->
<xsl:template match='comp' mode='base'>
<xsl:param name='role' select='/..'/>
<xsl:param name='id' select='@id'/>
<xsl:param name='htag' select='/..'/>
<xsl:param name='current' select='.'/>
<xsl:element name='{$htag}' namespace="">
<xsl:attribute name='id'>
<xsl:value-of select='$id'/>
</xsl:attribute>
<anchor id='{$current/@shortname}'/>
<head>
<xsl:value-of select='@longname'/>
<xsl:text> : </xsl:text>
<xsl:call-template name='dtimplRefByName'>
<xsl:with-param name='name' select='@type'/>
</xsl:call-template>
<xsl:if test='@default'>
<xsl:text> (default </xsl:text>
<emph>
<xsl:value-of select='@default'/>
</emph>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text> (</xsl:text>
<xsl:choose>
<xsl:when test="$role='exclude'">
<xsl:text>fixed</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>inherited from </xsl:text>
<termref ref='{ancestor::dtimpl[1]/@id}'>
<xsl:value-of select='ancestor::dtimpl[1]/@shortname'/>
</termref>
</xsl:otherwise>
</xsl:choose>
<xsl:text>)</xsl:text>
</head>
<xsl:apply-templates select='definition'/>
</xsl:element>
</xsl:template>
<!-- Don't show a section for the inherited attributes that
don't add anything.
-->
<xsl:template match="comp[@base and not(node())]"
priority='1'>
</xsl:template>
<!-- NOW THE SAME FOR PROPERTIES -->
<!-- REDESIGN! SEPARATION OF CONCERNS IS VIOLATED, so we can't
reuse this code. What if all I want is to get to all the
inherited attributes and content without producing the v3pub
output?
GS TODO: do this for comp as well?
Simply construct an element as the union of the inherited
element and this element with this element's attributes
overriding the inherited attributes. The parent element is
expanded in a nodes named <inherits>, so one can inspect
the ancestry tree.
-->
<xsl:template match="prop[@base]|comp[@base]" mode="inherit">
<xsl:param name="done" select="/.."/>
<xsl:choose>
<xsl:when test='$done[@id=current()/@id]'>
<xsl:message terminate='yes'>
<xsl:text>CIRCULAR REFERENCE THROUGH </xsl:text>
<xsl:value-of select='@id'/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="last">
<xsl:apply-templates select='//*[name(.)=name(current())
and @id=current()/@base]'
mode='inherit'>
<xsl:with-param name='done' select='.|$done'/>
</xsl:apply-templates>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="$last/*/@*"/>
<xsl:copy-of select="@*"/>
<xsl:attribute name="for">
<xsl:value-of select="(ancestor::dt|ancestor::dtimpl)/@id"/>
</xsl:attribute>
<inherited from="{$last/*/@for}">
<xsl:copy-of select="$last/*/@*"/>
<xsl:copy-of select="$last/*/node()"/>
</inherited>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- This terminates the up-recursion chasing the final base
of the component.
-->
<xsl:template match="prop|comp" mode="inherit">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="for">
<xsl:value-of select="(ancestor::dt|ancestor::dtimpl)/@id"/>
</xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:template>
<!-- GUNTHER'S ADDITIONS -->
<xsl:template match='constraint'>
<xsl:apply-templates select='node()'/>
</xsl:template>
<xsl:template match='definition'>
<p>
<emph role="strong">Definition: </emph>
<xsl:apply-templates select="@*|node()"/>
</p>
</xsl:template>
<xsl:template match='hide'/>
<xsl:template match="sub">
<emph role="sub"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="sup">
<emph role="sup"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="var">
<emph><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="v">
<emph><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="sys">
<emph role="strong"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="dim">
<emph role="emph"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="i">
<emph><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="un">
<emph role="strong"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="lit">
<emph role="strong"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<xsl:template match="vec[text()='u']">
<emph>û</emph>
</xsl:template>
<xsl:template match="sym[@name]">
<xsl:text><</xsl:text>
<emph><xsl:value-of select="@name"/></emph>
<xsl:text>></xsl:text>
</xsl:template>
<xsl:template match="lit[@value]">
<xsl:text>“</xsl:text>
<code><xsl:value-of select="@value"/></code>
<xsl:text>”</xsl:text>
</xsl:template>
<xsl:template match="prod">
<emph role="strong"><xsl:text>Π</xsl:text></emph><xsl:apply-templates select="@*|node()"/>
</xsl:template>
<xsl:template match="prod/@from">
<emph role="sub"><xsl:value-of select="."/></emph>
</xsl:template>
<xsl:template match="prod/@to">
<emph role="sup"><xsl:value-of select="."/></emph>
</xsl:template>
<xsl:template match="strong">
<emph role="strong"><xsl:apply-templates select="@*|node()"/></emph>
</xsl:template>
<!-- A DTDL fragment rendered in the document.
-->
<xsl:template match='dtdl'>
<xsl:param name='id' select='@id'/>
<exhibit role='dtdl'>
<xsl:if test='$id'>
<xsl:attribute name='id'>
<xsl:value-of select='$id'/>
</xsl:attribute>
<anchor id="{$id}"/> <!-- FIXME: this is just a hack -->
</xsl:if>
<caption/>
<pre><xsl:apply-templates select="node()"/></pre>
</exhibit>
</xsl:template>
<!-- A DTDL fragment that is copy/pasted from its generalization
data type.
-->
<xsl:template match='dtdl[@base]'>
<xsl:param name='done' select='/..'/>
<xsl:param name='id' select='@id'/>
<xsl:choose>
<xsl:when test='$done[@id=current()/@id]'>
<xsl:message terminate='yes'>
<xsl:text>CIRCULAR REFERENCE THROUGH </xsl:text>
<xsl:value-of select='@id'/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select='//dtdl[@id=current()/@base]'>
<xsl:with-param name='done' select='.|$done'/>
<xsl:with-param name='id' select='$id'/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- A schema fragment rendered in the document.
-->
<xsl:template match='schema[@hide]' priority="5"/>
<xsl:template match='schema'/>
<!--
<xsl:param name='id' select='@id'/>
<exhibit role="schema" verbatim="yes">
<xsl:if test='$id'>
<xsl:attribute name='id'>
<xsl:value-of select='$id'/>
</xsl:attribute>
<anchor id="{$id}"/>
</xsl:if>
<caption/>
<xsl:apply-templates mode="xml-verbatim" select="node()"/>
</exhibit>
</xsl:template>
-->
<!-- A schema fragment that is copy/pasted from its generalization
data type.
-->
<xsl:template match='schema[@base or @copy-from]'/>
<!--
<xsl:param name='done' select='/..'/>
<xsl:param name='id' select='@id'/>
<xsl:param name='base' select='@base|@copy-from'/>
<xsl:choose>
<xsl:when test='$done[@id=current()/@id]'>
<xsl:message terminate='yes'>
<xsl:text>CIRCULAR REFERENCE THROUGH </xsl:text>
<xsl:value-of select='@id'/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select='//schema[@id=$base]'>
<xsl:with-param name='done' select='.|$done'/>
<xsl:with-param name='id' select='$id'/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-->
<xsl:template match='xpath-constraint'/>
<!-- <xsl:apply-templates select='node()'/>
<exhibit role='schema' verbatim="yes">
<caption/>
<xsl:variable name="schemaconstraint">
<xsl:apply-templates mode="raw" select="."/>
</xsl:variable>
<xsl:apply-templates mode="xml-verbatim" select="$schemaconstraint/node()"/>
</exhibit>
</xsl:template>
-->
<!-- ADDON TO THE xml-verbatim MODE (see xml-verbatim.xsl) -->
<!-- An ellipsis in a fragment is rendered in the document
as an abbreviated tag with some "...".
-->
<!-- Ellipsis without references shouldn't exist, but you never
know what's comming, so here is one with a straight "..."
look. -->
<xsl:template match='ellipsis' mode='xml-verbatim'>
<xsl:param name="indent" select="''" />
<br/><xsl:value-of select="$indent"/><xsl:text>...</xsl:text>
</xsl:template>
<!-- Some ellipsis may just have child ellipses. If it also has
a @ref attribute, the next rule should take over. -->
<xsl:template match='ellipsis[child::ellipsis]' mode='xml-verbatim'>
<xsl:param name="indent" select="''" />
<xsl:apply-templates mode="xml-verbatim" select="node()">
<xsl:with-param name="indent" select="$indent" />
</xsl:apply-templates>
</xsl:template>
<!-- Ellipses with a @ref: this is the normal case. Here we
dereference the @ref and unwrap the schema container.
The content of the schema fragment will be transformed in
ellipsis mode. -->
<xsl:template match='ellipsis[@ref]' priority='1' mode='xml-verbatim'>
<xsl:param name="indent" select="''" />
<xsl:apply-templates select='//schema[@id=current()/@ref]/*'
mode="ellipsis">
<xsl:with-param name="indent" select="$indent" />
</xsl:apply-templates>
<xsl:apply-templates mode="xml-verbatim" select="node()">
<xsl:with-param name="indent" select="$indent" />
</xsl:apply-templates>
</xsl:template>
<!-- Most ellipses are for elements and attributes of which we
will show name and type only. -->
<xsl:template match='xsd:element|xsd:attribute' mode='ellipsis'>
<xsl:param name="indent" select="''" />
<br/><xsl:value-of select='$indent'/>
<span class="{local-name(.)}">
<xsl:text><</xsl:text>
<xsl:variable name="ns-prefix" select="substring-before(name(),':')" />
<xsl:if test="$ns-prefix != ''">
<span class="xml-verbatim-element-nsprefix">
<xsl:value-of select="$ns-prefix" />
</span>
<xsl:text>:</xsl:text>
</xsl:if>
<span class="xml-verbatim-element-name">
<xsl:value-of select="local-name()" />
</span>
<xsl:for-each select="@name|@type|@ref">
<xsl:call-template name="xml-verbatim-attrs" />
</xsl:for-each>