Debian Codegraph @

samples/generate-wadl/src/main/doc/wadl_documentation.xsl

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
6 Copyright (c) 2006-2013 Oracle and/or its affiliates. All rights reserved.
7
8 The contents of this file are subject to the terms of either the GNU
9 General Public License Version 2 only ("GPL") or the Common Development
10 and Distribution License("CDDL") (collectively, the "License"). You
11 may not use this file except in compliance with the License. You can
12 obtain a copy of the License at
13 http://glassfish.java.net/public/CDDL+GPL_1_1.html
14 or packager/legal/LICENSE.txt. See the License for the specific
15 language governing permissions and limitations under the License.
16
17 When distributing the software, include this License Header Notice in each
18 file and include the License file at packager/legal/LICENSE.txt.
19
20 GPL Classpath Exception:
21 Oracle designates this particular file as subject to the "Classpath"
22 exception as provided by Oracle in the GPL Version 2 section of the License
23 file that accompanied this code.
24
25 Modifications:
26 If applicable, add the following below the License Header, with the fields
27 enclosed by brackets [] replaced by your own identifying information:
28 "Portions Copyright [year] [name of copyright owner]"
29
30 Contributor(s):
31 If you wish your version of this file to be governed by only the CDDL or
32 only the GPL Version 2, indicate your decision by adding "[Contributor]
33 elects to include this software in this distribution under the [CDDL or GPL
34 Version 2] license." If you don't indicate a single choice of license, a
35 recipient has the option to distribute your version of this file under
36 either the CDDL, the GPL Version 2 or to extend the choice of license to
37 its licensees as provided above. However, if you add GPL Version 2 code
38 and therefore, elected the GPL Version 2 license, then the option applies
39 only if the new code is made subject to such option by the copyright
40 holder.
41
42 -->
43
44 <!--
45 * FIXME
46 - Doesn't inherit query/header params from resource/@type
47 - XML schema import, include, redefine don't import
48 -->
49 <!--
50 * TODO
51 - forms
52 - link to or include non-schema variable type defs (as a separate list?)
53 - @href error handling
54 -->
55
56 <xsl:stylesheet
57 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
58 xmlns:wadl="http://wadl.dev.java.net/2009/02"
59 xmlns:xs="http://www.w3.org/2001/XMLSchema"
60 xmlns:html="http://www.w3.org/1999/xhtml"
61 xmlns:exsl="http://exslt.org/common"
62 xmlns:ns="urn:namespace"
63 extension-element-prefixes="exsl"
64 xmlns="http://www.w3.org/1999/xhtml"
65 exclude-result-prefixes="xsl wadl xs html ns"
66 >
67
68 <xsl:output
69 method="html"
70 encoding="UTF-8"
71 indent="yes"
72 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
73 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
74 />
75
76 <xsl:variable name="wadl-ns">http://research.sun.com/wadl/2006/10</xsl:variable>
77
78
79 <!-- expand @hrefs, @types into a full tree -->
80
81 <xsl:variable name="resources">
82 <xsl:apply-templates select="/wadl:application/wadl:resources" mode="expand"/>
83 </xsl:variable>
84
85 <xsl:template match="wadl:resources" mode="expand">
86 <xsl:variable name="base">
87 <xsl:choose>
88 <xsl:when test="substring(@base, string-length(@base), 1) = '/'">
89 <xsl:value-of select="substring(@base, 1, string-length(@base) - 1)"/>
90 </xsl:when>
91 <xsl:otherwise><xsl:value-of select="@base"/></xsl:otherwise>
92 </xsl:choose>
93 </xsl:variable>
94 <xsl:element name="resources" namespace="{$wadl-ns}">
95 <xsl:for-each select="namespace::*">
96 <xsl:variable name="prefix" select="name(.)"/>
97 <xsl:if test="$prefix">
98 <xsl:attribute name="ns:{$prefix}"><xsl:value-of select="."/></xsl:attribute>
99 </xsl:if>
100 </xsl:for-each>
101 <xsl:apply-templates select="@*|node()" mode="expand">
102 <xsl:with-param name="base" select="$base"/>
103 </xsl:apply-templates>
104 </xsl:element>
105 </xsl:template>
106
107 <xsl:template match="wadl:resource[@type]" mode="expand">
108 <xsl:param name="base"></xsl:param>
109 <xsl:variable name="uri" select="substring-before(@type, '#')"/>
110 <xsl:variable name="id" select="substring-after(@type, '#')"/>
111 <xsl:element name="resource" namespace="{$wadl-ns}">
112 <xsl:choose>
113 <xsl:when test="$uri">
114 <xsl:variable name="included" select="document($uri, /)"/>
115 <xsl:copy-of select="$included/descendant::wadl:resource_type[@id=$id]/@*"/>
116 <xsl:attribute name="id"><xsl:value-of select="@type"/></xsl:attribute>
117 <xsl:apply-templates select="$included/descendant::wadl:resource_type[@id=$id]/*" mode="expand">
118 <xsl:with-param name="base" select="$uri"/>
119 </xsl:apply-templates>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:copy-of select="//resource_type[@id=$id]/@*"/>
123 <xsl:attribute name="id"><xsl:value-of select="$base"/>#<xsl:value-of select="@type"/></xsl:attribute>
124 <xsl:apply-templates select="//wadl:resource_type[@id=$id]/*" mode="expand">
125 <xsl:with-param name="base" select="$base"/>
126 </xsl:apply-templates>
127 </xsl:otherwise>
128 </xsl:choose>
129 <xsl:apply-templates select="node()" mode="expand">
130 <xsl:with-param name="base" select="$base"/>
131 </xsl:apply-templates>
132 </xsl:element>
133 </xsl:template>
134
135 <xsl:template match="wadl:*[@href]" mode="expand">
136 <xsl:param name="base"></xsl:param>
137 <xsl:variable name="uri" select="substring-before(@href, '#')"/>
138 <xsl:variable name="id" select="substring-after(@href, '#')"/>
139 <xsl:element name="{local-name()}" namespace="{$wadl-ns}">
140 <xsl:copy-of select="@*"/>
141 <xsl:choose>
142 <xsl:when test="$uri">
143 <xsl:attribute name="id"><xsl:value-of select="@href"/></xsl:attribute>
144 <xsl:variable name="included" select="document($uri, /)"/>
145 <xsl:apply-templates select="$included/descendant::wadl:*[@id=$id]/*" mode="expand">
146 <xsl:with-param name="base" select="$uri"/>
147 </xsl:apply-templates>
148 </xsl:when>
149 <xsl:otherwise>
150 <xsl:attribute name="id"><xsl:value-of select="$base"/>#<xsl:value-of select="$id"/></xsl:attribute>
151 <!-- xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute -->
152 <xsl:attribute name="element"><xsl:value-of select="//wadl:*[@id=$id]/@element"/></xsl:attribute>
153 <xsl:attribute name="mediaType"><xsl:value-of select="//wadl:*[@id=$id]/@mediaType"/></xsl:attribute>
154 <xsl:apply-templates select="//wadl:*[@id=$id]/*" mode="expand">
155 <xsl:with-param name="base" select="$base"/>
156 </xsl:apply-templates>
157 </xsl:otherwise>
158 </xsl:choose>
159 </xsl:element>
160 </xsl:template>
161
162 <xsl:template match="node()[@id]" mode="expand">
163 <xsl:param name="base"></xsl:param>
164 <xsl:element name="{local-name()}" namespace="{$wadl-ns}">
165 <xsl:copy-of select="@*"/>
166 <xsl:attribute name="id"><xsl:value-of select="$base"/>#<xsl:value-of select="@id"/></xsl:attribute>
167 <!-- xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute -->
168 <xsl:apply-templates select="node()" mode="expand">
169 <xsl:with-param name="base" select="$base"/>
170 </xsl:apply-templates>
171 </xsl:element>
172 </xsl:template>
173
174 <xsl:template match="@*|node()" mode="expand">
175 <xsl:param name="base"></xsl:param>
176 <xsl:copy>
177 <xsl:apply-templates select="@*|node()" mode="expand">
178 <xsl:with-param name="base" select="$base"/>
179 </xsl:apply-templates>
180 </xsl:copy>
181 </xsl:template>
182
183 <!-- debug $resources
184 <xsl:template match="/">
185 <xsl:copy-of select="$resources"/>
186 </xsl:template>
187 -->
188
189 <!-- collect grammars (TODO: walk over $resources instead) -->
190
191 <xsl:variable name="grammars">
192 <xsl:copy-of select="/wadl:application/wadl:grammars/*[not(namespace-uri()=$wadl-ns)]"/>
193 <xsl:apply-templates select="/wadl:application/wadl:grammars/wadl:include[@href]" mode="include-grammar"/>
194 <xsl:apply-templates select="/wadl:application/wadl:resources/descendant::wadl:resource[@type]" mode="include-href"/>
195 <xsl:apply-templates select="exsl:node-set($resources)/descendant::wadl:*[@href]" mode="include-href"/>
196 </xsl:variable>
197
198 <xsl:template match="wadl:include[@href]" mode="include-grammar">
199 <xsl:variable name="included" select="document(@href, /)/*"></xsl:variable>
200 <xsl:element name="wadl:include">
201 <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
202 <xsl:copy-of select="$included"/> <!-- FIXME: xml-schema includes, etc -->
203 </xsl:element>
204 </xsl:template>
205
206 <xsl:template match="wadl:*[@href]" mode="include-href">
207 <xsl:variable name="uri" select="substring-before(@href, '#')"/>
208 <xsl:if test="$uri">
209 <xsl:variable name="included" select="document($uri, /)"/>
210 <xsl:copy-of select="$included/wadl:application/wadl:grammars/*[not(namespace-uri()=$wadl-ns)]"/>
211 <xsl:apply-templates select="$included/descendant::wadl:include[@href]" mode="include-grammar"/>
212 <xsl:apply-templates select="$included/wadl:application/wadl:resources/descendant::wadl:resource[@type]" mode="include-href"/>
213 <xsl:apply-templates select="$included/wadl:application/wadl:resources/descendant::wadl:*[@href]" mode="include-href"/>
214 </xsl:if>
215 </xsl:template>
216
217 <xsl:template match="wadl:resource[@type]" mode="include-href">
218 <xsl:variable name="uri" select="substring-before(@type, '#')"/>
219 <xsl:if test="$uri">
220 <xsl:variable name="included" select="document($uri, /)"/>
221 <xsl:copy-of select="$included/wadl:application/wadl:grammars/*[not(namespace-uri()=$wadl-ns)]"/>
222 <xsl:apply-templates select="$included/descendant::wadl:include[@href]" mode="include-grammar"/>
223 <xsl:apply-templates select="$included/wadl:application/wadl:resources/descendant::wadl:resource[@type]" mode="include-href"/>
224 <xsl:apply-templates select="$included/wadl:application/wadl:resources/descendant::wadl:*[@href]" mode="include-href"/>
225 </xsl:if>
226 </xsl:template>
227
228 <!-- main template -->
229
230 <xsl:template match="/wadl:application">
231 <html>
232 <head>
233 <title>
234 <xsl:choose>
235 <xsl:when test="wadl:doc[@title]">
236 <xsl:value-of select="wadl:doc[@title][1]/@title"/>
237 </xsl:when>
238 <xsl:otherwise>My Web Application</xsl:otherwise>
239 </xsl:choose>
240 </title>
241 <style type="text/css">
242 body {
243 font-family: sans-serif;
244 font-size: 0.85em;
245 margin: 2em 8em;
246 }
247 .methods {
248 background-color: #eef;
249 padding: 1em;
250 }
251 h1 {
252 font-size: 2.5em;
253 }
254 h2 {
255 border-bottom: 1px solid black;
256 margin-top: 1em;
257 margin-bottom: 0.5em;
258 font-size: 2em;
259 }
260 h3 {
261 color: orange;
262 font-size: 1.75em;
263 margin-top: 1.25em;
264 margin-bottom: 0em;
265 }
266 h4 {
267 margin: 0em;
268 padding: 0em;
269 border-bottom: 2px solid white;
270 }
271 h6 {
272 font-size: 1.1em;
273 color: #99a;
274 margin: 0.5em 0em 0.25em 0em;
275 }
276 code {
277 font-size: 1.2em;
278 color: #111166;
279 }
280 pre {
281 padding-left: 2em;
282 }
283 dd {
284 margin-left: 1em;
285 }
286 tt {
287 font-size: 1.2em;
288 }
289 table {
290 margin-bottom: 0.5em;
291 }
292 th {
293 text-align: left;
294 font-weight: normal;
295 color: black;
296 border-bottom: 1px solid black;
297 padding: 3px 6px;
298 }
299 td {
300 padding: 3px 6px;
301 vertical-align: top;
302 background-color: f6f6ff;
303 font-size: 0.85em;
304 }
305 td p {
306 margin: 0px;
307 }
308 ul {
309 padding-left: 1.75em;
310 }
311 p + ul, p + ol, p + dl {
312 margin-top: 0em;
313 }
314 .optional {
315 font-weight: normal;
316 opacity: 0.75;
317 }
318 </style>
319 </head>
320 <body>
321 <h1>
322 <xsl:choose>
323 <xsl:when test="wadl:doc[@title]">
324 <xsl:value-of select="wadl:doc[@title][1]/@title"/>
325 </xsl:when>
326 <xsl:otherwise>My Web Application</xsl:otherwise>
327 </xsl:choose>
328 </h1>
329 <xsl:apply-templates select="wadl:doc"/>
330 <ul>
331 <li><a href="#resources">Resources</a>
332 <xsl:apply-templates select="exsl:node-set($resources)" mode="toc"/>
333 </li>
334 <li><a href="#representations">Representations</a>
335 <ul>
336 <xsl:apply-templates select="exsl:node-set($resources)/descendant::wadl:representation" mode="toc"/>
337 </ul>
338 </li>
339 <xsl:if test="descendant::wadl:fault">
340 <li><a href="#faults">Faults</a>
341 <ul>
342 <xsl:apply-templates select="exsl:node-set($resources)/descendant::wadl:fault" mode="toc"/>
343 </ul>
344 </li>
345 </xsl:if>
346 </ul>
347 <h2 id="resources">Resources</h2>
348 <xsl:apply-templates select="exsl:node-set($resources)" mode="list"/>
349 <h2 id="representations">Representations</h2>
350 <xsl:apply-templates select="exsl:node-set($resources)/descendant::wadl:representation" mode="list"/>
351 <xsl:if test="exsl:node-set($resources)/descendant::wadl:fault"><h2 id="faults">Faults</h2>
352 <xsl:apply-templates select="exsl:node-set($resources)/descendant::wadl:fault" mode="list"/>
353 </xsl:if>
354 </body>
355 </html>
356 </xsl:template>
357
358 <!-- Table of Contents -->
359
360 <xsl:template match="wadl:resources" mode="toc">
361 <xsl:variable name="base">
362 <xsl:choose>
363 <xsl:when test="substring(@base, string-length(@base), 1) = '/'">
364 <xsl:value-of select="substring(@base, 1, string-length(@base) - 1)"/>
365 </xsl:when>
366 <xsl:otherwise><xsl:value-of select="@base"/></xsl:otherwise>
367 </xsl:choose>
368 </xsl:variable>
369 <ul>
370 <xsl:apply-templates select="wadl:resource" mode="toc">
371 <xsl:with-param name="context"><xsl:value-of select="$base"/></xsl:with-param>
372 </xsl:apply-templates>
373 </ul>
374 </xsl:template>
375
376 <xsl:template match="wadl:resource" mode="toc">
377 <xsl:param name="context"/>
378 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
379 <xsl:variable name="name"><xsl:value-of select="$context"/>/<xsl:value-of select="@path"/></xsl:variable>
380 <li><a href="#{$id}"><xsl:value-of select="$name"/></a>
381 <xsl:if test="wadl:resource">
382 <ul>
383 <xsl:apply-templates select="wadl:resource" mode="toc">
384 <xsl:with-param name="context" select="$name"/>
385 </xsl:apply-templates>
386 </ul>
387 </xsl:if>
388 </li>
389 </xsl:template>
390
391 <xsl:template match="wadl:representation|wadl:fault" mode="toc">
392 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
393 <xsl:variable name="href" select="@id"/>
394 <xsl:choose>
395 <xsl:when test="preceding::wadl:*[@id=$href]"/>
396 <xsl:otherwise>
397 <li>
398 <a href="#{$id}">
399 <xsl:call-template name="representation-name"/>
400 </a>
401 </li>
402 </xsl:otherwise>
403 </xsl:choose>
404 </xsl:template>
405
406 <!-- Listings -->
407
408 <xsl:template match="wadl:resources" mode="list">
409 <xsl:variable name="base">
410 <xsl:choose>
411 <xsl:when test="substring(@base, string-length(@base), 1) = '/'">
412 <xsl:value-of select="substring(@base, 1, string-length(@base) - 1)"/>
413 </xsl:when>
414 <xsl:otherwise><xsl:value-of select="@base"/></xsl:otherwise>
415 </xsl:choose>
416 </xsl:variable>
417 <xsl:apply-templates select="wadl:resource" mode="list"/>
418
419 </xsl:template>
420
421 <xsl:template match="wadl:resource" mode="list">
422 <xsl:param name="context"/>
423 <xsl:variable name="href" select="@id"/>
424 <xsl:choose>
425 <xsl:when test="preceding::wadl:resource[@id=$href]"/>
426 <xsl:otherwise>
427 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
428 <xsl:variable name="name">
429 <xsl:value-of select="$context"/>/<xsl:value-of select="@path"/>
430 <xsl:for-each select="wadl:param[@style='matrix']">
431 <span class="optional">;<xsl:value-of select="@name"/>=...</span>
432 </xsl:for-each>
433 </xsl:variable>
434 <div class="resource">
435 <h3 id="{$id}">
436 <xsl:choose>
437 <xsl:when test="wadl:doc[@title]"><xsl:value-of select="wadl:doc[@title][1]/@title"/></xsl:when>
438 <xsl:otherwise>
439 <xsl:copy-of select="$name"/>
440 <xsl:for-each select="wadl:method[1]/wadl:request/wadl:param[@style='query']">
441 <xsl:choose>
442 <xsl:when test="@required='true'">
443 <xsl:choose>
444 <xsl:when test="preceding-sibling::wadl:param[@style='query']">&amp;</xsl:when>
445 <xsl:otherwise>?</xsl:otherwise>
446 </xsl:choose>
447 <xsl:value-of select="@name"/>
448 </xsl:when>
449 <xsl:otherwise>
450 <span class="optional">
451 <xsl:choose>
452 <xsl:when test="preceding-sibling::wadl:param[@style='query']">&amp;</xsl:when>
453 <xsl:otherwise>?</xsl:otherwise>
454 </xsl:choose>
455 <xsl:value-of select="@name"/>
456 </span>
457 </xsl:otherwise>
458 </xsl:choose>
459 </xsl:for-each>
460 </xsl:otherwise>
461 </xsl:choose>
462
463 </h3>
464 <xsl:apply-templates select="wadl:doc"/>
465 <xsl:apply-templates select="." mode="param-group">
466 <xsl:with-param name="prefix">resource-wide</xsl:with-param>
467 <xsl:with-param name="style">template</xsl:with-param>
468 </xsl:apply-templates>
469 <xsl:apply-templates select="." mode="param-group">
470 <xsl:with-param name="prefix">resource-wide</xsl:with-param>
471 <xsl:with-param name="style">matrix</xsl:with-param>
472 </xsl:apply-templates>
473 <h6>Methods</h6>
474 <div class="methods">
475 <xsl:apply-templates select="wadl:method"/>
476 </div>
477 </div>
478 <xsl:apply-templates select="wadl:resource" mode="list">
479 <xsl:with-param name="context" select="$name"/>
480 </xsl:apply-templates>
481 </xsl:otherwise>
482 </xsl:choose>
483 </xsl:template>
484
485 <xsl:template match="wadl:method">
486 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
487 <div class="method">
488 <h4 id="{$id}"><xsl:value-of select="@name"/></h4>
489 <xsl:apply-templates select="wadl:doc"/>
490 <xsl:apply-templates select="wadl:request"/>
491 <xsl:apply-templates select="wadl:response"/>
492 </div>
493 </xsl:template>
494
495 <xsl:template match="wadl:request">
496 <xsl:apply-templates select="." mode="param-group">
497 <xsl:with-param name="prefix">request</xsl:with-param>
498 <xsl:with-param name="style">query</xsl:with-param>
499 </xsl:apply-templates>
500 <xsl:apply-templates select="." mode="param-group">
501 <xsl:with-param name="prefix">request</xsl:with-param>
502 <xsl:with-param name="style">header</xsl:with-param>
503 </xsl:apply-templates>
504 <xsl:if test="wadl:representation">
505 <p><em>acceptable request representations:</em></p>
506 <ul>
507 <xsl:apply-templates select="wadl:representation"/>
508 </ul>
509 </xsl:if>
510 </xsl:template>
511
512 <xsl:template match="wadl:response">
513 <xsl:apply-templates select="." mode="param-group">
514 <xsl:with-param name="prefix">response</xsl:with-param>
515 <xsl:with-param name="style">header</xsl:with-param>
516 </xsl:apply-templates>
517 <xsl:if test="wadl:representation">
518 <p><em>available response representations:</em></p>
519 <ul>
520 <xsl:apply-templates select="wadl:representation"/>
521 </ul>
522 </xsl:if>
523 <xsl:if test="wadl:fault">
524 <p><em>potential faults:</em></p>
525 <ul>
526 <xsl:apply-templates select="wadl:fault"/>
527 </ul>
528 </xsl:if>
529 </xsl:template>
530
531 <xsl:template match="wadl:representation|wadl:fault">
532 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
533 <li>
534 <a href="#{$id}">
535 <xsl:call-template name="representation-name"/>
536 </a>
537 </li>
538 </xsl:template>
539
540 <xsl:template match="wadl:representation|wadl:fault" mode="list">
541 <xsl:variable name="id"><xsl:call-template name="get-id"/></xsl:variable>
542 <xsl:variable name="href" select="@id"/>
543 <xsl:variable name="expanded-name">
544 <xsl:call-template name="expand-qname">
545 <xsl:with-param select="@element" name="qname"/>
546 </xsl:call-template>
547 </xsl:variable>
548 <xsl:choose>
549 <xsl:when test="preceding::wadl:*[@id=$href]"/>
550 <xsl:otherwise>
551 <h3 id="{$id}">
552 <xsl:call-template name="representation-name"/>
553 </h3>
554 <xsl:apply-templates select="wadl:doc"/>
555 <xsl:if test="@element or wadl:param">
556 <div class="representation">
557 <xsl:if test="@element">
558 <h6>XML Schema</h6>
559 <xsl:call-template name="get-element">
560 <xsl:with-param name="context" select="."/>
561 <xsl:with-param name="qname" select="@element"/>
562 </xsl:call-template>
563 </xsl:if>
564 <xsl:apply-templates select="." mode="param-group">
565 <xsl:with-param name="style">plain</xsl:with-param>
566 </xsl:apply-templates>
567 <xsl:apply-templates select="." mode="param-group">
568 <xsl:with-param name="style">header</xsl:with-param>
569 </xsl:apply-templates>
570 </div>
571 </xsl:if>
572 </xsl:otherwise>
573 </xsl:choose>
574 </xsl:template>
575
576 <xsl:template match="wadl:*" mode="param-group">
577 <xsl:param name="style"/>
578 <xsl:param name="prefix"></xsl:param>
579 <xsl:if test="ancestor-or-self::wadl:*/wadl:param[@style=$style]">
580 <h6><xsl:value-of select="$prefix"/><xsl:text> </xsl:text><xsl:value-of select="$style"/> parameters</h6>
581 <table>
582 <tr>
583 <th>parameter</th>
584 <th>value</th>
585 <th>description</th>
586 </tr>
587 <xsl:apply-templates select="ancestor-or-self::wadl:*/wadl:param[@style=$style]"/>
588 </table>
589 </xsl:if>
590 </xsl:template>
591
592 <xsl:template match="wadl:param">
593 <tr>
594 <td>
595 <p><strong><xsl:value-of select="@name"/></strong></p>
596 </td>
597 <td>
598 <p>
599 <em><xsl:call-template name="link-qname"><xsl:with-param name="qname" select="@type"/></xsl:call-template></em>
600 <xsl:if test="@required='true'"> <small> (required)</small></xsl:if>
601 <xsl:if test="@repeating='true'"> <small> (repeating)</small></xsl:if>
602 </p>
603 <xsl:choose>
604 <xsl:when test="wadl:option">
605 <p><em>One of:</em></p>
606 <ul>
607 <xsl:apply-templates select="wadl:option"/>
608 </ul>
609 </xsl:when>
610 <xsl:otherwise>
611 <xsl:if test="@default"><p>Default: <tt><xsl:value-of select="@default"/></tt></p></xsl:if>
612 <xsl:if test="@fixed"><p>Fixed: <tt><xsl:value-of select="@fixed"/></tt></p></xsl:if>
613 </xsl:otherwise>
614 </xsl:choose>
615 </td>
616 <td>
617 <xsl:apply-templates select="wadl:doc"/>
618 <xsl:if test="wadl:option[wadl:doc]">
619 <dl>
620 <xsl:apply-templates select="wadl:option" mode="option-doc"/>
621 </dl>
622 </xsl:if>
623 <xsl:if test="@path">
624 <ul>
625 <li>XPath to value: <tt><xsl:value-of select="@path"/></tt></li>
626 <xsl:apply-templates select="wadl:link"/>
627 </ul>
628 </xsl:if>
629 </td>
630 </tr>
631 </xsl:template>
632
633 <xsl:template match="wadl:link">
634 <li>
635 Link: <a href="#{@resource_type}"><xsl:value-of select="@rel"/></a>
636 </li>
637 </xsl:template>
638
639 <xsl:template match="wadl:option">
640 <li>
641 <tt><xsl:value-of select="@value"/></tt>
642 <xsl:if test="ancestor::wadl:param[1]/@default=@value"> <small> (default)</small></xsl:if>
643 </li>
644 </xsl:template>
645
646 <xsl:template match="wadl:option" mode="option-doc">
647 <dt>
648 <tt><xsl:value-of select="@value"/></tt>
649 <xsl:if test="ancestor::wadl:param[1]/@default=@value"> <small> (default)</small></xsl:if>
650 </dt>
651 <dd>
652 <xsl:apply-templates select="wadl:doc"/>
653 </dd>
654 </xsl:template>
655
656 <xsl:template match="wadl:doc">
657 <xsl:param name="inline">0</xsl:param>
658 <!-- skip WADL elements -->
659 <xsl:choose>
660 <xsl:when test="node()[1]=text() and $inline=0">
661 <p>
662 <!-- xsl:apply-templates select="node()" mode="copy" / -->
663 <xsl:value-of select="node()" disable-output-escaping="yes"/>
664 </p>
665 </xsl:when>
666 <xsl:otherwise>
667 <xsl:apply-templates select="node()" mode="copy"/>
668 </xsl:otherwise>
669 </xsl:choose>
670 </xsl:template>
671
672 <!-- utilities -->
673
674 <xsl:template name="get-id">
675 <xsl:choose>
676 <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
677 <xsl:otherwise><xsl:value-of select="generate-id()"/></xsl:otherwise>
678 </xsl:choose>
679 </xsl:template>
680
681 <xsl:template name="get-namespace-uri">
682 <xsl:param name="context" select="."/>
683 <xsl:param name="qname"/>
684 <xsl:variable name="prefix" select="substring-before($qname,':')"/>
685 <xsl:variable name="qname-ns-uri" select="$context/namespace::*[name()=$prefix]"/>
686 <!-- nasty hack to get around libxsl's refusal to copy all namespace nodes when pushing nodesets around -->
687 <xsl:choose>
688 <xsl:when test="$qname-ns-uri">
689 <xsl:value-of select="$qname-ns-uri"/>
690 </xsl:when>
691 <xsl:otherwise>
692 <xsl:value-of select="exsl:node-set($resources)/*[1]/attribute::*[namespace-uri()='urn:namespace' and local-name()=$prefix]"/>
693 </xsl:otherwise>
694 </xsl:choose>
695 </xsl:template>
696
697 <xsl:template name="get-element">
698 <xsl:param name="context" select="."/>
699 <xsl:param name="qname"/>
700 <xsl:variable name="ns-uri">
701 <xsl:call-template name="get-namespace-uri">
702 <xsl:with-param name="context" select="$context"/>
703 <xsl:with-param name="qname" select="$qname"/>
704 </xsl:call-template>
705 </xsl:variable>
706 <xsl:variable name="localname" select="substring-after($qname, ':')"/>
707 <xsl:variable name="definition" select="exsl:node-set($grammars)/descendant::xs:element[@name=$localname][ancestor-or-self::*[@targetNamespace=$ns-uri]]"/>
708 <xsl:variable name='source' select="$definition/ancestor-or-self::wadl:include[1]/@href"/>
709 <p><em>Source: <a href="{$source}"><xsl:value-of select="$source"/></a></em></p>
710 <pre><xsl:apply-templates select="$definition" mode="encode"/></pre>
711 </xsl:template>
712
713 <xsl:template name="link-qname">
714 <xsl:param name="context" select="."/>
715 <xsl:param name="qname"/>
716 <xsl:variable name="ns-uri">
717 <xsl:call-template name="get-namespace-uri">
718 <xsl:with-param name="context" select="$context"/>
719 <xsl:with-param name="qname" select="$qname"/>
720 </xsl:call-template>
721 </xsl:variable>
722 <xsl:variable name="localname" select="substring-after($qname, ':')"/>
723 <xsl:choose>
724 <xsl:when test="$ns-uri='http://www.w3.org/2001/XMLSchema'">
725 <a href="http://www.w3.org/TR/xmlschema-2/#{$localname}"><xsl:value-of select="$localname"/></a>
726 </xsl:when>
727 <xsl:otherwise>
728 <xsl:variable name="definition" select="exsl:node-set($grammars)/descendant::xs:*[@name=$localname][ancestor-or-self::*[@targetNamespace=$ns-uri]]"/>
729 <a href="{$definition/ancestor-or-self::wadl:include[1]/@href}" title="{$definition/descendant::xs:documentation/descendant::text()}"><xsl:value-of select="$localname"/></a>
730 </xsl:otherwise>
731 </xsl:choose>
732 </xsl:template>
733
734 <xsl:template name="expand-qname">
735 <xsl:param name="context" select="."/>
736 <xsl:param name="qname"/>
737 <xsl:variable name="ns-uri">
738 <xsl:call-template name="get-namespace-uri">
739 <xsl:with-param name="context" select="$context"/>
740 <xsl:with-param name="qname" select="$qname"/>
741 </xsl:call-template>
742 </xsl:variable>
743 <xsl:text>{</xsl:text>
744 <xsl:value-of select="$ns-uri"/>
745 <xsl:text>} </xsl:text>
746 <xsl:value-of select="substring-after($qname, ':')"/>
747 </xsl:template>
748
749
750 <xsl:template name="representation-name">
751 <xsl:variable name="expanded-name">
752 <xsl:call-template name="expand-qname">
753 <xsl:with-param select="@element" name="qname"/>
754 </xsl:call-template>
755 </xsl:variable>
756 <xsl:choose>
757 <xsl:when test="wadl:doc[@title]">
758 <xsl:value-of select="wadl:doc[@title][1]/@title"/>
759 <xsl:if test="@status or @mediaType or @element"> (</xsl:if>
760 <xsl:if test="@status">Status Code </xsl:if><xsl:value-of select="@status"/>
761 <xsl:if test="@status and @mediaType"> - </xsl:if>
762 <xsl:value-of select="@mediaType"/>
763 <xsl:if test="(@status or @mediaType) and @element"> - </xsl:if>
764 <xsl:if test="@element">
765 <abbr title="{$expanded-name}"><xsl:value-of select="@element"/></abbr>
766 </xsl:if>
767 <xsl:if test="@status or @mediaType or @element">)</xsl:if>
768 </xsl:when>
769 <xsl:otherwise>
770 <xsl:if test="@status">Status Code </xsl:if><xsl:value-of select="@status"/>
771 <xsl:if test="@status and @mediaType"> - </xsl:if>
772 <xsl:value-of select="@mediaType"/>
773 <xsl:if test="@element"> (</xsl:if>
774 <abbr title="{$expanded-name}"><xsl:value-of select="@element"/></abbr>
775 <xsl:if test="@element">)</xsl:if>
776 </xsl:otherwise>
777 </xsl:choose>
778 </xsl:template>
779
780 <!-- entity-encode markup for display -->
781
782 <xsl:template match="*" mode="encode">
783 <xsl:text>&lt;</xsl:text>
784 <xsl:value-of select="name()"/><xsl:apply-templates select="attribute::*" mode="encode"/>
785 <xsl:choose>
786 <xsl:when test="*|text()">
787 <xsl:text>&gt;</xsl:text>
788 <xsl:apply-templates select="*|text()" mode="encode" xml:space="preserve"/>
789 <xsl:text>&lt;/</xsl:text><xsl:value-of select="name()"/><xsl:text>&gt;</xsl:text>
790 </xsl:when>
791 <xsl:otherwise>
792 <xsl:text>/&gt;</xsl:text>
793 </xsl:otherwise>
794 </xsl:choose>
795 </xsl:template>
796
797 <xsl:template match="@*" mode="encode">
798 <xsl:text> </xsl:text><xsl:value-of select="name()"/><xsl:text>="</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>
799 </xsl:template>
800
801 <xsl:template match="text()" mode="encode">
802 <xsl:value-of select="." xml:space="preserve"/>
803 </xsl:template>
804
805 <!-- copy HTML for display -->
806
807 <xsl:template match="html:*" mode="copy">
808 <!-- remove the prefix on HTML elements -->
809 <xsl:element name="{local-name()}">
810 <xsl:for-each select="@*">
811 <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
812 </xsl:for-each>
813 <xsl:apply-templates select="node()" mode="copy"/>
814 </xsl:element>
815 </xsl:template>
816
817 <xsl:template match="@*|node()[namespace-uri()!='http://www.w3.org/1999/xhtml']" mode="copy">
818 <!-- everything else goes straight through -->
819 <xsl:copy>
820 <xsl:apply-templates select="@*|node()" mode="copy"/>
821 </xsl:copy>
822 </xsl:template>
823
824 <!-- disable-output-escaping="yes" -->
825
826 </xsl:stylesheet>