-
Notifications
You must be signed in to change notification settings - Fork 2
/
xs3p.xsl
8520 lines (7984 loc) · 357 KB
/
xs3p.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" standalone="yes"?>
<!--
Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 2002
The software contained on this media is the property of the
DSTC Pty Ltd. Use of this software is strictly in accordance
with the license agreement in the accompanying LICENSE file.
If your distribution of this software does not contain a
LICENSE file then you have no rights to use this software
in any manner and should contact DSTC at the address below
to determine an appropriate licensing arrangement.
DSTC Pty Ltd
Level 7, General Purpose South
The University of Queensland
QLD 4072 Australia
Tel: +61 7 3365 4310
Fax: +61 7 3365 4311
Email: [email protected]
This software is being provided "AS IS" without warranty of
any kind. In no event shall DSTC Pty Ltd be liable for
damage of any kind arising out of or in connection with
the use or performance of this software.
-->
<!--
File:
xs3p.xsl
Description:
Stylesheet that generates XHTML documentation, given an XML
Schema document
Assumptions:
-Resulting documentation will only be displayed properly with
the latest browsers that support XHTML and CSS. Older
browsers are not supported.
-Assumed that XSD document conforms to the XSD recommendation.
No validity checking is done.
Constraints:
-Local schema components cannot contain two dashes in
'documentation' elements within their 'annotation' element.
This is because the contents of those 'documentation'
elements are displayed in a separate window using Javascript.
This Javascript code is enclosed in comments, which do not
allow two dashes inside themselves.
Notes:
-Javascript code is placed within comments, even though in
strict XHTML, JavaScript code should be placed within CDATA
sections. This is because current browsers generate a syntax
error if the page contains CDATA sections. Placing Javascript
code within comments means that the code cannot contain two
dashes.
(See 'PrintJSCode' named template.)
Stylesheet Sections:
-Global Parameters
Specify parameters that can be set externally to customise
stylesheet
-Constants
Constants used by the stylesheet
-Main Document
Templates to generate the overall document and the top-level
sections within it
-Hierarchy table
Templates for displaying type hierarchy for simple and
complex types, and substitution group hierarchy for elements
-Properties table
Templates for displaying the properties of top-level schema
components
-XML Instance Representation table
Templates for displaying how an XML instance conforming to
the schema component would look like
-Schema Component Representation table
Templates for displaying the XML representation of the schema
component
-XML Pretty Printer
Templates for displaying arbitrary XML instances
-Handling Schema Component References
Templates for generating internal and external links
-General Utility Templates
General templates used by other templates in this stylesheet
To Do List:
-It is not clever when printing out element and attribute
wildcards in the XML Instance Representation tables. It prints
out all wildcards, rather than working out the actual wildcard
is from multiple wildcard instances.
-Same as above for simple type constraints, e.g. it doesn't
summarise multiple pattern constraints.
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ppp="http://titanium.dstc.edu.au/xml/xs3p"
version="1.0"
exclude-result-prefixes="xsd ppp html">
<xsl:output
method="xml"
encoding="ISO-8859-1"
standalone="yes"
version="1.0"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"/>
<xsl:key name="type" match="/xsd:schema/xsd:complexType | /xsd:schema/xsd:simpleType | /xsd:schema/xsd:redefine/xsd:complexType | /xsd:schema/xsd:redefine/xsd:simpleType" use="@name" />
<xsl:key name="complexType" match="/xsd:schema/xsd:complexType | /xsd:schema/xsd:redefine/xsd:complexType" use="@name" />
<xsl:key name="simpleType" match="/xsd:schema/xsd:simpleType | /xsd:schema/xsd:redefine/xsd:simpleType" use="@name" />
<xsl:key name="attributeGroup" match="/xsd:schema/xsd:attributeGroup | /xsd:schema/xsd:redefine/xsd:attributeGroup" use="@name" />
<xsl:key name="group" match="/xsd:schema/xsd:group | /xsd:schema/xsd:redefine/xsd:group" use="@name" />
<xsl:key name="attribute" match="/xsd:schema/xsd:attribute" use="@name" />
<xsl:key name="element" match="/xsd:schema/xsd:element" use="@name" />
<!-- ******** Global Parameters ******** -->
<!-- Title of XHTML document. -->
<xsl:param name="title"></xsl:param>
<!-- If 'true', sorts the top-level schema components by type,
then name. Otherwise, displays the components by the order that
they appear in the schema. -->
<xsl:param name="sortByComponent">true</xsl:param>
<!-- If 'true', XHTML document uses JavaScript for added
functionality, such as pop-up windows and information-
hiding.
Otherwise, XHTML document does not use JavaScript. -->
<xsl:param name="useJavaScript">true</xsl:param>
<!-- If 'true', prints all super-types in the
type hierarchy box.
Otherwise, prints the parent type only in the
type hierarchy box. -->
<xsl:param name="printAllSuperTypes">true</xsl:param>
<!-- If 'true', prints all sub-types in the
type hierarchy box.
Otherwise, prints the direct sub-types only in the
type hierarchy box. -->
<xsl:param name="printAllSubTypes">true</xsl:param>
<!-- If 'true', prints out the Glossary section. -->
<xsl:param name="printGlossary">true</xsl:param>
<!-- If 'true', prints out the Legend section. -->
<xsl:param name="printLegend">true</xsl:param>
<!-- If 'true', prints prefix matching namespace of schema
components in XML Instance Representation tables. -->
<xsl:param name="printNSPrefixes">true</xsl:param>
<!-- If 'true', searches 'included' schemas for schema components
when generating links and XML Instance Representation tables. -->
<xsl:param name="searchIncludedSchemas">false</xsl:param>
<!-- If 'true', searches 'imported' schemas for schema components
when generating links and XML Instance Representation tables. -->
<xsl:param name="searchImportedSchemas">false</xsl:param>
<!-- File containing the mapping from file locations of external
(e.g. included, imported, refined) schemas to file locations
of their XHTML documentation. -->
<xsl:param name="linksFile"></xsl:param>
<!-- Set the base URL for resolving links. -->
<xsl:param name="baseURL"></xsl:param>
<!-- Uses an external CSS stylesheet rather than using
internally-declared CSS properties. -->
<xsl:param name="externalCSSURL"></xsl:param>
<!-- ******** Constants ******** -->
<!-- XML Schema Namespace -->
<xsl:variable name="XSD_NS">http://www.w3.org/2001/XMLSchema</xsl:variable>
<!-- XML Namespace -->
<xsl:variable name="XML_NS">http://www.w3.org/XML/1998/namespace</xsl:variable>
<!-- Number of 'em' to indent from parent element's start tag to
child element's start tag -->
<xsl:variable name="ELEM_INDENT">1.5</xsl:variable>
<!-- Number of 'em' to indent from parent element's start tag to
attribute's tag -->
<xsl:variable name="ATTR_INDENT">0.5</xsl:variable>
<!-- Title to use if none provided -->
<xsl:variable name="DEFAULT_TITLE">XML Schema Documentation</xsl:variable>
<!-- Prefixes used for anchor names -->
<!-- Type definitions -->
<xsl:variable name="TYPE_PREFIX">type_</xsl:variable>
<!-- Attribute declarations -->
<xsl:variable name="ATTR_PREFIX">attribute_</xsl:variable>
<!-- Attribute group definitions -->
<xsl:variable name="ATTR_GRP_PREFIX">attributeGroup_</xsl:variable>
<!-- Complex type definitions -->
<xsl:variable name="CTYPE_PREFIX" select="$TYPE_PREFIX"/>
<!-- Element declarations -->
<xsl:variable name="ELEM_PREFIX">element_</xsl:variable>
<!-- Key definitions -->
<xsl:variable name="KEY_PREFIX">key_</xsl:variable>
<!-- Group definitions -->
<xsl:variable name="GRP_PREFIX">group_</xsl:variable>
<!-- Notations -->
<xsl:variable name="NOTA_PREFIX">notation_</xsl:variable>
<!-- Namespace declarations -->
<xsl:variable name="NS_PREFIX">ns_</xsl:variable>
<!-- Simple type definitions -->
<xsl:variable name="STYPE_PREFIX" select="$TYPE_PREFIX"/>
<!-- Glossary terms -->
<xsl:variable name="TERM_PREFIX">term_</xsl:variable>
<!-- The original schema needs to be stored because when
calculating links for references, the links have to be
relative to the original schema. See 'PrintCompRef'
template. -->
<xsl:variable name="ORIGINAL_SCHEMA" select="/xsd:schema"/>
<!-- ******** Main Document ******** -->
<!--
Main template that starts the process
-->
<xsl:template match="/xsd:schema">
<!-- Check that links file is provided if searching external
schemas for components. -->
<xsl:if test="$linksFile='' and (normalize-space(translate($searchIncludedSchemas, 'TRUE', 'true'))='true' or normalize-space(translate($searchImportedSchemas, 'TRUE', 'true'))='true')">
<xsl:call-template name="HandleError">
<xsl:with-param name="isTerminating">true</xsl:with-param>
<xsl:with-param name="errorMsg">
'linksFile' variable must be provided if either
'searchIncludedSchemas' or 'searchImportedSchemas' is true.
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<!-- Get title of document -->
<xsl:variable name="actualTitle">
<xsl:choose>
<xsl:when test="$title != ''">
<xsl:value-of select="$title"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$DEFAULT_TITLE"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<html>
<head>
<!-- Set title bar -->
<title><xsl:value-of select="$actualTitle"/></title>
<!-- Set content type -->
<meta http-equiv="Content-Type" content="text/xml; charset=iso-8859-1"/>
<!-- Set base URL to use in working out relative paths -->
<xsl:if test="$baseURL != ''">
<xsl:element name="base">
<xsl:attribute name="href"><xsl:value-of select="$baseURL"/></xsl:attribute>
</xsl:element>
</xsl:if>
<!-- Set CSS styles -->
<style type="text/css">
<xsl:choose>
<!-- Use external CSS stylesheet -->
<xsl:when test="$externalCSSURL != ''">
<xsl:text>
@import url(</xsl:text><xsl:value-of select="$externalCSSURL"/><xsl:text>);
</xsl:text>
</xsl:when>
<!-- Use internal CSS styles -->
<xsl:otherwise>
<xsl:call-template name="DocumentCSSStyles"/>
</xsl:otherwise>
</xsl:choose>
</style>
<!-- Add Javascript code to make the collapseable boxes work -->
<xsl:if test="normalize-space(translate($useJavaScript,'TRUE','true'))='true'">
<xsl:call-template name="PrintJSCode">
<xsl:with-param name="code">
<xsl:call-template name="DocumentJSCode"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</head>
<body>
<!-- Title -->
<h1><a name="top"><xsl:value-of select="$actualTitle"/></a></h1>
<!-- Buttons for displaying printer-friendly version, and
expanding and collapsing all boxes -->
<xsl:call-template name="GlobalControlButtons"/>
<!-- Section: Table of Contents -->
<h2>Table of Contents</h2>
<xsl:apply-templates select="." mode="toc"/>
<xsl:call-template name="SectionFooter"/>
<!-- Section: Schema Document Properties -->
<h2><a name="SchemaProperties">Schema Document Properties</a></h2>
<!-- Sub-section: Properties table -->
<xsl:apply-templates select="." mode="properties"/>
<!-- Sub-section: Namespace Legend -->
<h3>Declared Namespaces</h3>
<xsl:apply-templates select="." mode="namespaces"/>
<!-- Sub-section: Schema Component Representation table -->
<xsl:call-template name="SchemaComponentTable">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<xsl:call-template name="SectionFooter"/>
<!-- Section: Redefined Schema Components -->
<xsl:if test="xsd:redefine">
<h2><a name="Redefinitions">Redefined Schema Components</a></h2>
<xsl:apply-templates select="xsd:redefine/xsd:simpleType | xsd:redefine/xsd:complexType | xsd:redefine/xsd:attributeGroup | xsd:redefine/xsd:group" mode="topSection"/>
</xsl:if>
<!-- Sections: Top-level Schema Components -->
<xsl:choose>
<!-- Sort schema components -->
<xsl:when test="normalize-space(translate($sortByComponent,'TRUE','true'))='true'">
<!-- Declarations -->
<xsl:if test="xsd:attribute or xsd:element">
<h2><a name="SchemaDeclarations">Global Declarations</a></h2>
<xsl:apply-templates select="xsd:attribute | xsd:element" mode="topSection">
<xsl:sort select="local-name(.)" order="ascending"/>
<xsl:sort select="@name" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
<!-- Definitions -->
<xsl:if test="xsd:attributeGroup or xsd:complexType or xsd:group or xsd:notation or xsd:simpleType">
<h2><a name="SchemaDefinitions">Global Definitions</a></h2>
<xsl:apply-templates select="xsd:attributeGroup | xsd:complexType | xsd:group | xsd:notation | xsd:simpleType" mode="topSection">
<xsl:sort select="local-name(.)" order="ascending"/>
<xsl:sort select="@name" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
</xsl:when>
<!-- Display schema components as they occur -->
<xsl:otherwise>
<h2><a name="SchemaComponents">Global Schema Components</a></h2>
<xsl:apply-templates select="xsd:attribute | xsd:attributeGroup | xsd:complexType | xsd:element | xsd:group | xsd:notation | xsd:simpleType" mode="topSection"/>
</xsl:otherwise>
</xsl:choose>
<!-- Section: Legend -->
<xsl:if test="normalize-space(translate($printLegend,'TRUE','true'))='true'">
<div id="legend">
<h2><a name="Legend">Legend</a></h2>
<xsl:call-template name="Legend"/>
<xsl:call-template name="SectionFooter"/>
</div>
</xsl:if>
<!-- Section: Glossary -->
<xsl:if test="normalize-space(translate($printGlossary,'TRUE','true'))='true'">
<div id="glossary">
<h2><a name="Glossary">Glossary</a></h2>
<xsl:call-template name="Glossary"/>
<xsl:call-template name="SectionFooter"/>
</div>
</xsl:if>
<!-- Document Footer -->
<p class="footer">
<xsl:text>Generated by </xsl:text>
<a href="http://xml.fiforms.org/xs3p/">xs3p</a> (<a href="http://titanium.dstc.edu.au/xml/xs3p">old link</a>)
<xsl:text>.</xsl:text>
<xsl:if test="normalize-space(translate($useJavaScript,'TRUE','true'))='true'">
<xsl:text> Last modified: </xsl:text>
<xsl:call-template name="PrintJSCode">
<xsl:with-param name="code">document.write(document.lastModified);</xsl:with-param>
</xsl:call-template>
</xsl:if>
</p>
</body>
</html>
</xsl:template>
<!--
Prints out the table of Declared Namespaces for the
current schema.
-->
<xsl:template match="xsd:schema" mode="namespaces">
<table class="namespaces">
<tr>
<th>Prefix</th>
<th>Namespace</th>
</tr>
<!-- Default namespace (no prefix) -->
<xsl:if test="namespace::*[local-name(.)='']">
<xsl:variable name="ns" select="namespace::*[local-name(.)='']"/>
<tr>
<td>
<a name="{$NS_PREFIX}">Default namespace</a>
</td>
<td>
<xsl:choose>
<xsl:when test="/xsd:schema/@targetNamespace and $ns=normalize-space(/xsd:schema/@targetNamespace)">
<span class="targetNS">
<xsl:value-of select="$ns"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ns"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:if>
<!-- Namespaces with prefixes -->
<xsl:for-each select="namespace::*[local-name(.)!='']">
<xsl:variable name="prefix" select="local-name(.)"/>
<xsl:variable name="ns" select="."/>
<tr>
<td>
<a name="{concat($NS_PREFIX, $prefix)}">
<xsl:value-of select="$prefix"/>
</a>
</td>
<td>
<xsl:choose>
<xsl:when test="/xsd:schema/@targetNamespace and $ns=normalize-space(/xsd:schema/@targetNamespace)">
<span class="targetNS">
<xsl:value-of select="$ns"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ns"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!--
Prints out the Table of Contents.
-->
<xsl:template match="xsd:schema" mode="toc">
<ul>
<!-- Section: Schema Document Properties -->
<li>
<a href="#SchemaProperties">Schema Document Properties</a>
</li>
<!-- Section: Redefined Schema Components -->
<xsl:if test="xsd:redefine">
<li>
<a href="#Redefinitions">Redefined Schema Components</a>
</li>
</xsl:if>
<!-- Sections: Top-level Schema Components -->
<xsl:choose>
<!-- Sort schema components -->
<xsl:when test="normalize-space(translate($sortByComponent,'TRUE','true'))='true'">
<!-- Declarations -->
<xsl:if test="xsd:attribute or xsd:element">
<li><a href="#SchemaDeclarations">Global Declarations</a>
<ul>
<xsl:apply-templates select="xsd:attribute | xsd:element" mode="toc">
<xsl:sort select="local-name(.)" order="ascending"/>
<xsl:sort select="@name" order="ascending"/>
</xsl:apply-templates>
</ul>
</li>
</xsl:if>
<!-- Definitions -->
<xsl:if test="xsd:attributeGroup or xsd:complexType or xsd:group or xsd:notation or xsd:simpleType">
<li><a href="#SchemaDefinitions">Global Definitions</a>
<ul>
<xsl:apply-templates select="xsd:attributeGroup | xsd:complexType | xsd:group | xsd:notation | xsd:simpleType" mode="toc">
<xsl:sort select="local-name(.)" order="ascending"/>
<xsl:sort select="@name" order="ascending"/>
</xsl:apply-templates>
</ul>
</li>
</xsl:if>
</xsl:when>
<!-- Display schema components in order as they appear in schema -->
<xsl:otherwise>
<li><a href="#SchemaComponents">Global Schema Components</a>
<ul>
<xsl:apply-templates select="xsd:attribute | xsd:attributeGroup | xsd:complexType | xsd:element | xsd:group | xsd:notation | xsd:simpleType" mode="toc"/>
</ul>
</li>
</xsl:otherwise>
</xsl:choose>
</ul>
<!-- Section: Legend -->
<xsl:if test="normalize-space(translate($printLegend,'TRUE','true'))='true'">
<ul id="legendTOC" style="margin-top: 0em">
<li><a href="#Legend">Legend</a></li>
</ul>
</xsl:if>
<!-- Section: Glossary -->
<xsl:if test="normalize-space(translate($printGlossary,'TRUE','true'))='true'">
<ul id="glossaryTOC" style="margin-top: 0em">
<li><a href="#Glossary">Glossary</a></li>
</ul>
</xsl:if>
</xsl:template>
<!--
Prints out a link to a top-level schema component section in the
Table of Contents.
-->
<xsl:template match="xsd:*[@name]" mode="toc">
<xsl:variable name="componentID">
<xsl:call-template name="GetComponentID">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
</xsl:variable>
<li>
<a href="#{$componentID}">
<xsl:call-template name="GetComponentDescription">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<xsl:text>: </xsl:text>
<strong><xsl:value-of select="@name"/></strong>
</a>
</li>
</xsl:template>
<!--
Prints out the section for a top-level schema component.
-->
<xsl:template match="xsd:*[@name]" mode="topSection">
<!-- Header -->
<xsl:call-template name="ComponentSectionHeader">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<!-- Hierarchy table (for types and elements) -->
<xsl:apply-templates select="." mode="hierarchy"/>
<!-- Properties table -->
<xsl:apply-templates select="." mode="properties"/>
<!-- XML Instance Representation table -->
<xsl:call-template name="SampleInstanceTable">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<!-- Schema Component Representation table -->
<xsl:call-template name="SchemaComponentTable">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<!-- Footer -->
<xsl:call-template name="SectionFooter"/>
</xsl:template>
<!--
Prints out the buttons that can expand and collapse all boxes in
this page.
-->
<xsl:template name="GlobalControlButtons">
<xsl:if test="normalize-space(translate($useJavaScript,'TRUE','true'))='true'">
<div style="float: right;">
<!-- Printer-friendly Version -->
<div id="printerControls" style="display:none;">
<input type="checkbox" onclick="displayMode(this.checked)"/>
<xsl:text>Printer-friendly Version</xsl:text>
</div>
<xsl:call-template name="PrintJSCode">
<xsl:with-param name="code">
var pc = getElementObject("printerControls");
if (pc != null) {
pc.style.display="block";
}
</xsl:with-param>
</xsl:call-template>
<!-- Expand/Collapse All buttons -->
<div id="globalControls" style="display:none">
<strong>XML Instance Representation:</strong><br/>
<span style="margin-left: 1em; white-space: nowrap">
<xsl:text>[ </xsl:text>
<a href="javascript:void(0)" onclick="expandAll(xiBoxes)">Expand All</a>
<xsl:text> | </xsl:text>
<a href="javascript:void(0)" onclick="collapseAll(xiBoxes)">Collapse All</a>
<xsl:text> ]</xsl:text>
</span><br/><br/>
<strong>Schema Component Representation:</strong><br/>
<span style="margin-left: 1em; white-space: nowrap">
<xsl:text>[ </xsl:text>
<a href="javascript:void(0)" onclick="expandAll(scBoxes)">Expand All</a>
<xsl:text> | </xsl:text>
<a href="javascript:void(0)" onclick="collapseAll(scBoxes)">Collapse All</a>
<xsl:text> ]</xsl:text>
</span>
</div>
<xsl:call-template name="PrintJSCode">
<xsl:with-param name="code">
var gc = getElementObject("globalControls");
if (gc != null) {
gc.style.display="block";
}
</xsl:with-param>
</xsl:call-template>
</div>
</xsl:if>
</xsl:template>
<!--
Prints out the section header of a top-level schema component.
Param(s):
component (Node) required
Top-level schema component
-->
<xsl:template name="ComponentSectionHeader">
<xsl:param name="component"/>
<xsl:variable name="componentID">
<xsl:call-template name="GetComponentID">
<xsl:with-param name="component" select="$component"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="componentDescription">
<xsl:call-template name="GetComponentDescription">
<xsl:with-param name="component" select="$component"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="componentTermRef">
<xsl:call-template name="GetComponentTermRef">
<xsl:with-param name="component" select="$component"/>
</xsl:call-template>
</xsl:variable>
<h3>
<!-- Description -->
<xsl:choose>
<xsl:when test="$componentTermRef != ''">
<xsl:call-template name="PrintGlossaryTermRef">
<xsl:with-param name="code" select="$componentTermRef"/>
<xsl:with-param name="term" select="$componentDescription"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$componentDescription"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>: </xsl:text>
<!-- Name -->
<a name="{$componentID}" class="name">
<xsl:value-of select="$component/@name"/>
</a>
</h3>
</xsl:template>
<!--
Prints out footer for top-level sections.
-->
<xsl:template name="SectionFooter">
<!-- Link to top of page-->
<div style="text-align: right; clear: both;"><a href="#top">top</a></div>
<hr/>
</xsl:template>
<!--
Java Script code required by the entire HTML document.
-->
<xsl:template name="DocumentJSCode">
<!-- Get all IDs of XML Instance Representation boxes
and place them in an array. -->
<xsl:text>/* IDs of XML Instance Representation boxes */
</xsl:text>
<xsl:text>var xiBoxes = new Array(</xsl:text>
<xsl:for-each select="/xsd:schema/xsd:*[@name]">
<xsl:if test="position()!=1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:text>'</xsl:text>
<xsl:call-template name="GetComponentID">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<xsl:text>_xibox'</xsl:text>
</xsl:for-each>
<xsl:text>);
</xsl:text>
<!-- Get all IDs of Schema Component Representation boxes
and place them in an array. -->
<xsl:text>/* IDs of Schema Component Representation boxes */
</xsl:text>
<xsl:text>var scBoxes = new Array('schema_scbox'</xsl:text>
<xsl:for-each select="/xsd:schema/xsd:*[@name]">
<xsl:text>, '</xsl:text>
<xsl:call-template name="GetComponentID">
<xsl:with-param name="component" select="."/>
</xsl:call-template>
<xsl:text>_scbox'</xsl:text>
</xsl:for-each>
<xsl:text>);
</xsl:text>
<!-- Functions -->
<xsl:text>
/**
* Can get the ID of the button controlling
* a collapseable box by concatenating
* this string onto the ID of the box itself.
*/
var B_SFIX = "_button";
/**
* Counter of documentation windows
* Used to give each window a unique name
*/
var windowCount = 0;
/**
* Returns an element in the current HTML document.
*
* @param elementID Identifier of HTML element
* @return HTML element object
*/
function getElementObject(elementID) {
var elemObj = null;
if (document.getElementById) {
elemObj = document.getElementById(elementID);
}
return elemObj;
}
/**
* Closes a collapseable box.
*
* @param boxObj Collapseable box
* @param buttonObj Button controlling box
*/
function closeBox(boxObj, buttonObj) {
if (boxObj == null || buttonObj == null) {
// Box or button not found
} else {
// Change 'display' CSS property of box
boxObj.style.display="none";
// Change text of button
if (boxObj.style.display=="none") {
buttonObj.value=" + ";
}
}
}
/**
* Opens a collapseable box.
*
* @param boxObj Collapseable box
* @param buttonObj Button controlling box
*/
function openBox(boxObj, buttonObj) {
if (boxObj == null || buttonObj == null) {
// Box or button not found
} else {
// Change 'display' CSS property of box
boxObj.style.display="block";
// Change text of button
if (boxObj.style.display=="block") {
buttonObj.value=" - ";
}
}
}
/**
* Sets the state of a collapseable box.
*
* @param boxID Identifier of box
* @param open If true, box is "opened",
* Otherwise, box is "closed".
*/
function setState(boxID, open) {
var boxObj = getElementObject(boxID);
var buttonObj = getElementObject(boxID+B_SFIX);
if (boxObj == null || buttonObj == null) {
// Box or button not found
} else if (open) {
openBox(boxObj, buttonObj);
// Make button visible
buttonObj.style.display="inline";
} else {
closeBox(boxObj, buttonObj);
// Make button visible
buttonObj.style.display="inline";
}
}
/**
* Switches the state of a collapseable box, e.g.
* if it's opened, it'll be closed, and vice versa.
*
* @param boxID Identifier of box
*/
function switchState(boxID) {
var boxObj = getElementObject(boxID);
var buttonObj = getElementObject(boxID+B_SFIX);
if (boxObj == null || buttonObj == null) {
// Box or button not found
} else if (boxObj.style.display=="none") {
// Box is closed, so open it
openBox(boxObj, buttonObj);
} else if (boxObj.style.display=="block") {
// Box is opened, so close it
closeBox(boxObj, buttonObj);
}
}
/**
* Closes all boxes in a given list.
*
* @param boxList Array of box IDs
*/
function collapseAll(boxList) {
var idx;
for (idx = 0; idx < boxList.length; idx++) {
var boxObj = getElementObject(boxList[idx]);
var buttonObj = getElementObject(boxList[idx]+B_SFIX);
closeBox(boxObj, buttonObj);
}
}
/**
* Open all boxes in a given list.
*
* @param boxList Array of box IDs
*/
function expandAll(boxList) {
var idx;
for (idx = 0; idx < boxList.length; idx++) {
var boxObj = getElementObject(boxList[idx]);
var buttonObj = getElementObject(boxList[idx]+B_SFIX);
openBox(boxObj, buttonObj);
}
}
/**
* Makes all the control buttons of boxes appear.
*
* @param boxList Array of box IDs
*/
function viewControlButtons(boxList) {
var idx;
for (idx = 0; idx < boxList.length; idx++) {
buttonObj = getElementObject(boxList[idx]+B_SFIX);
if (buttonObj != null) {
buttonObj.style.display = "inline";
}
}
}
/**
* Makes all the control buttons of boxes disappear.
*
* @param boxList Array of box IDs
*/
function hideControlButtons(boxList) {
var idx;
for (idx = 0; idx < boxList.length; idx++) {
buttonObj = getElementObject(boxList[idx]+B_SFIX);
if (buttonObj != null) {
buttonObj.style.display = "none";
}
}
}
/**
* Sets the page for either printing mode
* or viewing mode. In printing mode, the page
* is made to be more readable when printing it out.
* In viewing mode, the page is more browsable.
*
* @param isPrinterVersion If true, display in
* printing mode; otherwise,
* in viewing mode
*/
function displayMode(isPrinterVersion) {
var obj;
if (isPrinterVersion) {
// Hide global control buttons
obj = getElementObject("globalControls");
if (obj != null) {
obj.style.visibility = "hidden";
}
// Hide Legend
obj = getElementObject("legend");
if (obj != null) {
obj.style.display = "none";
}
obj = getElementObject("legendTOC");
if (obj != null) {
obj.style.display = "none";
}
// Hide Glossary
obj = getElementObject("glossary");
if (obj != null) {
obj.style.display = "none";
}
obj = getElementObject("glossaryTOC");
if (obj != null) {
obj.style.display = "none";
}
// Expand all XML Instance Representation tables
expandAll(xiBoxes);
// Expand all Schema Component Representation tables
expandAll(scBoxes);
// Hide Control buttons
hideControlButtons(xiBoxes);
hideControlButtons(scBoxes);
} else {
// View global control buttons
obj = getElementObject("globalControls");
if (obj != null) {
obj.style.visibility = "visible";
}
// View Legend
obj = getElementObject("legend");
if (obj != null) {
obj.style.display = "block";
}
obj = getElementObject("legendTOC");
if (obj != null) {
obj.style.display = "block";
}
// View Glossary
obj = getElementObject("glossary");
if (obj != null) {
obj.style.display = "block";
}
obj = getElementObject("glossaryTOC");
if (obj != null) {
obj.style.display = "block";
}
// Expand all XML Instance Representation tables
expandAll(xiBoxes);
// Collapse all Schema Component Representation tables
collapseAll(scBoxes);
// View Control buttons
viewControlButtons(xiBoxes);
viewControlButtons(scBoxes);
}
}
/**
* Opens up a window displaying the documentation
* of a schema component in the XML Instance
* Representation table.
*
* @param compDesc Description of schema component
* @param compName Name of schema component
* @param docTextArray Array containing the paragraphs
* of the new document
*/
function viewDocumentation(compDesc, compName, docTextArray) {
var width = 400;
var height = 200;
var locX = 100;
var locY = 200;
/* Generate content */
var actualText = "<html>";
actualText += "<head><title>";
actualText += compDesc;
if (compName != '') {
actualText += ": " + compName;
}
actualText += "</title></head>";
actualText += "<body bgcolor=\"#FFFFEE\">";
// Title
actualText += "<p style=\"font-family: Arial, sans-serif; font-size: 12pt; font-weight: bold; letter-spacing:1px;\">";
actualText += compDesc;
if (compName != '') {
actualText += ": <span style=\"color:#006699\">" + compName + "</span>";
}
actualText += "</p>";
// Documentation
var idx;
for (idx = 0; idx < docTextArray.length; idx++) {
actualText += "<p style=\"font-family: Arial, sans-serif; font-size: 10pt;\">" + docTextArray[idx] + "</p>";
}
// Link to close window
actualText += "<a href=\"javascript:void(0)\" onclick=\"window.close();\" style=\"font-family: Arial, sans-serif; font-size: 8pt;\">Close</a>";
actualText += "</body></html>";
/* Display window */
windowCount++;