~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/content/common/xslt/schema.xslt

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
 
 
3
<!-- (C) 2009 Rackspace Hosting, All Rights Reserved -->
 
4
 
 
5
 
 
6
<xslt:stylesheet version="1.0"
 
7
            xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
 
8
            xmlns:html="http://www.w3.org/1999/xhtml"
 
9
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 
10
            xmlns:xsdxt="http://docs.rackspacecloud.com/xsd-ext/v1.0"
 
11
            xmlns="http://www.w3.org/1999/xhtml"
 
12
            >
 
13
 
 
14
  <xslt:output method="html"
 
15
               encoding="UTF-8"
 
16
               media-type="text/html"
 
17
               doctype-public = "-//W3C//DTD HTML 4.01//EN"
 
18
               doctype-system = "http://www.w3.org/TR/html4/strict.dtd" />
 
19
 
 
20
  <!-- Params -->
 
21
  <xslt:param name="base">
 
22
      <xslt:choose>
 
23
          <xslt:when test="/xsd:schema/@xsdxt:base">
 
24
              <xslt:value-of select="/xsd:schema/@xsdxt:base"/>
 
25
          </xslt:when>
 
26
          <xslt:otherwise>
 
27
              <xslt:text>..</xslt:text>
 
28
          </xslt:otherwise>
 
29
      </xslt:choose>
 
30
  </xslt:param>
 
31
 
 
32
  <!-- Global Variables -->
 
33
  <xslt:variable name="defaultTitle">XML Schema Documentation</xslt:variable>
 
34
  <xslt:variable name="templateType">application/xhtml+xml</xslt:variable>
 
35
  <xslt:variable name="schemaNamespace">http://www.w3.org/2001/XMLSchema</xslt:variable>
 
36
  <xslt:variable name="schemaDatatypeURI">http://web4.w3.org/TR/2001/REC-xmlschema-2-20010502/#</xslt:variable>
 
37
 
 
38
  <xslt:variable name="dQuote">"</xslt:variable>
 
39
  <xslt:variable name="sQuote">'</xslt:variable>
 
40
 
 
41
  <!-- The namespace prefixes -->
 
42
  <xslt:variable name="targetPrefix">
 
43
      <xslt:for-each select="/xsd:schema/namespace::node()">
 
44
        <xslt:if test=".=/xsd:schema/@targetNamespace">
 
45
          <xslt:value-of select="name(.)"/>
 
46
        </xslt:if>
 
47
      </xslt:for-each>
 
48
  </xslt:variable>
 
49
 
 
50
  <xslt:variable name="schemaPrefix">
 
51
      <xslt:for-each select="/xsd:schema/namespace::node()">
 
52
        <xslt:if test="(.=$schemaNamespace) and (string-length(.) > 0)">
 
53
          <xslt:value-of select="name(.)"/>
 
54
        </xslt:if>
 
55
      </xslt:for-each>
 
56
  </xslt:variable>
 
57
 
 
58
  <!-- Anchor prefixes -->
 
59
  <xslt:variable name="elementPrefix">element_</xslt:variable>
 
60
  <xslt:variable name="attributePrefix">attrib_</xslt:variable>
 
61
  <xslt:variable name="attributeGroupPrefix">attgrp_</xslt:variable>
 
62
  <xslt:variable name="groupPrefix">grp_</xslt:variable>
 
63
  <xslt:variable name="typePrefix">type_</xslt:variable>
 
64
 
 
65
  <!-- YUI BASE:  -->
 
66
  <!--
 
67
      We only load YUI style sheets here. We bring js stuff
 
68
      dynamically. Stylesheet's can't really be brought dynamically.
 
69
      They need to be loaded before anything else.
 
70
  -->
 
71
  <xslt:variable name="YUI_BASE">http://yui.yahooapis.com/2.7.0/build/</xslt:variable>
 
72
  <xslt:variable name="YUI_RESET_STYLESHEET">
 
73
    <xslt:value-of select="concat($YUI_BASE,'reset/reset-min.css')" />
 
74
  </xslt:variable>
 
75
  <xslt:variable name="YUI_BASE_STYLESHEET">
 
76
    <xslt:value-of select="concat($YUI_BASE,'base/base-min.css')" />
 
77
  </xslt:variable>
 
78
  <xslt:variable name="YUI_FONTS_STYLESHEET">
 
79
    <xslt:value-of select="concat($YUI_BASE,'fonts/fonts-min.css')" />
 
80
  </xslt:variable>
 
81
  <xslt:variable name="YUI_GRIDS_STYLESHEET">
 
82
    <xslt:value-of select="concat($YUI_BASE,'grids/grids-min.css')" />
 
83
  </xslt:variable>
 
84
 
 
85
  <xslt:template name="addStylesheet">
 
86
    <xslt:param name="sheet" />
 
87
    <xslt:element name="link">
 
88
      <xslt:attribute name="rel">stylesheet</xslt:attribute>
 
89
      <xslt:attribute name="type">text/css</xslt:attribute>
 
90
      <xslt:attribute name="href">
 
91
        <xslt:value-of select="$sheet"/>
 
92
      </xslt:attribute>
 
93
    </xslt:element>
 
94
  </xslt:template>
 
95
 
 
96
  <!-- Templates -->
 
97
  <xslt:template name="SchemaHandler" match="xsd:schema">
 
98
    <html>
 
99
      <head>
 
100
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
101
        <xslt:call-template name="addStylesheet">
 
102
          <xslt:with-param name="sheet" select="$YUI_RESET_STYLESHEET"/>
 
103
        </xslt:call-template>
 
104
        <xslt:call-template name="addStylesheet">
 
105
          <xslt:with-param name="sheet" select="$YUI_BASE_STYLESHEET"/>
 
106
        </xslt:call-template>
 
107
        <xslt:call-template name="addStylesheet">
 
108
          <xslt:with-param name="sheet" select="$YUI_FONTS_STYLESHEET"/>
 
109
        </xslt:call-template>
 
110
        <xslt:call-template name="addStylesheet">
 
111
          <xslt:with-param name="sheet" select="$YUI_GRIDS_STYLESHEET"/>
 
112
        </xslt:call-template>
 
113
        <xslt:call-template name="addStylesheet">
 
114
          <xslt:with-param name="sheet" select="concat($base,'/style/schema.css')"/>
 
115
        </xslt:call-template>
 
116
 
 
117
        <!--
 
118
            Add custom links...
 
119
        -->
 
120
        <xslt:for-each select="//xsdxt:link">
 
121
          <xslt:if test="not(@qname)">
 
122
            <xslt:element name="link">
 
123
              <xslt:if test="@rev">
 
124
                <xslt:attribute name="rev"><xslt:value-of select="@rev"/></xslt:attribute>
 
125
              </xslt:if>
 
126
              <xslt:if test="@rel">
 
127
                <xslt:attribute name="rel"><xslt:value-of select="@rel"/></xslt:attribute>
 
128
              </xslt:if>
 
129
              <xslt:if test="@href">
 
130
                <xslt:attribute name="href"><xslt:value-of select="@href"/></xslt:attribute>
 
131
              </xslt:if>
 
132
              <xslt:if test="@type">
 
133
                <xslt:attribute name="type"><xslt:value-of select="@type"/></xslt:attribute>
 
134
              </xslt:if>
 
135
            </xslt:element>
 
136
          </xslt:if>
 
137
        </xslt:for-each>
 
138
 
 
139
        <!--
 
140
            Set the title if it's available, default title if not.
 
141
        -->
 
142
        <xslt:choose>
 
143
          <xslt:when test="xsd:annotation/xsd:appinfo/xsdxt:title">
 
144
            <title><xslt:value-of select="xsd:annotation/xsd:appinfo/xsdxt:title"/></title>
 
145
          </xslt:when>
 
146
          <xslt:otherwise>
 
147
            <title><xslt:value-of select="$defaultTitle"/></title>
 
148
          </xslt:otherwise>
 
149
        </xslt:choose>
 
150
 
 
151
        <!-- Schema scripts -->
 
152
        <script type="text/javascript" src="{$base}/js/trc/util.js"> </script>
 
153
        <script type="text/javascript" src="{$base}/js/trc/schema/layoutManager.js"> </script>
 
154
        <script type="text/javascript" src="{$base}/js/trc/schema/sampleManager.js"> </script>
 
155
        <script type="text/javascript" src="{$base}/js/trc/schema/controller.js"> </script>
 
156
 
 
157
        <xslt:if test="//xsdxt:samples | //xsdxt:code">
 
158
          <script type="text/javascript">
 
159
            <xslt:for-each select="//xsdxt:samples">
 
160
              <xslt:variable name="elmId"><xslt:value-of select="generate-id(.)"/></xslt:variable>
 
161
              <xslt:if test="xsdxt:sample">
 
162
                <xslt:text>trc.schema.sampleManager.samples["</xslt:text>
 
163
                <xslt:value-of select="$elmId"/>
 
164
                <xslt:text>"]=[</xslt:text>
 
165
                <xslt:for-each select="xsdxt:sample">
 
166
                  <xslt:call-template name="StringToJavascript">
 
167
                    <xslt:with-param name="inString" select="generate-id(.)"/>
 
168
                  </xslt:call-template>
 
169
                  <xslt:if test="generate-id(../xsdxt:sample[count(../xsdxt:sample)]) !=
 
170
                                 generate-id(.)
 
171
                                 ">
 
172
                    <xslt:text>,</xslt:text>
 
173
                  </xslt:if>
 
174
                </xslt:for-each>
 
175
                <xslt:text>];</xslt:text>
 
176
              </xslt:if>
 
177
            </xslt:for-each>
 
178
            <xslt:if test="//xsdxt:code">
 
179
              <xslt:text>trc.schema.sampleManager.codes.push(</xslt:text>
 
180
              <xslt:for-each select="//xsdxt:code">
 
181
                <xslt:text>{ id : </xslt:text>
 
182
                <xslt:value-of select="concat($dQuote,generate-id(.),$dQuote)" />
 
183
                <xslt:text>, type : "</xslt:text>
 
184
                <xslt:choose>
 
185
                  <xslt:when test="@type">
 
186
                    <xslt:value-of select="@type"/>
 
187
                  </xslt:when>
 
188
                  <xslt:otherwise>
 
189
                    <xslt:text>application/xml</xslt:text>
 
190
                  </xslt:otherwise>
 
191
                </xslt:choose>
 
192
                <xslt:text>", href : </xslt:text>
 
193
                <xslt:choose>
 
194
                  <xslt:when test="@href">
 
195
                    <xslt:value-of select="concat($dQuote,@href,$dQuote)"/>
 
196
                  </xslt:when>
 
197
                  <xslt:otherwise>
 
198
                    <xslt:text>null</xslt:text>
 
199
                  </xslt:otherwise>
 
200
                </xslt:choose>
 
201
                <xslt:text>}</xslt:text>
 
202
                  <xslt:text>,</xslt:text>
 
203
              </xslt:for-each>
 
204
              <xslt:text>null);</xslt:text>
 
205
            </xslt:if>
 
206
          </script>
 
207
        </xslt:if>
 
208
 
 
209
        <xslt:call-template name="ControllerJSHandler" />
 
210
 
 
211
        <!--
 
212
            Copy any HTML header tags here
 
213
        -->
 
214
        <xslt:for-each select="//xsdxt:head">
 
215
          <xslt:choose>
 
216
            <xslt:when test="not(@type)">
 
217
              <xslt:copy-of select="./*" />
 
218
            </xslt:when>
 
219
            <xslt:when test="@type = $templateType">
 
220
              <xslt:copy-of select="./*" />
 
221
            </xslt:when>
 
222
          </xslt:choose>
 
223
        </xslt:for-each>
 
224
      </head>
 
225
      <body>
 
226
        <div id="Controller">
 
227
        </div>
 
228
        <div id="doc">
 
229
          <div id="Main">
 
230
            <div id="SrcContent">
 
231
              <div class="SampleCode">
 
232
                <pre id="SrcContentCode">Loading...</pre>
 
233
              </div>
 
234
            </div>
 
235
            <div id="Content">
 
236
              <!--
 
237
                  If there is a title use it as a first heading, otherwise,
 
238
                  use default title.
 
239
              -->
 
240
              <xslt:choose>
 
241
                <xslt:when test="xsd:annotation/xsd:appinfo/xsdxt:title">
 
242
                  <h1><xslt:value-of select="xsd:annotation/xsd:appinfo/xsdxt:title"/></h1>
 
243
                </xslt:when>
 
244
                <xslt:otherwise>
 
245
                  <h1><xslt:value-of select="$defaultTitle"/></h1>
 
246
                </xslt:otherwise>
 
247
              </xslt:choose>
 
248
 
 
249
              <!--
 
250
                  Schema attributes
 
251
              -->
 
252
              <table summary="Schema-level attributes">
 
253
                <tbody>
 
254
                  <xslt:for-each select="@*">
 
255
                    <tr>
 
256
                      <td><xslt:value-of select="local-name(.)"/></td>
 
257
                      <td><xslt:value-of select="."/></td>
 
258
                    </tr>
 
259
                  </xslt:for-each>
 
260
                </tbody>
 
261
              </table>
 
262
 
 
263
              <!--
 
264
                  Copy schema-level documentation if there's anything to
 
265
                  copy. This also processes any internal documentation
 
266
                  annotations:  currently just xsdxt:code.
 
267
              -->
 
268
              <xslt:apply-templates select="xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
269
            
 
270
              <!--
 
271
                  Next comes custom header...
 
272
              -->
 
273
              <div id="Header">
 
274
                <xslt:for-each select="//xsdxt:header">
 
275
                  <xslt:choose>
 
276
                    <xslt:when test="not(@type)">
 
277
                      <xslt:copy-of select="./*" />
 
278
                    </xslt:when>
 
279
                    <xslt:when test="@type = $templateType">
 
280
                      <xslt:copy-of select="./*" />
 
281
                    </xslt:when>
 
282
                  </xslt:choose>
 
283
                </xslt:for-each>
 
284
              </div>
 
285
 
 
286
 
 
287
              <!--
 
288
                  Namespace info, not all borowsers have namespace node
 
289
                  support.  Specifically Firefox currently lacks it.
 
290
 
 
291
               See:
 
292
               https://bugzilla.mozilla.org/show_bug.cgi?id=94270
 
293
 
 
294
               In this case we ask the user to try a different
 
295
               browser:  Opera, Safari, or even IE.
 
296
              -->
 
297
              <h2>Namespaces</h2>
 
298
              <xslt:choose>
 
299
                <xslt:when test="count(namespace::*) = 0">
 
300
                  <!--Namespaces are not available...-->
 
301
                  <div class="Warning">
 
302
                    <p>
 
303
                      Your browser does not seem to have support for
 
304
                      namespace nodes in XPath. If you're a Firefox
 
305
                      user, please consider voting to get this issue
 
306
                      resolved:
 
307
                      <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=94270"
 
308
                         title="FireFox Bug 94270">
 
309
                        https://bugzilla.mozilla.org/show_bug.cgi?id=94270
 
310
                      </a>
 
311
                    </p>
 
312
                  </div>
 
313
                </xslt:when>
 
314
                <xslt:otherwise>
 
315
                  <table summary="Namespace details">
 
316
                    <tbody>
 
317
                      <xslt:for-each select="namespace::*">
 
318
                        <xslt:sort />
 
319
                        <tr>
 
320
                          <td><xslt:value-of select="name(.)"/></td>
 
321
                          <td><xslt:value-of select="."/></td>
 
322
                        </tr>
 
323
                      </xslt:for-each>
 
324
                    </tbody>
 
325
                  </table>
 
326
                </xslt:otherwise>
 
327
              </xslt:choose>
 
328
 
 
329
              <!--
 
330
                  Next, call the handlers for the top schema elements.
 
331
              -->
 
332
              <xslt:if test="xsd:import">
 
333
                <xslt:call-template name="ImportHandler" />
 
334
              </xslt:if>
 
335
              <xslt:if test="xsd:include">
 
336
                <xslt:call-template name="IncludeHandler" />
 
337
              </xslt:if>
 
338
 
 
339
              <xslt:if test="xsd:element">
 
340
                <xslt:call-template name="ElementHandler" />
 
341
              </xslt:if>
 
342
 
 
343
              <xslt:if test="xsd:complexType">
 
344
                <xslt:call-template name="ComplexTypeHandler" />
 
345
              </xslt:if>
 
346
 
 
347
              <xslt:if test="xsd:simpleType">
 
348
                <xslt:call-template name="SimpleTypeHandler" />
 
349
              </xslt:if>
 
350
 
 
351
              <!-- Finally, custom footers -->
 
352
              <div id="Footer">
 
353
                <xslt:for-each select="//xsdxt:footer">
 
354
                  <xslt:choose>
 
355
                    <xslt:when test="not(@type)">
 
356
                      <xslt:copy-of select="./*" />
 
357
                    </xslt:when>
 
358
                    <xslt:when test="@type = $templateType">
 
359
                      <xslt:copy-of select="./*" />
 
360
                    </xslt:when>
 
361
                  </xslt:choose>
 
362
                </xslt:for-each>
 
363
              </div>
 
364
            </div>
 
365
          </div>
 
366
        </div>
 
367
      </body>
 
368
    </html>
 
369
  </xslt:template>
 
370
 
 
371
  <xslt:template name="ControllerExternJSLinks">
 
372
    <xslt:param name="nodes" />
 
373
 
 
374
    <xslt:text>trc.schema.controller.links['</xslt:text>
 
375
    <xslt:value-of select="local-name($nodes[1])"/>
 
376
    <xslt:text>']=[</xslt:text>
 
377
    <xslt:for-each select="$nodes">
 
378
      <xslt:call-template name="ControllerJSLink">
 
379
        <xslt:with-param name="href" select="@schemaLocation"/>
 
380
        <xslt:with-param name="name">
 
381
          <xslt:choose>
 
382
            <xslt:when test="@namespace">
 
383
              <xslt:value-of select="@namespace" />
 
384
            </xslt:when>
 
385
            <xslt:otherwise>
 
386
              <xslt:value-of select="@schemaLocation" />
 
387
            </xslt:otherwise>
 
388
          </xslt:choose>
 
389
        </xslt:with-param>
 
390
        <xslt:with-param name="title">
 
391
          <xslt:choose>
 
392
            <xslt:when test="@namespace">
 
393
              <xslt:value-of select="concat('View schema for namespace ',@namespace)"/>
 
394
            </xslt:when>
 
395
            <xslt:otherwise>
 
396
              <xslt:value-of select="concat('Visit schema ',@schemaLocation)"/>
 
397
            </xslt:otherwise>
 
398
          </xslt:choose>
 
399
        </xslt:with-param>
 
400
      </xslt:call-template>
 
401
      <xslt:if test="$nodes[count($nodes)]/@schemaLocation !=
 
402
                     @schemaLocation">
 
403
        <xslt:text>,</xslt:text>
 
404
      </xslt:if>
 
405
    </xslt:for-each>
 
406
    <xslt:text>];</xslt:text>
 
407
  </xslt:template>
 
408
 
 
409
  <xslt:template name="ControllerIndexJSLink">
 
410
    <xslt:param name="node" select="//xsdxt:link[@rel = 'index']" />
 
411
 
 
412
    <xslt:text>trc.schema.controller.index = </xslt:text>
 
413
    <xslt:call-template name="ControllerJSLink">
 
414
      <xslt:with-param name="href">
 
415
        <xslt:value-of select="$node/@href"/>
 
416
      </xslt:with-param>
 
417
      <xslt:with-param name="name">
 
418
        <xslt:text>index</xslt:text>
 
419
      </xslt:with-param>
 
420
      <xslt:with-param name="title">
 
421
        <xslt:text>Index Schema Document</xslt:text>
 
422
      </xslt:with-param>
 
423
    </xslt:call-template>
 
424
    <xslt:text>;</xslt:text>
 
425
  </xslt:template>
 
426
 
 
427
  <xslt:template name="ControllerNamedElementJSLink">
 
428
    <xslt:param name="nodes" />
 
429
    <xslt:param name="anchorPrefix" />
 
430
 
 
431
    <xslt:text>trc.schema.controller.links['</xslt:text>
 
432
    <xslt:value-of select="local-name($nodes[1])"/>
 
433
    <xslt:text>']=[</xslt:text>
 
434
    <xslt:for-each select="$nodes">
 
435
      <xslt:call-template name="ControllerJSLink">
 
436
        <xslt:with-param name="href">
 
437
          <xslt:text>#</xslt:text>
 
438
          <xslt:value-of select="$anchorPrefix" />
 
439
          <xslt:value-of select="@name" />
 
440
        </xslt:with-param>
 
441
        <xslt:with-param name="name">
 
442
          <xslt:call-template name="StringToName"/>
 
443
        </xslt:with-param>
 
444
        <xslt:with-param name="title">
 
445
          <xslt:text>See definition of </xslt:text>
 
446
          <xslt:call-template name="StringToName"/>
 
447
        </xslt:with-param>
 
448
      </xslt:call-template>
 
449
      <xslt:if test="generate-id($nodes[count($nodes)]) !=
 
450
                     generate-id(.)">
 
451
        <xslt:text>,</xslt:text>
 
452
      </xslt:if>
 
453
    </xslt:for-each>
 
454
    <xslt:text>];</xslt:text>
 
455
  </xslt:template>
 
456
 
 
457
  <xslt:template name="ControllerJSLink">
 
458
    <xslt:param name="name"  />
 
459
    <xslt:param name="href"  />
 
460
    <xslt:param name="title" />
 
461
 
 
462
    <xslt:text>{ href : </xslt:text>
 
463
    <xslt:call-template name="StringToJavascript">
 
464
      <xslt:with-param name="inString">
 
465
        <xslt:value-of select="$href"/>
 
466
      </xslt:with-param>
 
467
    </xslt:call-template>
 
468
    <xslt:text>, name : </xslt:text>
 
469
    <xslt:call-template name="StringToJavascript">
 
470
      <xslt:with-param name="inString">
 
471
        <xslt:value-of select="$name"/>
 
472
      </xslt:with-param>
 
473
    </xslt:call-template>
 
474
    <xslt:text>, title : </xslt:text>
 
475
    <xslt:call-template name="StringToJavascript">
 
476
      <xslt:with-param name="inString">
 
477
        <xslt:value-of select="$title"/>
 
478
      </xslt:with-param>
 
479
    </xslt:call-template>
 
480
    <xslt:text>}</xslt:text>
 
481
  </xslt:template>
 
482
 
 
483
  <!--
 
484
      Adds javascript for controller data..
 
485
  -->
 
486
  <xslt:template name="ControllerJSHandler">
 
487
    <script type="text/javascript">
 
488
      <xslt:if test="xsd:import">
 
489
        <xslt:call-template name="ControllerExternJSLinks">
 
490
          <xslt:with-param name="nodes" select="xsd:import" />
 
491
        </xslt:call-template>
 
492
      </xslt:if>
 
493
      <xslt:if test="xsd:include">
 
494
        <xslt:call-template name="ControllerExternJSLinks">
 
495
          <xslt:with-param name="nodes" select="xsd:include" />
 
496
        </xslt:call-template>
 
497
      </xslt:if>
 
498
      <xslt:if test="xsd:element">
 
499
        <xslt:call-template name="ControllerNamedElementJSLink">
 
500
          <xslt:with-param name="nodes" select="xsd:element"/>
 
501
          <xslt:with-param name="anchorPrefix" select="$elementPrefix"/>
 
502
        </xslt:call-template>
 
503
      </xslt:if>
 
504
      <xslt:if test="xsd:attribute">
 
505
        <xslt:call-template name="ControllerNamedElementJSLink">
 
506
          <xslt:with-param name="nodes" select="xsd:attribute"/>
 
507
          <xslt:with-param name="anchorPrefix" select="$attributePrefix"/>
 
508
        </xslt:call-template>
 
509
      </xslt:if>
 
510
      <xslt:if test="xsd:complexType">
 
511
        <xslt:call-template name="ControllerNamedElementJSLink">
 
512
          <xslt:with-param name="nodes" select="xsd:complexType"/>
 
513
          <xslt:with-param name="anchorPrefix" select="$typePrefix"/>
 
514
        </xslt:call-template>
 
515
      </xslt:if>
 
516
      <xslt:if test="xsd:simpleType">
 
517
        <xslt:call-template name="ControllerNamedElementJSLink">
 
518
          <xslt:with-param name="nodes" select="xsd:simpleType"/>
 
519
          <xslt:with-param name="anchorPrefix" select="$typePrefix"/>
 
520
        </xslt:call-template>
 
521
      </xslt:if>
 
522
      <xslt:if test="//xsdxt:link[@rel = 'index']">
 
523
        <xslt:call-template name="ControllerIndexJSLink" />
 
524
      </xslt:if>
 
525
    </script>
 
526
  </xslt:template>
 
527
 
 
528
  <xslt:template name="ImportHandler">
 
529
    <h2>Imports</h2>
 
530
    <table summary="A list of imported XML Schema" class="ImportTable">
 
531
      <tbody>
 
532
        <xslt:for-each select="xsd:import">
 
533
          <tr>
 
534
            <td>
 
535
              <xslt:value-of select="@namespace"/>
 
536
            </td>
 
537
            <td>
 
538
              <div class="Extern">
 
539
                <div class="ExternHref">
 
540
                  <xslt:element name="a">
 
541
                    <xslt:attribute name="href"><xslt:value-of select="@schemaLocation"/></xslt:attribute>
 
542
                    <xslt:attribute name="title">Visit <xslt:value-of select="@schemaLocation"/></xslt:attribute>
 
543
                    <xslt:value-of select="@schemaLocation"/>
 
544
                  </xslt:element>
 
545
                </div>
 
546
                <div class="ExternDoc">
 
547
                  <xslt:apply-templates select="xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
548
                </div>
 
549
              </div>
 
550
            </td>
 
551
          </tr>
 
552
        </xslt:for-each>
 
553
      </tbody>
 
554
    </table>
 
555
  </xslt:template>
 
556
 
 
557
  <xslt:template name="IncludeHandler">
 
558
    <h2>Includes</h2>
 
559
    <table summary="A list of included XML Schema">
 
560
      <tbody>
 
561
        <xslt:for-each select="xsd:include">
 
562
          <tr>
 
563
            <td>
 
564
              <div class="Extern">
 
565
                <div class="ExternHref">
 
566
                  <xslt:element name="a">
 
567
                    <xslt:attribute name="href"><xslt:value-of select="@schemaLocation"/></xslt:attribute>
 
568
                    <xslt:attribute name="title">Visit <xslt:value-of select="@schemaLocation"/></xslt:attribute>
 
569
                    <xslt:value-of select="@schemaLocation"/>
 
570
                  </xslt:element>
 
571
                </div>
 
572
                <div class="ExternDoc">
 
573
                  <xslt:apply-templates select="xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
574
                </div>
 
575
              </div>
 
576
            </td>
 
577
          </tr>
 
578
        </xslt:for-each>
 
579
      </tbody>
 
580
    </table>
 
581
  </xslt:template>
 
582
 
 
583
  <xslt:template name="ElementHandler">
 
584
    <h2>Elements</h2>
 
585
    <xslt:for-each select="xsd:element">
 
586
      <xslt:call-template name="NamedElement">
 
587
        <xslt:with-param name="anchorPrefix" select="$elementPrefix" />
 
588
      </xslt:call-template>
 
589
      <xslt:if test="xsd:annotation/xsd:appinfo/xsdxt:samples">
 
590
        <xslt:apply-templates select="xsd:annotation/xsd:appinfo/xsdxt:samples" mode="Docs" />
 
591
      </xslt:if>
 
592
    </xslt:for-each>
 
593
  </xslt:template>
 
594
 
 
595
  <xslt:template name="SampleHandler" match="xsdxt:samples" mode="Docs">
 
596
    <xslt:variable name="sampleID" select="generate-id(.)"/>
 
597
    <xslt:if test="xsdxt:description">
 
598
      <xslt:apply-templates select="xsdxt:description/*" mode="Docs" />
 
599
    </xslt:if>
 
600
    <form action="">
 
601
      <div class="SampleControl">
 
602
        <xslt:element name="select">
 
603
          <xslt:attribute name="onchange">
 
604
            <xslt:text>trc.schema.sampleManager.showSample(</xslt:text>
 
605
            <xslt:call-template name="StringToJavascript">
 
606
              <xslt:with-param name="inString" select="$sampleID"/>
 
607
            </xslt:call-template>
 
608
            <xslt:text>);</xslt:text>
 
609
          </xslt:attribute>
 
610
          <xslt:attribute name="id">
 
611
            <xslt:value-of select="$sampleID"/>
 
612
          </xslt:attribute>
 
613
          <xslt:for-each select="xsdxt:sample">
 
614
            <xslt:element name="option">
 
615
              <xslt:attribute name="value">
 
616
                <xslt:value-of select="generate-id(.)"/>
 
617
              </xslt:attribute>
 
618
              <xslt:choose>
 
619
                <xslt:when test="@title">
 
620
                  <xslt:value-of select="@title"/>
 
621
                </xslt:when>
 
622
                <xslt:otherwise>
 
623
                  <xslt:value-of select="./xsdxt:code/@type"/>
 
624
                </xslt:otherwise>
 
625
              </xslt:choose>
 
626
            </xslt:element>
 
627
          </xslt:for-each>
 
628
        </xslt:element>
 
629
      </div>
 
630
    </form>
 
631
    <xslt:for-each select="xsdxt:sample">
 
632
      <xslt:element name="div">
 
633
        <xslt:attribute name="id"><xslt:value-of select="generate-id(.)"/></xslt:attribute>
 
634
        <xslt:attribute name="class">Sample</xslt:attribute>
 
635
        <div class="SampleDesc">
 
636
          <xslt:apply-templates select="xsdxt:description/*" mode="Docs"/>
 
637
        </div>
 
638
        <xslt:apply-templates select="xsdxt:code" mode="Docs"/>
 
639
      </xslt:element>
 
640
    </xslt:for-each>
 
641
  </xslt:template>
 
642
 
 
643
  <!--
 
644
      Documentation templates, copy everything but process the
 
645
      xsdxt:code tag.
 
646
  -->
 
647
  <xslt:template match="xsdxt:code" mode="Docs">
 
648
    <div class="SampleCode">
 
649
      <xslt:element name="pre">
 
650
        <xslt:attribute name="id">
 
651
          <xslt:value-of select="generate-id(.)"/>
 
652
        </xslt:attribute>
 
653
        <xslt:choose>
 
654
          <xslt:when test="@href">
 
655
            <xslt:text>Loading...</xslt:text>
 
656
          </xslt:when>
 
657
          <xslt:otherwise>
 
658
            <xslt:value-of select="."/>
 
659
          </xslt:otherwise>
 
660
        </xslt:choose>
 
661
      </xslt:element>
 
662
    </div>
 
663
  </xslt:template>
 
664
 
 
665
  <xslt:template match="*" mode="Docs">
 
666
    <xslt:copy-of select="." />
 
667
  </xslt:template>
 
668
 
 
669
  <xslt:template name="ComplexTypeHandler">
 
670
    <h2>Complex Types</h2>
 
671
    <xslt:for-each select="xsd:complexType">
 
672
      <xslt:call-template name="NamedElement">
 
673
        <xslt:with-param name="anchorPrefix" select="$typePrefix" />
 
674
      </xslt:call-template>
 
675
      <xslt:apply-templates />
 
676
    </xslt:for-each>
 
677
  </xslt:template>
 
678
 
 
679
  <xslt:template name="SimpleTypeHandler">
 
680
    <h2>Simple Types</h2>
 
681
    <xslt:for-each select="xsd:simpleType">
 
682
      <xslt:call-template name="NamedElement">
 
683
        <xslt:with-param name="anchorPrefix" select="$typePrefix" />
 
684
      </xslt:call-template>
 
685
      <xslt:apply-templates />
 
686
    </xslt:for-each>
 
687
  </xslt:template>
 
688
 
 
689
  <xslt:template name="NamedElementLink">
 
690
    <xslt:param name="anchorPrefix" />
 
691
    <xslt:call-template name="Anchor">
 
692
      <xslt:with-param name="href">
 
693
        <xslt:text>#</xslt:text>
 
694
        <xslt:value-of select="$anchorPrefix"/>
 
695
        <xslt:value-of select="@name"/>
 
696
      </xslt:with-param>
 
697
      <xslt:with-param name="content">
 
698
        <xslt:call-template name="StringToName" />
 
699
      </xslt:with-param>
 
700
    </xslt:call-template>
 
701
  </xslt:template>
 
702
 
 
703
  <xslt:template name="NamedElement">
 
704
    <xslt:param name="anchorPrefix" />
 
705
    <xslt:element name="a">
 
706
      <xslt:attribute name="id"><xslt:value-of select="$anchorPrefix"/><xslt:value-of select="@name"/></xslt:attribute>
 
707
      <!--
 
708
          Placing a comment here causes the anchor tag to be closed
 
709
          correctly in IE 8.
 
710
      -->
 
711
      <xslt:comment>
 
712
        <xslt:value-of select="@name"/>
 
713
      </xslt:comment>
 
714
    </xslt:element>
 
715
    <h3>
 
716
      <xslt:call-template name="StringToName" />
 
717
    </h3>
 
718
 
 
719
    <xslt:choose>
 
720
      <!-- look for extensions and restrictions in type names -->
 
721
        <xslt:when test="$anchorPrefix = $typePrefix">
 
722
          <xslt:if test=".//xsd:extension">
 
723
            <div class="NameAddl">
 
724
              <xslt:text> extends: </xslt:text>
 
725
              <xslt:for-each select=".//xsd:extension">
 
726
                <xslt:apply-templates select="@base" mode="QNameToLink" />
 
727
                <xslt:if test=".//xsd:extension[count(.//xsd:extension)]/@base != @base">
 
728
                  <xslt:text>,</xslt:text>
 
729
                </xslt:if>
 
730
              </xslt:for-each>
 
731
            </div>
 
732
          </xslt:if>
 
733
          <xslt:if test=".//xsd:restriction">
 
734
            <div class="NameAddl">
 
735
              <xslt:text> restricts: </xslt:text>
 
736
              <xslt:for-each select=".//xsd:restriction">
 
737
                <xslt:apply-templates select="@base" mode="QNameToLink" />
 
738
                <xslt:if test=".//xsd:restriction[count(.//xsd:restriction)]/@base != @base">
 
739
                  <xslt:text>,</xslt:text>
 
740
                </xslt:if>
 
741
              </xslt:for-each>
 
742
            </div>
 
743
          </xslt:if>
 
744
        </xslt:when>
 
745
    </xslt:choose>
 
746
 
 
747
    <xslt:call-template name="AttribsAndDocs" />
 
748
 
 
749
  </xslt:template>
 
750
 
 
751
  <!-- Display all attributes besides @name -->
 
752
  <xslt:template name="Attribs">
 
753
    <xslt:param name="isSubItem" select="false()"/>
 
754
    <xslt:if test="(count(@*) > 1) or ((count(@*) = 1) and not(@name))">
 
755
      <xslt:element name="div">
 
756
        <xslt:attribute name="class">
 
757
          <xslt:choose>
 
758
            <xslt:when test="$isSubItem = true()">
 
759
              <xslt:text>SubAttributes</xslt:text>
 
760
            </xslt:when>
 
761
            <xslt:otherwise>
 
762
              <xslt:text>Attributes</xslt:text>
 
763
            </xslt:otherwise>
 
764
          </xslt:choose>
 
765
        </xslt:attribute>
 
766
        <table summary="Attributes">
 
767
          <tbody>
 
768
            <xslt:for-each select="@*">
 
769
              <xslt:sort select="local-name(.)"/>
 
770
              <xslt:if test="local-name(.) != 'name'">
 
771
                <tr>
 
772
                  <td><xslt:value-of select="local-name(.)"/></td>
 
773
                  <td><xslt:call-template name="QNameToLink"/></td>
 
774
                </tr>
 
775
              </xslt:if>
 
776
            </xslt:for-each>
 
777
          </tbody>
 
778
        </table>
 
779
      </xslt:element>
 
780
    </xslt:if>
 
781
  </xslt:template>
 
782
 
 
783
  <xslt:template name="Docs">
 
784
    <xslt:param name="isSubItem" select="false()"/>
 
785
    <!--
 
786
        Copy element-level documentation
 
787
    -->
 
788
    <xslt:if test="xsd:annotation/xsd:documentation">
 
789
      <xslt:element name="div">
 
790
        <xslt:attribute name="class">
 
791
          <xslt:choose>
 
792
            <xslt:when test="$isSubItem = true()">
 
793
              <xslt:text>SubDocumentation</xslt:text>
 
794
            </xslt:when>
 
795
            <xslt:otherwise>
 
796
              <xslt:text>Documentation</xslt:text>
 
797
            </xslt:otherwise>
 
798
          </xslt:choose>
 
799
        </xslt:attribute>
 
800
        <xslt:apply-templates select="xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
801
      </xslt:element>
 
802
    </xslt:if>
 
803
  </xslt:template>
 
804
 
 
805
  <xslt:template name="AttribsAndDocs">
 
806
    <xslt:param name="isSubItem" select="false()"/>
 
807
    <xslt:call-template name="Attribs">
 
808
      <xslt:with-param name="isSubItem" select="$isSubItem"/>
 
809
    </xslt:call-template>
 
810
    <xslt:call-template name="Docs">
 
811
      <xslt:with-param name="isSubItem" select="$isSubItem"/>
 
812
    </xslt:call-template>
 
813
  </xslt:template>
 
814
 
 
815
  <!--
 
816
      Convert a qname to a link.
 
817
  -->
 
818
  <xslt:template name="QNameToLink" match="@*" mode="QNameToLink">
 
819
    <xslt:param name="qname" select="normalize-space(.)"/>
 
820
    <xslt:choose>
 
821
      <xslt:when test="contains($qname,':')">
 
822
        <xslt:variable name="prefix" select="substring-before($qname,':')"/>
 
823
        <xslt:variable name="localName" select="substring-after($qname,':')"/>
 
824
        <xslt:choose>
 
825
          <xslt:when test="//xsdxt:link[(@qname = $qname) and (@rel = 'schema')]">
 
826
            <xslt:call-template name="Anchor">
 
827
              <xslt:with-param name="href"  select="//xsdxt:link[(@qname = $qname) and (@rel = 'schema')]/@href"/>
 
828
              <xslt:with-param name="title" select="concat('See ',$localName)"/>
 
829
            </xslt:call-template>
 
830
          </xslt:when>
 
831
          <xslt:when test="$prefix = $targetPrefix">
 
832
            <xslt:call-template name="Anchor">
 
833
              <xslt:with-param name="href"><xslt:call-template name="QNameToLocalAnchor"/></xslt:with-param>
 
834
              <xslt:with-param name="title" select="concat('See ',$localName)"/>
 
835
            </xslt:call-template>
 
836
          </xslt:when>
 
837
          <xslt:when test="$prefix = $schemaPrefix">
 
838
            <xslt:call-template name="Anchor">
 
839
              <xslt:with-param name="href"><xslt:call-template name="QNameToXSDAnchor"/></xslt:with-param>
 
840
              <xslt:with-param name="title" select="concat('See ',$localName)"/>
 
841
            </xslt:call-template>
 
842
          </xslt:when>
 
843
           <xslt:otherwise>
 
844
             <xslt:call-template name="Anchor">
 
845
               <xslt:with-param name="href"><xslt:call-template name="QNameToForeignAnchor"/></xslt:with-param>
 
846
               <xslt:with-param name="title" select="concat('See ',$localName)"/>
 
847
             </xslt:call-template>
 
848
           </xslt:otherwise>
 
849
        </xslt:choose>
 
850
      </xslt:when>
 
851
      <xslt:otherwise>
 
852
        <xslt:value-of select="."/>
 
853
      </xslt:otherwise>
 
854
    </xslt:choose>
 
855
  </xslt:template>
 
856
 
 
857
  <!-- Write an anchor if it's defined for the current node -->
 
858
  <xslt:template name="Anchor">
 
859
    <xslt:param name="href" /> <!-- if empty don't make an anchor -->
 
860
    <xslt:param name="title">
 
861
      <xslt:if test="@name">
 
862
        <xslt:value-of select="concat('See ',@name)"/>
 
863
      </xslt:if>
 
864
    </xslt:param>
 
865
    <xslt:param name="content" select="."/>
 
866
    <xslt:choose>
 
867
      <xslt:when test="string-length($href) != 0">
 
868
        <xslt:element name="a">
 
869
          <xslt:attribute name="href"><xslt:value-of select="$href"/></xslt:attribute>
 
870
          <xslt:attribute name="title"><xslt:value-of select="$title"/></xslt:attribute>
 
871
          <xslt:value-of select="$content"/>
 
872
        </xslt:element>
 
873
      </xslt:when>
 
874
      <xslt:otherwise><xslt:value-of select="."/></xslt:otherwise>
 
875
    </xslt:choose>
 
876
  </xslt:template>
 
877
 
 
878
  <!--
 
879
      Given a quname attribute pointing to a forign XSD type return a
 
880
      link if a single import statement exists with a schemaLocation
 
881
      attribute
 
882
  -->
 
883
  <xslt:template name="QNameToForeignAnchor">
 
884
    <xslt:param name="qname" select="normalize-space(.)"/>
 
885
    <xslt:param name="localName" select="substring-after($qname, ':')"/>
 
886
    <xslt:param name="prefix" select="substring-before($qname, ':')"/>
 
887
    <xslt:if test="namespace-uri(..) = $schemaNamespace">
 
888
      <xslt:variable name="namespace">
 
889
        <xslt:for-each select="/xsd:schema/namespace::node()">
 
890
          <xslt:if test="name(.)=$prefix">
 
891
            <xslt:value-of select="."/>
 
892
          </xslt:if>
 
893
        </xslt:for-each>
 
894
      </xslt:variable>
 
895
      <xslt:if test="(string-length($namespace) > 0) and
 
896
                     (count(/xsd:schema/xsd:import[@namespace = $namespace]) = 1) and
 
897
                     /xsd:schema/xsd:import[@namespace = $namespace]/@schemaLocation
 
898
                     ">
 
899
        <xslt:value-of select="/xsd:schema/xsd:import[@namespace = $namespace]/@schemaLocation"/>
 
900
      </xslt:if>
 
901
    </xslt:if>
 
902
  </xslt:template>
 
903
 
 
904
  <!--
 
905
      Given a qname attribute pointing to an XSD type, returns an anchor
 
906
      to the XSD definition.  This only works for type references.
 
907
  -->
 
908
  <xslt:template name="QNameToXSDAnchor">
 
909
    <xslt:param name="qname" select="normalize-space(.)"/>
 
910
    <xslt:param name="localName" select="substring-after($qname, ':')"/>
 
911
    <xslt:if test="namespace-uri(..) = $schemaNamespace">
 
912
      <xslt:if test="(local-name(.) = 'type') or (local-name(.) = 'base')">
 
913
        <xslt:value-of select="concat($schemaDatatypeURI,$localName)" />
 
914
      </xslt:if>
 
915
    </xslt:if>
 
916
  </xslt:template>
 
917
 
 
918
  <!--
 
919
     Given a qname attribute, returns an anchor target for that qname,
 
920
     or an empty string if an anchor cannot be generated for whatever
 
921
     reason.
 
922
  -->
 
923
  <xslt:template name="QNameToLocalAnchor">
 
924
    <xslt:param name="qname" select="normalize-space(.)"/>
 
925
    <xslt:param name="localName" select="substring-after($qname, ':')"/>
 
926
    <xslt:if test="namespace-uri(..) = $schemaNamespace">
 
927
      <xslt:choose>
 
928
        <xslt:when test="(local-name(.) = 'type') or
 
929
                         (local-name(.) = 'base') or
 
930
                         (local-name(.) = 'itemType')"><xslt:call-template name="LocalTypeAnchor"><xslt:with-param name="localName" select="$localName"/>
 
931
        </xslt:call-template></xslt:when>
 
932
        <xslt:when test="local-name(.) = 'ref'"><xslt:call-template name="LocalRefAnchor"><xslt:with-param name="localName" select="$localName"/>
 
933
        </xslt:call-template></xslt:when>
 
934
      </xslt:choose>
 
935
    </xslt:if>
 
936
  </xslt:template>
 
937
 
 
938
  <xslt:template name="LocalRefAnchor">
 
939
    <xslt:param name="localName" />
 
940
    <xslt:choose>
 
941
      <!-- Element Reference -->
 
942
      <xslt:when test="local-name(..) = 'element'">
 
943
        <xslt:call-template name="LocalRefAnchorBuilder">
 
944
          <xslt:with-param name="localName" select="$localName"/>
 
945
          <xslt:with-param name="search" select="/xsd:schema/xsd:element[@name= $localName]"/>
 
946
          <xslt:with-param name="refPrefix" select="$elementPrefix"/>
 
947
        </xslt:call-template>
 
948
      </xslt:when>
 
949
      <!-- Attribute Reference -->
 
950
      <xslt:when test="local-name(..) = 'attribute'">
 
951
        <xslt:call-template name="LocalRefAnchorBuilder">
 
952
          <xslt:with-param name="localName" select="$localName"/>
 
953
          <xslt:with-param name="search" select="/xsd:schema/xsd:attribute[@name= $localName]"/>
 
954
          <xslt:with-param name="refPrefix" select="$attributePrefix"/>
 
955
        </xslt:call-template>
 
956
      </xslt:when>
 
957
      <!-- Attribute Group Reference -->
 
958
      <xslt:when test="local-name(..) = 'attributeGroup'">
 
959
        <xslt:call-template name="LocalRefAnchorBuilder">
 
960
          <xslt:with-param name="localName" select="$localName"/>
 
961
          <xslt:with-param name="search" select="/xsd:schema/xsd:attributeGroup[@name= $localName]"/>
 
962
          <xslt:with-param name="refPrefix" select="$attributeGroupPrefix"/>
 
963
        </xslt:call-template>
 
964
      </xslt:when>
 
965
      <!-- Group Reference -->
 
966
      <xslt:when test="local-name(..) = 'group'">
 
967
        <xslt:call-template name="LocalRefAnchorBuilder">
 
968
          <xslt:with-param name="localName" select="$localName"/>
 
969
          <xslt:with-param name="search" select="/xsd:schema/xsd:group[@name= $localName]"/>
 
970
          <xslt:with-param name="refPrefix" select="$groupPrefix"/>
 
971
        </xslt:call-template>
 
972
      </xslt:when>
 
973
    </xslt:choose>
 
974
  </xslt:template>
 
975
 
 
976
  <xslt:template  name="LocalRefAnchorBuilder">
 
977
    <xslt:param name="localName" />
 
978
    <xslt:param name="search" />
 
979
    <xslt:param name="refPrefix" />
 
980
    <xslt:choose>
 
981
      <xslt:when test="$search">
 
982
        <xslt:value-of select="concat('#',$refPrefix,$localName)"/>
 
983
      </xslt:when>
 
984
      <!--
 
985
          If we have a single incude then we assume it's
 
986
          included...
 
987
      -->
 
988
      <xslt:when test="count(/xsd:schema/xsd:include) = 1"><xslt:value-of
 
989
      select="concat(/xsd:schema/xsd:include/@schemaLocation,'#',$refPrefix,$localName)"/></xslt:when>
 
990
    </xslt:choose>
 
991
  </xslt:template>
 
992
 
 
993
  <!--
 
994
     Given a local name as a pram, returns a local "type" anchor or an
 
995
     empty string if one cannot be generated.
 
996
  -->
 
997
  <xslt:template name="LocalTypeAnchor">
 
998
    <xslt:param name="localName" />
 
999
    <xslt:choose>
 
1000
      <!-- Search the types -->
 
1001
      <xslt:when
 
1002
          test="/xsd:schema/xsd:complexType[@name = $localName] or
 
1003
                /xsd:schema/xsd:simpleType[@name = $localName]"
 
1004
          ><xslt:value-of select="concat('#',$typePrefix,$localName)"/></xslt:when>
 
1005
      <!--
 
1006
           If we haven't hit yet see if we have an include.
 
1007
           Currently this only works with a single include.
 
1008
      -->
 
1009
      <xslt:when
 
1010
          test="count(/xsd:schema/xsd:include) = 1"><xslt:value-of
 
1011
          select="concat(/xsd:schema/xsd:include/@schemaLocation,'#',$typePrefix,$localName)"/></xslt:when>
 
1012
      <!-- Can't tell so send an empty string... -->
 
1013
      <xslt:otherwise />
 
1014
    </xslt:choose>
 
1015
  </xslt:template>
 
1016
 
 
1017
  <!-- Internal sequences -->
 
1018
  <xslt:template match="xsd:sequence">
 
1019
    <div class="Sequence">
 
1020
       <span class="h4">Sequence</span>
 
1021
       <xslt:call-template name="AttribsAndDocs" />
 
1022
       <xslt:apply-templates />
 
1023
    </div>
 
1024
  </xslt:template>
 
1025
 
 
1026
  <xslt:template name="SubItem">
 
1027
    <xslt:param name="name" />
 
1028
    <div class="SubItem">
 
1029
      <div class="SubItemProps">
 
1030
        <div class="SubName">
 
1031
          <xslt:value-of select="$name"/>
 
1032
        </div>
 
1033
        <xslt:call-template name="Attribs">
 
1034
          <xslt:with-param name="isSubItem" select="true()"/>
 
1035
        </xslt:call-template>
 
1036
      </div>
 
1037
      <xslt:call-template name="Docs">
 
1038
        <xslt:with-param name="isSubItem" select="true()"/>
 
1039
      </xslt:call-template>
 
1040
    </div>
 
1041
  </xslt:template>
 
1042
 
 
1043
  <xslt:template match="xsd:element">
 
1044
    <xslt:call-template name="SubItem">
 
1045
      <xslt:with-param name="name">
 
1046
        <xslt:choose>
 
1047
          <xslt:when test="@name">
 
1048
            <xslt:call-template name="StringToElementName">
 
1049
              <xslt:with-param name="inString" select="@name"/>
 
1050
            </xslt:call-template>
 
1051
          </xslt:when>
 
1052
          <xslt:when test="@ref">
 
1053
            <xslt:variable name="elementName" select="substring-after(@ref,':')"/>
 
1054
            <xslt:call-template name="StringToElementName">
 
1055
              <xslt:with-param name="inString" select="$elementName"/>
 
1056
            </xslt:call-template>
 
1057
          </xslt:when>
 
1058
        </xslt:choose>
 
1059
      </xslt:with-param>
 
1060
    </xslt:call-template>
 
1061
  </xslt:template>
 
1062
 
 
1063
  <xslt:template match="xsd:any">
 
1064
    <xslt:call-template name="SubItem">
 
1065
      <xslt:with-param name="name">
 
1066
        <xslt:text>&lt;?&gt; (Any Element)</xslt:text>
 
1067
      </xslt:with-param>
 
1068
    </xslt:call-template>
 
1069
  </xslt:template>
 
1070
 
 
1071
  <xslt:template match="xsd:anyAttribute">
 
1072
    <xslt:call-template name="SubItem">
 
1073
      <xslt:with-param name="name">
 
1074
        <xslt:text>@? (Any Attribute)</xslt:text>
 
1075
      </xslt:with-param>
 
1076
    </xslt:call-template>
 
1077
  </xslt:template>
 
1078
 
 
1079
  <xslt:template match="xsd:restriction">
 
1080
    <div class="SubName">
 
1081
      <xslt:text>restriction</xslt:text>
 
1082
    </div>
 
1083
    <table summary="Restriction Props and Attributes">
 
1084
      <tbody>
 
1085
        <xslt:for-each select="@*">
 
1086
          <xslt:sort select="local-name(.)"/>
 
1087
          <xslt:if test="local-name(.) != 'name'">
 
1088
            <tr>
 
1089
              <td><xslt:value-of select="local-name(.)"/></td>
 
1090
              <td><xslt:call-template name="QNameToLink"/></td>
 
1091
            </tr>
 
1092
          </xslt:if>
 
1093
        </xslt:for-each>
 
1094
 
 
1095
        <!-- simple restrictions -->
 
1096
        <xslt:for-each select="xsd:minExclusive | xsd:minInclusive   |
 
1097
                               xsd:maxExclusive | xsd:maxInclusive   |
 
1098
                               xsd:totalDigits  | xsd:fractionDigits |
 
1099
                               xsd:length       | xsd:minLength      |
 
1100
                               xsd:maxLength    | xsd:minLength      |
 
1101
                               xsd:whitespace   | xsd:pattern
 
1102
                               ">
 
1103
          <tr>
 
1104
            <td><xslt:value-of select="local-name(.)"/></td>
 
1105
            <xslt:call-template name="DisplaySimpleRestriction"/>
 
1106
          </tr>
 
1107
        </xslt:for-each>
 
1108
 
 
1109
        <xslt:if test="xsd:enumeration">
 
1110
          <tr>
 
1111
            <td>enum values</td>
 
1112
            <xslt:call-template name="DisplayEnumeration">
 
1113
              <xslt:with-param name="enum" select="xsd:enumeration[1]"/>
 
1114
            </xslt:call-template>
 
1115
          </tr>
 
1116
          <xslt:for-each select="xsd:enumeration">
 
1117
            <xslt:if test="@value != ../xsd:enumeration[1]/@value">
 
1118
              <tr>
 
1119
                <td></td>
 
1120
                <xslt:call-template name="DisplayEnumeration"/>
 
1121
              </tr>
 
1122
            </xslt:if>
 
1123
          </xslt:for-each>
 
1124
        </xslt:if>
 
1125
      </tbody>
 
1126
    </table>
 
1127
 
 
1128
    <!--
 
1129
        Copy restriction docs documentation...
 
1130
    -->
 
1131
    <xslt:if test="xsd:annotation/xsd:documentation">
 
1132
      <xslt:apply-templates select="xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
1133
    </xslt:if>
 
1134
 
 
1135
    <!--
 
1136
        Apply templates for unhandled children
 
1137
    -->
 
1138
    <xslt:apply-templates select="xsd:simpleType     | xsd:group     |
 
1139
                                  xsd:all            | xsd:choice    |
 
1140
                                  xsd:sequence       | xsd:attribute |
 
1141
                                  xsd:attributeGroup | xsd:anyAttribute" />
 
1142
  </xslt:template>
 
1143
 
 
1144
  <!--
 
1145
      Displays an enumeration in a table...
 
1146
  -->
 
1147
  <xslt:template name="DisplayEnumeration">
 
1148
    <xslt:param name="enum" select="." />
 
1149
    <td>
 
1150
      <div class="Enum">
 
1151
        <div class="EnumValue">
 
1152
          <xslt:value-of select="$enum/@value"/>
 
1153
          <xslt:if test="$enum/@id">
 
1154
            <xslt:text> (id = </xslt:text>
 
1155
            <xslt:value-of select="$enum/@id"/>
 
1156
            <xslt:text>)</xslt:text>
 
1157
          </xslt:if>
 
1158
        </div>
 
1159
        <xslt:if test="$enum/xsd:annotation/xsd:documentation">
 
1160
          <div class="EnumDoc">
 
1161
            <xslt:apply-templates select="$enum/xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
1162
          </div>
 
1163
        </xslt:if>
 
1164
      </div>
 
1165
    </td>
 
1166
  </xslt:template>
 
1167
 
 
1168
  <!--
 
1169
      A Simple restriction in a table fragment.
 
1170
  -->
 
1171
  <xslt:template name="DisplaySimpleRestriction">
 
1172
    <xslt:param name="restriction" select="." />
 
1173
    <td>
 
1174
      <xslt:value-of select="$restriction/@value"/>
 
1175
      <xslt:if test="$restriction/@id">
 
1176
        <xslt:text> (id = </xslt:text>
 
1177
        <xslt:value-of select="$restriction/@id"/>
 
1178
        <xslt:text>)</xslt:text>
 
1179
      </xslt:if>
 
1180
      <xslt:if test="$restriction/@fixed = 'true'">
 
1181
        <xslt:text> (fixed)</xslt:text>
 
1182
      </xslt:if>
 
1183
    </td>
 
1184
    <xslt:if test="$restriction/xsd:annotation/xsd:documentation">
 
1185
      <td>
 
1186
        <xslt:apply-templates select="$restriction/xsd:annotation/xsd:documentation/*" mode="Docs"/>
 
1187
      </td>
 
1188
    </xslt:if>
 
1189
  </xslt:template>
 
1190
 
 
1191
  <!-- Catch all for the missed elements -->
 
1192
  <xslt:template match="xsd:*">
 
1193
    <xslt:if test="local-name(.) != 'annotation'">
 
1194
      <div class="SubElementName">
 
1195
        <xslt:value-of select="local-name(.)"/>
 
1196
      </div>
 
1197
      <xslt:call-template name="AttribsAndDocs" />
 
1198
      <div class="SubElementContent">
 
1199
        <xslt:apply-templates />
 
1200
      </div>
 
1201
    </xslt:if>
 
1202
  </xslt:template>
 
1203
 
 
1204
  <xslt:template match="xsd:attribute">
 
1205
    <xslt:call-template name="SubItem">
 
1206
      <xslt:with-param name="name">
 
1207
        <xslt:choose>
 
1208
          <xslt:when test="@name">
 
1209
            <xslt:call-template name="StringToAttributeName">
 
1210
              <xslt:with-param name="inString" select="@name"/>
 
1211
            </xslt:call-template>
 
1212
          </xslt:when>
 
1213
          <xslt:when test="@ref">
 
1214
            <xslt:variable name="attribName" select="substring-after(@ref,':')"/>
 
1215
            <xslt:call-template name="StringToAttributeName">
 
1216
              <xslt:with-param name="inString" select="$attribName"/>
 
1217
            </xslt:call-template>
 
1218
          </xslt:when>
 
1219
        </xslt:choose>
 
1220
      </xslt:with-param>
 
1221
    </xslt:call-template>
 
1222
  </xslt:template>
 
1223
 
 
1224
  <!-- ignore other text -->
 
1225
  <xslt:template match="text()" />
 
1226
 
 
1227
  <!-- Convert a string to a name -->
 
1228
  <xslt:template name="StringToName">
 
1229
    <xslt:param name="inString" select="@name" />
 
1230
    <xslt:param name="inNode" select="." />
 
1231
 
 
1232
    <xslt:choose>
 
1233
      <!-- element names handled with StringToElementName -->
 
1234
      <xslt:when test="(local-name($inNode) = 'element') and
 
1235
                       (namespace-uri($inNode) = $schemaNamespace)
 
1236
                       ">
 
1237
        <xslt:call-template name="StringToElementName">
 
1238
          <xslt:with-param name="inString" select="$inString"/>
 
1239
        </xslt:call-template>
 
1240
      </xslt:when>
 
1241
 
 
1242
      <!-- attribute names handled with StringToAttributeName -->
 
1243
      <xslt:when test="(local-name($inNode) = 'attribute') and
 
1244
                       (namespace-uri($inNode) = $schemaNamespace)
 
1245
                       ">
 
1246
        <xslt:call-template name="StringToAttributeName">
 
1247
          <xslt:with-param name="inString" select="$inString"/>
 
1248
        </xslt:call-template>
 
1249
      </xslt:when>
 
1250
 
 
1251
      <xslt:otherwise>
 
1252
        <xslt:value-of select="@name"/>
 
1253
      </xslt:otherwise>
 
1254
    </xslt:choose>
 
1255
  </xslt:template>
 
1256
 
 
1257
  <!-- Convert a string to an element name -->
 
1258
  <xslt:template name="StringToElementName">
 
1259
    <xslt:param name="inString" />
 
1260
    <xslt:text>&lt;</xslt:text>
 
1261
    <xslt:value-of select="$inString" />
 
1262
    <xslt:text>&gt;</xslt:text>
 
1263
  </xslt:template>
 
1264
 
 
1265
  <!-- Convert a string to an attribute name -->
 
1266
  <xslt:template name="StringToAttributeName">
 
1267
    <xslt:param name="inString" />
 
1268
    <xslt:text>@</xslt:text>
 
1269
    <xslt:value-of select="$inString" />
 
1270
  </xslt:template>
 
1271
 
 
1272
  <!--
 
1273
    Convert a string parameter to an escapted Javascript string in
 
1274
    quotes.
 
1275
  -->
 
1276
  <xslt:template name="StringToJavascript">
 
1277
    <xslt:param name="inString" />
 
1278
    <!-- quote the string -->
 
1279
    <xslt:variable name="quotedString"
 
1280
                   select="concat($dQuote,translate($inString,$dQuote,$sQuote),$dQuote)"/>
 
1281
    <!-- replace linefeeds with \n -->
 
1282
    <xslt:variable name="lfString">
 
1283
      <xslt:call-template name="ReplaceText">
 
1284
        <xslt:with-param name="inString" select="$quotedString"/>
 
1285
        <xslt:with-param name="searchString" select="'&#x0a;'"/>
 
1286
        <xslt:with-param name="replaceString" select="'\n'"/>
 
1287
      </xslt:call-template>
 
1288
    </xslt:variable>
 
1289
    <!-- replace tabs with 5 spaces -->
 
1290
    <xslt:variable name="tabString">
 
1291
      <xslt:call-template name="ReplaceText">
 
1292
        <xslt:with-param name="inString" select="$lfString"/>
 
1293
        <xslt:with-param name="searchString" select="'&#x09;'"/>
 
1294
        <xslt:with-param name="replaceString" select="'     '"/>
 
1295
      </xslt:call-template>
 
1296
    </xslt:variable>
 
1297
    <!-- remove carrige returns -->
 
1298
    <xslt:variable name="crString" select="translate($tabString,'&#x0d;','')"/>
 
1299
    <!-- replace < with unicode sequence -->
 
1300
    <xslt:variable name="ltString">
 
1301
      <xslt:call-template name="ReplaceText">
 
1302
        <xslt:with-param name="inString" select="$crString"/>
 
1303
        <xslt:with-param name="searchString" select="'&#x3c;'"/>
 
1304
        <xslt:with-param name="replaceString" select="'\u003c'"/>
 
1305
      </xslt:call-template>
 
1306
    </xslt:variable>
 
1307
    <!-- replace > with unicode sequence -->
 
1308
    <xslt:variable name="gtString">
 
1309
      <xslt:call-template name="ReplaceText">
 
1310
        <xslt:with-param name="inString" select="$ltString"/>
 
1311
        <xslt:with-param name="searchString" select="'&#x3e;'"/>
 
1312
        <xslt:with-param name="replaceString" select="'\u003e'"/>
 
1313
      </xslt:call-template>
 
1314
    </xslt:variable>
 
1315
    <xslt:value-of select="$gtString"/>
 
1316
  </xslt:template>
 
1317
 
 
1318
  <!--
 
1319
     Simple search and replace
 
1320
  -->
 
1321
  <xslt:template name="ReplaceText">
 
1322
    <xslt:param name="inString" />
 
1323
    <xslt:param name="searchString"/>
 
1324
    <xslt:param name="replaceString"/>
 
1325
 
 
1326
    <xslt:choose>
 
1327
      <xslt:when test="$searchString and
 
1328
                       contains($inString, $searchString)">
 
1329
        <xslt:value-of select="substring-before($inString, $searchString)"/>
 
1330
        <xslt:value-of select="$replaceString"/>
 
1331
        <xslt:call-template name="ReplaceText">
 
1332
          <xslt:with-param name="inString" select="substring-after($inString, $searchString)"/>
 
1333
          <xslt:with-param name="searchString" select="$searchString"/>
 
1334
          <xslt:with-param name="replaceString" select="$replaceString"/>
 
1335
        </xslt:call-template>
 
1336
      </xslt:when>
 
1337
      <xslt:otherwise>
 
1338
        <xslt:value-of select="$inString"/>
 
1339
      </xslt:otherwise>
 
1340
    </xslt:choose>
 
1341
  </xslt:template>
 
1342
</xslt:stylesheet>