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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
wadl-to-refhtml.xsl
Generate HTML documentation for a webservice described in a WADL file.
This is tailored to WADL generated by Launchpad's web service.
Based on wadl_documentaion.xsl from Mark Nottingham <mnot@yahoo-inc.com>
that can be found at http://www.mnot.net/webdesc/
Copyright (c) 2006-2007 Yahoo! Inc.
Copyright (c) 2008-2011 Canonical Ltd.
This work is licensed under the Creative Commons Attribution-ShareAlike 2.5
License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/2.5/
or send a letter to
Creative Commons
543 Howard Street, 5th Floor
San Francisco, California, 94105, USA
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:wadl="http://research.sun.com/wadl/2006/10"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl wadl html"
>
<xsl:output
method="xml"
encoding="UTF-8"
indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>
<!-- Allow using key('id', 'people') to identify unique elements, since
the document doesn't have a parsed DTD.
-->
<xsl:key name="id" match="*[@id]" use="@id"/>
<!-- Embedded stylesheet. -->
<xsl:template name="css-stylesheet">
<style type="text/css">
body {
font-family: sans-serif;
font-size: 0.85em;
margin: 2em 8em;
}
.methods {
background-color: #eef;
padding: 1em;
margin-bottom: 0.5em;
}
.method {
padding-left: 4em;
}
h1 {
font-size: 2.5em;
}
h2 {
border-bottom: 1px solid black;
margin-top: 1em;
margin-bottom: 0.5em;
font-size: 2em;
}
h3 {
color: orange;
font-size: 1.75em;
margin-top: 1.25em;
margin-bottom: 0em;
}
h4 {
font-size: 1.50em;
margin: 0em;
padding: 0em;
border-bottom: 2px solid white;
}
h5 {
font-size: 1.25em;
margin-left: -3em;
}
h6 {
font-size: 1.1em;
color: #99a;
margin: 0.5em 0em 0.25em 0em;
}
dd {
margin-left: 1em;
}
tt, code {
font-size: 1.2em;
}
table {
margin-bottom: 0.5em;
}
th {
text-align: left;
font-weight: normal;
color: black;
border-bottom: 1px solid black;
padding: 3px 6px;
}
td {
padding: 3px 6px;
vertical-align: top;
background-color: #f6f6ff;
font-size: 0.85em;
}
td p {
margin: 0px;
}
ul {
padding-left: 1.75em;
}
p + ul, p + ol, p + dl {
margin-top: 0em;
}
label {
font-weight: bold;
}
.optional {
font-weight: normal;
opacity: 0.75;
}
.toc-link {
font-size: 0.85em;
}
</style>
</xsl:template>
<!-- Contains the base URL for the webservice without a trailing
slash. -->
<xsl:variable name="base">
<xsl:variable name="uri" select="//wadl:resources/@base"/>
<xsl:choose>
<xsl:when
test="substring($uri, string-length($uri) , 1) = '/'">
<xsl:value-of
select="substring($uri, 1, string-length($uri) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$uri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Contains the list of top-level parameters that are links to
collections. Does not contain parameters that are not links to
collections, such as 'me_link'. -->
<xsl:variable name="top_level_collections"
select="key('id', 'service-root-json')/wadl:param[
contains(@name, '_collection_link')]/wadl:link" />
<!-- Generate the URL to the top-level collection. -->
<xsl:template name="resource-uri-doc">
<xsl:param name="url"><xsl:value-of
select="$base"/>/<xsl:value-of select="@id"/></xsl:param>
<p><label>URL:</label>
<code><xsl:copy-of select="$url" /></code></p>
</xsl:template>
<xsl:template name="entry-uri-doc">
<xsl:call-template name="resource-uri-doc">
<xsl:with-param name="url">
<xsl:choose>
<xsl:when test="
@id = 'bug_link_target'
or @id = 'bug_target'
or @id = 'has_bugs'
or @id = 'has_milestones'
or @id = 'object_with_translation_imports'
or @id = 'question_target'
or @id = 'specification_target'
or @id = 'structural_subscription_target'
">
<em>depends on the underlying entry</em>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="find-entry-uri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="find-entry-uri">
<xsl:value-of select="$base"/>
<xsl:choose>
<xsl:when test="@id = 'archive'">
<xsl:text>/</xsl:text>
<var><distribution></var>
<xsl:text>/+archive/</xsl:text>
<var><archive.name></var>
</xsl:when>
<xsl:when test="@id = 'archive_permission'">
<xsl:text>/</xsl:text>
<var><archive.distribution></var>
<xsl:text>/+archive/</xsl:text>
<var><archive.name></var>
<xsl:text>/+</xsl:text>
<xsl:text>name</xsl:text>
<xsl:text>/</xsl:text>
<xsl:text>person.name</xsl:text>
<xsl:text>.</xsl:text>
<xsl:text>[component or source package].name</xsl:text>
</xsl:when>
<xsl:when test="@id = 'binary_package_publishing_history'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/+archive/</xsl:text>
<var><binary_package.name></var>
<xsl:text>/+binarypub/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'branch'">
<xsl:text>/~</xsl:text>
<var><author.name></var>
<xsl:text>/</xsl:text>
<var><project.name></var>
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'branch_merge_proposal'">
<xsl:text>/~</xsl:text>
<var><author.name></var>
<xsl:text>/</xsl:text>
<var><project.name></var>
<xsl:text>/</xsl:text>
<var><branch.name></var>
<xsl:text>/+merge/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'bug'">
<xsl:text>/bugs/</xsl:text><var><id></var>
</xsl:when>
<xsl:when test="@id = 'bug_attachment'">
<xsl:text>/bugs/</xsl:text>
<var><bug.id></var>
<xsl:text>/attachments/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'bug_subscription'">
<xsl:text>/bugs/</xsl:text>
<var><bug.id></var>
<xsl:text>/subscriptions/</xsl:text>
<var><subscriber.name></var>
</xsl:when>
<xsl:when test="@id = 'bug_task'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+bug/</xsl:text>
<var ><bug.id></var>
</xsl:when>
<xsl:when test="@id = 'bug_watch'">
<xsl:text>/bugs/</xsl:text>
<var><bug.id></var>
<xsl:text>/watch/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'bug_tracker'">
<xsl:text>/bugs/bugtrackers/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'build'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/+source/</xsl:text>
<var><source_package.name></var>
<xsl:text>/+build/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'builder'">
<xsl:text>/builders/</xsl:text>
<var><builder.name></var>
</xsl:when>
<xsl:when test="@id = 'cve'">
<xsl:text>/bugs/cve/</xsl:text>
<var><sequence></var>
</xsl:when>
<xsl:when test="@id = 'country'">
<xsl:text>/+countries/</xsl:text>
<var><iso3166code2></var>
</xsl:when>
<xsl:when test="@id = 'distribution_source_package'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/+source/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'distro_arch_series'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/</xsl:text>
<var><distroseries.name></var>
<xsl:text>/</xsl:text>
<var><architecture_tag></var>
</xsl:when>
<xsl:when test="@id = 'distro_series'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'email_address'">
<xsl:text>/</xsl:text>
<var><person.name></var>
<xsl:text>/+email/</xsl:text>
<var><email></var>
</xsl:when>
<xsl:when test="@id = 'gpg_key'">
<xsl:text>/</xsl:text>
<var><person.name></var>
<xsl:text>/+gpg-keys/</xsl:text>
<var><keyid></var>
</xsl:when>
<xsl:when test="@id = 'hwdb'">
<xsl:text>/+hwdb</xsl:text>
</xsl:when>
<xsl:when test="@id = 'h_w_device'">
<xsl:text>/+hwdb/+device/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'h_w_device_class'">
<xsl:text>/+hwdb/+deviceclass/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'h_w_driver'">
<xsl:text>/+hwdb/+driver/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'h_w_submission'">
<xsl:text>/+hwdb/+submission/</xsl:text>
<var><submission-key></var>
</xsl:when>
<xsl:when test="@id = 'h_w_submission_device'">
<xsl:text>/+hwdb/+submissiondevice/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'h_w_vendor_i_d'">
<xsl:text>/+hwdb/+hwvendorid/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'h_w_driver_name'">
<xsl:text>/+hwdb/+drivername/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'h_w_driver_package_name'">
<xsl:text>/+hwdb/+driverpackagename/</xsl:text>
<var><package_name></var>
</xsl:when>
<xsl:when test="@id = 'jabber_id'">
<xsl:text>/</xsl:text>
<var><person.name></var>
<xsl:text>/+jabberid/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'irc_id'">
<xsl:text>/</xsl:text>
<var><person.name></var>
<xsl:text>/+ircnick/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'language'">
<xsl:text>/+languages/</xsl:text>
<var><code></var>
</xsl:when>
<xsl:when test="@id = 'message'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+bug/</xsl:text>
<var><bug.id></var>
<xsl:text>/comments/</xsl:text>
<var><index></var>
</xsl:when>
<xsl:when test="@id = 'milestone'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+milestone/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test=" @id = 'distribution'
or @id = 'pillar'
or @id = 'product'
or @id = 'project'
or @id = 'project_group'">
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'team' or @id = 'person'">
<xsl:text>/~</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'pillars'">
<xsl:text>/pillars</xsl:text>
</xsl:when>
<xsl:when test="@id = 'processor'">
<xsl:text>/+processors/</xsl:text>
<var><processor.name></var>
</xsl:when>
<xsl:when test="@id = 'processor_family'">
<xsl:text>/+processor-families/</xsl:text>
<var><processor_family.name></var>
</xsl:when>
<xsl:when test="@id = 'product_release'">
<xsl:text>/</xsl:text>
<var><product.name></var>
<xsl:text>/</xsl:text>
<var><product_series.name></var>
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'product_series'">
<xsl:text>/</xsl:text>
<var><product.name></var>
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'project_release'">
<xsl:text>/</xsl:text>
<var><project.name></var>
<xsl:text>/</xsl:text>
<var><project_series.name></var>
<xsl:text>/</xsl:text>
<var><release.version></var>
</xsl:when>
<xsl:when test="@id = 'project_release_file'">
<xsl:text>/</xsl:text>
<var><project.name></var>
<xsl:text>/</xsl:text>
<var><project_series.name></var>
<xsl:text>/</xsl:text>
<var><release.version></var>
<xsl:text>/+file/</xsl:text>
<var><hosted_file.filename></var>
</xsl:when>
<xsl:when test="@id = 'project_series'">
<xsl:text>/</xsl:text>
<var><project.name></var>
<xsl:text>/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'question'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+question/</xsl:text>
<var ><question.id></var>
</xsl:when>
<xsl:when test="@id = 'question_message'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+question/</xsl:text>
<var ><question.id></var>
<xsl:text>/messages/</xsl:text>
<var ><message.index></var>
</xsl:when>
<xsl:when test="@id = 'source_package'">
<xsl:text>/</xsl:text>
<var><distribution.name></var>
<xsl:text>/</xsl:text>
<var><distro_series.name></var>
<xsl:text>/+source/</xsl:text>
<var><name></var>
</xsl:when>
<xsl:when test="@id = 'source_package_publishing_history'">
<xsl:text>/</xsl:text>
<var><distribution></var>
<xsl:text>/+archive/</xsl:text>
<var><name></var>
<xsl:text>/+sourcepub/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'specification'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+spec/</xsl:text>
<var ><specification.name></var>
</xsl:when>
<xsl:when test="@id = 'specification_branch'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+spec/</xsl:text>
<var ><specification.name></var>
<xsl:text>/+branch/</xsl:text>
<var ><branch.unique_name[1:]></var>
</xsl:when>
<xsl:when test="@id = 'specification_subscription'">
<xsl:text>/</xsl:text>
<var><target.name></var>
<xsl:text>/+spec/</xsl:text>
<var ><specification.name></var>
<xsl:text>/+subscription/</xsl:text>
<var ><person.name></var>
</xsl:when>
<xsl:when test="@id = 'ssh_key'">
<xsl:text>/</xsl:text>
<var><person.name></var>
<xsl:text>/+ssh-keys/</xsl:text>
<var><keyid></var>
</xsl:when>
<xsl:when test="@id = 'team_membership'">
<xsl:text>/~</xsl:text>
<var><team.name></var>
<xsl:text>/+member/</xsl:text>
<var><member.name></var>
</xsl:when>
<xsl:when test="@id = 'wiki_name'">
<xsl:text>/~</xsl:text>
<var><person.name></var>
<xsl:text>/+wikiname/</xsl:text>
<var><id></var>
</xsl:when>
<xsl:when test="@id = 'commercial_subscription'">
<xsl:text>/+commercialsubscription/</xsl:text>
<var><commercial_subscription.id></var>
</xsl:when>
<!-- XXX: GavinPanella 2011-07-29 bug=735543: A bug exists
to do something more sensible here. For now, no one
cares, so let's shut this up. -->
<!-- <xsl:otherwise> -->
<!-- <xsl:message>Unknown entry URL: -->
<!-- <xsl:value-of select="@id" /> -->
<!-- </xsl:message> -->
<!-- </xsl:otherwise> -->
</xsl:choose>
</xsl:template>
<!-- We start here. -->
<xsl:template match="/wadl:application">
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="wadl:doc[@title]">
<xsl:value-of select="wadl:doc[@title][1]/@title"/>
</xsl:when>
<xsl:otherwise>Launchpad Web Service API</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<html>
<head>
<title><xsl:value-of select="$title" /></title>
<xsl:call-template name="css-stylesheet"/>
</head>
<body>
<h1><xsl:value-of select="$title" /></h1>
<xsl:apply-templates select="wadl:doc"/>
<xsl:call-template name="table-of-contents" />
<xsl:call-template name="top-level-objects" />
<xsl:call-template name="entry-types" />
</body>
</html>
</xsl:template>
<!-- Table of contents -->
<xsl:template name="table-of-contents">
<div id="toc" title="toc">
<h2>Table of Contents</h2>
<h3>Top-level collections</h3>
<ul>
<xsl:for-each select="$top_level_collections">
<xsl:sort select="../@name" />
<xsl:variable name="object_id"
select="substring-after(@resource_type, '#')" />
<xsl:variable name="collection_link_name"
select="substring-before(
../@name, '_collection_link')" />
<xsl:variable name="entry_link_name"
select="substring-before(
../@name, '_link')" />
<xsl:if test="string-length($object_id) > 0">
<li><a href="#{$object_id}">
<xsl:choose>
<xsl:when test="$collection_link_name">
<xsl:value-of select="$collection_link_name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$entry_link_name" />
</xsl:otherwise>
</xsl:choose>
</a></li>
</xsl:if>
</xsl:for-each>
</ul>
<h3>Entry types</h3>
<ul>
<xsl:for-each select="wadl:resource_type[
@id != 'service-root'
and @id != 'HostedFile'
and @id != 'ScalarValue'
and not(contains(@id, 'page-resource'))
]">
<xsl:sort select="@id" />
<xsl:variable name="id" select="./@id"/>
<xsl:variable name="in_top_level_collections"
select="$top_level_collections/@resource_type[
substring-after(., '#') = $id]" />
<xsl:if test="not($in_top_level_collections)">
<li><a href="#{$id}">
<xsl:call-template name="get-title-or-id">
<xsl:with-param name="element" select="." />
</xsl:call-template>
</a></li>
</xsl:if>
</xsl:for-each>
</ul>
</div>
</xsl:template>
<!-- Top level collections container -->
<xsl:template name="top-level-objects">
<div id="top-level-objects" title="top-level-objects">
<h2>Top-level collections</h2>
<xsl:for-each select="$top_level_collections">
<xsl:sort select="../@name" />
<xsl:variable name="object_id"
select="substring-after(@resource_type, '#')" />
<xsl:apply-templates
select="key('id', $object_id)"
mode="top-level-objects" />
</xsl:for-each>
</div>
</xsl:template>
<xsl:template name="find-root-object-uri">
<xsl:value-of select="$base"/>
<xsl:choose>
<xsl:when test="@id = 'hwdb'">
<xsl:text>/+hwdb</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>/</xsl:text><xsl:value-of select="@id" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Documentation for one top-level-object -->
<xsl:template match="wadl:resource_type" mode="top-level-objects">
<div id="{@id}" title="{@id}" class="top-level-object">
<h3><xsl:call-template name="get-title-or-id"/></h3>
<xsl:apply-templates select="wadl:doc"/>
<xsl:call-template name="resource-uri-doc">
<xsl:with-param name="url">
<!-- The default URL schema used for root objects of
Launchpad's webservice is
[urlbase]/[root-object-name]
e.g,
https://api.launchpad.net/beta/bugs
while the HWDB application root's URL is
https://api.launchpad.net/beta/+hwdb
In other words, the URL for the HWDB application
root needs to be mangled in a form similar to
that used for non-root objects in the template
"find-entry-uri".
-->
<xsl:call-template name="find-root-object-uri"/>
</xsl:with-param>
</xsl:call-template>
<!-- All top-level collections support a GET without arguments
iterating over all the resources.
The type of the resource is found by looking at the href attribute
of the default representation. Link is in the form
<resource>-page.
-->
<div class="methods standard">
<h4>Standard method</h4>
<xsl:variable name="default_get"
select="wadl:method[not(wadl:request)][1]" />
<xsl:variable name="resource_type"
select="substring-after(
substring-before(
$default_get//wadl:representation[
not(@mediaType)]/@href, '-page'),
'#')" />
<dl>
<dt>GET</dt>
<dd>Response contains a <a href="#{$resource_type}"
><xsl:call-template name="get-title-or-id">
<xsl:with-param name="element"
select="key('id', $resource_type)" />
</xsl:call-template></a>
collection.</dd>
</dl>
</div>
<xsl:call-template name="custom-GETs" />
<xsl:call-template name="custom-POSTs" />
<a href="#toc" class="toc-link">(back to Table of Contents)</a>
</div>
</xsl:template>
<!-- Documentation for the standard methods on an entry -->
<xsl:template name="standard-methods">
<div id="{@id}-standard-methods" title="{@id}-standard-methods" class="methods standard">
<h4>Standard methods</h4>
<dl>
<!-- Standard methods are the ones without a ws.op param. -->
<xsl:apply-templates
select="wadl:method[not(.//wadl:param[@name = 'ws.op'])]"
mode="standard-method">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</dl>
</div>
</xsl:template>
<!-- Documentation for the standard GET on an entry -->
<xsl:template match="wadl:method[@name='GET']" mode="standard-method">
<dt><xsl:value-of select="@name" /></dt>
<dd>Response contains the default
<xsl:call-template name="representation-type" /> representation
for this entry.
</dd>
</xsl:template>
<!-- Documentation for the standard PUT on an entry -->
<xsl:template match="wadl:method[@name='PUT']" mode="standard-method">
<dt><xsl:value-of select="@name" /></dt>
<dd>Entity body should contain a representation encoded using
<xsl:call-template name="representation-type" /> of the entry.
All fields of the default representation should be included. Only
fields marked as writeable in the default representation should be
modified.
</dd>
</xsl:template>
<!-- Documentation for the standard PATCH on an entry -->
<xsl:template match="wadl:method[@name='PATCH']" mode="standard-method">
<dt><xsl:value-of select="@name" /></dt>
<dd>Entity body should contain a represention encoded using
<xsl:call-template name="representation-type"/> of the entry
fields to update. Any fields of the default representation marked
as writeable can be included.
</dd>
</xsl:template>
<!-- Documentation for the custom GET operations of the resource type -->
<xsl:template name="custom-GETs">
<xsl:variable name="operations" select="wadl:method[
@name = 'GET'][.//wadl:param[@name = 'ws.op']]" />
<xsl:if test="$operations">
<div id="{@id}-custom-GETs" title="{@id}-custom-GETs" class="methods GETs">
<h4>Custom GET methods</h4>
<xsl:apply-templates select="$operations">
<xsl:sort select=".//wadl:param[@name='ws.op']/@fixed"/>
</xsl:apply-templates>
</div>
</xsl:if>
</xsl:template>
<!-- Documentation for the custom POST operations of the resource type -->
<xsl:template name="custom-POSTs">
<xsl:variable name="operations" select="wadl:method[
@name = 'POST'][.//wadl:param[@name = 'ws.op']]" />
<xsl:if test="$operations">
<div id="{@id}-custom-POSTs" title="{@id}-custom-POSTs" class="methods POSTs">
<h4>Custom POST methods</h4>
<xsl:apply-templates select="$operations">
<xsl:sort select=".//wadl:param[@name='ws.op']/@fixed"/>
</xsl:apply-templates>
</div>
</xsl:if>
</xsl:template>
<!-- Container for all the entry types documentation -->
<xsl:template name="entry-types">
<h2 id="entry-types" title="entry-types">Entry types</h2>
<!-- Process all the resource_types, except the service root,
special types like HostedFile, and the top-level collections. -->
<xsl:for-each select="wadl:resource_type[
@id != 'service-root'
and @id != 'HostedFile'
and @id != 'ScalarValue'
and not(contains(@id, 'page-resource'))
]">
<xsl:sort select="@id" />
<xsl:variable name="id" select="./@id"/>
<xsl:variable name="in_top_level_collections"
select="$top_level_collections/@resource_type[
substring-after(., '#') = $id]" />
<xsl:if test="not($in_top_level_collections)">
<xsl:apply-templates select="." mode="entry-types" />
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Documentation for one entry-type -->
<xsl:template match="wadl:resource_type" mode="entry-types">
<h3 id="{@id}" title="{@id}"><xsl:call-template name="get-title-or-id"/></h3>
<xsl:apply-templates select="wadl:doc"/>
<xsl:call-template name="entry-uri-doc"/>
<xsl:call-template name="default-representation" />
<xsl:call-template name="standard-methods" />
<xsl:call-template name="custom-GETs" />
<xsl:call-template name="custom-POSTs" />
<a href="#toc" class="toc-link">(back to Table of Contents)</a>
</xsl:template>
<!-- Documentation of the default representation for an entry -->
<xsl:template name="default-representation">
<xsl:variable name="default_get" select="wadl:method[
@name = 'GET' and not(wadl:request)]" />
<xsl:variable name="representation" select="key(
'id', substring-after(
$default_get/wadl:response/wadl:representation[
not(@mediaType)]/@href, '#'))"/>
<div class="representation">
<h4>Default representation
(<xsl:value-of select="$representation/@mediaType"/>)</h4>
<table>
<tr>
<th>Key</th>
<th>Value</th>
<th>Description</th>
</tr>
<xsl:apply-templates select="$representation/wadl:param"
mode="representation">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</table>
</div>
</xsl:template>
<!-- Output the cell containing the field name.
current() should be a wadl:param.
-->
<xsl:template name="param-name">
<td>
<p><strong><xsl:value-of select="@name"/></strong></p>
</td>
</xsl:template>
<!-- Output a table cell containing the parameter description.
current() should a wadl:param.
-->
<xsl:template name="param-description">
<td>
<xsl:apply-templates select="wadl:doc"/>
<xsl:if test="wadl:option[wadl:doc]">
<dl>
<xsl:apply-templates
select="wadl:option" mode="option-doc"/>
</dl>
</xsl:if>
</td>
</xsl:template>
<!-- Output information about the parameter value.
current() should be a wadl:param.
-->
<xsl:template name="param-value">
<xsl:if test="wadl:option">
<p><em>One of:</em></p>
<ul>
<xsl:apply-templates select="wadl:option"/>
</ul>
</xsl:if>
<xsl:apply-templates select="wadl:link[@resource_type]"/>
<xsl:if test="@default">
<p>
Default:
<var><xsl:value-of select="@default"/></var>
</p>
</xsl:if>
<xsl:if test="@fixed">
<p>
Fixed:
<var><xsl:value-of select="@fixed"/></var>
</p>
</xsl:if>
</xsl:template>
<!-- Output row describing one field in the default representation -->
<xsl:template match="wadl:param" mode="representation">
<xsl:variable name="resource_type"
select="substring-before(../@id, '-')" />
<xsl:variable name="patch_representation_id"
><xsl:value-of select="$resource_type"/>-diff</xsl:variable>
<xsl:variable name="patch_representation"
select="key('id', $patch_representation_id)"/>
<tr>
<xsl:call-template name="param-name"/>
<td>
<p>
<xsl:choose>
<xsl:when test="$patch_representation/wadl:param[@name
= current()/@name]">
<small>(writeable)</small>
</xsl:when>
<xsl:otherwise>
<small>(read-only)</small>
</xsl:otherwise>
</xsl:choose>
</p>
<xsl:call-template name="param-value" />
</td>
<xsl:call-template name="param-description" />
</tr>
</xsl:template>
<!-- Output the description of a link type in param listing -->
<xsl:template match="wadl:link[
@resource_type and ../@name != 'self_link']">
<xsl:variable name="resource_type"
select="substring-after(@resource_type, '#')"/>
<xsl:choose>
<xsl:when test="contains($resource_type, 'page-resource')">
Link to a <a href="#{substring-before($resource_type, '-')}"
><xsl:value-of
select="substring-before($resource_type, '-')"
/></a> collection.
</xsl:when>
<xsl:when test="$resource_type = 'HostedFile'">
Link to a file resource.
</xsl:when>
<xsl:otherwise>
Link to a <a href="#{$resource_type}"
><xsl:value-of select="$resource_type"/></a>.
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Documentation for a custom method -->
<xsl:template match="wadl:method[.//wadl:param[@name = 'ws.op']]">
<div class="method">
<h5 id="{@id}" title="{@id}"><xsl:value-of
select=".//wadl:param[@name = 'ws.op']/@fixed"/></h5>
<xsl:choose>
<xsl:when test="wadl:doc|wadl:request|wadl:response">
<xsl:apply-templates select="wadl:doc"/>
<xsl:apply-templates select="wadl:request"/>
<xsl:apply-templates select="wadl:response"/>
<xsl:if test="not(wadl:response)">
<xsl:apply-templates select="wadl:doc//html:th[
node() = 'return:'
]"/>
</xsl:if>
<xsl:call-template name="error-documentation"/>
</xsl:when>
<xsl:otherwise>
<p><em>Missing documentation.</em></p>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<!-- Documentation for the request parameters of a custom method -->
<xsl:template match="wadl:request">
<h6>Parameters</h6>
<table>
<tr>
<th>Parameter</th>
<th>Value</th>
<th>Description</th>
</tr>
<xsl:apply-templates
select=".//wadl:param[@style='query'][@fixed]"/>
<xsl:apply-templates
select=".//wadl:param[@style='query'][not(@fixed)]">
<xsl:sort select="@name" />
</xsl:apply-templates>
</table>
</xsl:template>
<!-- Documentation for the response of custom methods returning
and entry or a collection.
-->
<xsl:template match="wadl:response/wadl:representation[@href]">
<xsl:variable name="id" select="substring-after(@href, '#')" />
<xsl:variable name="resource_type"
select="substring-before($id, '-')"/>
<p class="response">Response contains an
<xsl:apply-templates select="key('id', $id)"
mode="representation-type"/>
representation of a
<a href="#{$resource_type}"><xsl:value-of
select="$resource_type"
/></a><xsl:if test="contains($id, '-page')">
collection
</xsl:if>.
</p>
</xsl:template>
<!-- Documentation of the custom method return type. -->
<xsl:template match="wadl:doc//html:th[node() = 'return:']">
<h6>Response (application/json)</h6>
<xsl:choose>
<xsl:when test="following-sibling::html:td/text()">
<p><xsl:apply-templates select="following-sibling::html:td"
mode="copy"/></p>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="following-sibling::html:td"
mode="copy"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Documentation of the error raised by the operation. -->
<xsl:template name="error-documentation">
<xsl:if test="wadl:doc//html:th[node() = 'raise:']">
<h6>Errors</h6>
<ul>
<xsl:apply-templates
select="wadl:doc//html:th[node() = 'raise:']"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="wadl:doc//html:th[node() = 'raise:']">
<li>
<xsl:apply-templates select="following-sibling::html:td"
mode="copy"/>
</li>
</xsl:template>
<!-- Documentation for request parameter. -->
<xsl:template match="wadl:param">
<tr>
<xsl:call-template name="param-name"/>
<td>
<xsl:if test="@required or @repeating">
<p>
<xsl:if test="@required='true'">
<small>(required)</small>
</xsl:if>
<xsl:if test="@repeating='true'">
<small>(repeating)</small>
</xsl:if>
</p>
</xsl:if>
<xsl:call-template name="param-value"/>
</td>
<xsl:call-template name="param-description"/>
</tr>
</xsl:template>
<!-- Documentation for factories.
Factory's response include a Location header pointint to a resource type.
-->
<xsl:template match="wadl:response/wadl:param[
@name = 'Location' and @style = 'header'
and wadl:link[@resource_type]]">
<xsl:variable name="resource_type"
select="substring-after(
wadl:link[@resource_type]/@resource_type, '#')"/>
<p>On success, the response status will be 201 and the
<var>Location</var> header will contain the link to the newly
created <a href="#{$resource_type}"
><xsl:value-of select="$resource_type" /></a>.
</p>
</xsl:template>
<!-- Output the available value for the parameter. -->
<xsl:template match="wadl:option">
<li>
<tt><xsl:value-of select="@value"/></tt>
<xsl:if test="ancestor::wadl:param[1]/@default=@value">
<small>(default)</small>
</xsl:if>
</li>
</xsl:template>
<!-- Ouput list of the documentation for each available option. -->
<xsl:template match="wadl:option" mode="option-doc">
<dt>
<tt><xsl:value-of select="@value"/></tt>
<xsl:if test="ancestor::wadl:param[1]/@default=@value">
<small>(default)</small>
</xsl:if>
</dt>
<dd>
<xsl:apply-templates select="wadl:doc"/>
</dd>
</xsl:template>
<!-- Format wadl:doc -->
<xsl:template match="wadl:doc">
<xsl:param name="inline">0</xsl:param>
<!-- skip WADL elements -->
<xsl:choose>
<xsl:when test="node()[1]=text() and $inline=0">
<!-- If the wadl:doc contains <p> tags wrap it in a <div>,
otherwise wrap it in a <p> tag. -->
<xsl:choose>
<xsl:when test="./html:p">
<div>
<xsl:apply-templates select="node()" mode="copy"/>
</div>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:apply-templates select="node()" mode="copy"/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()" mode="copy"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Returns the title or id of an element.
Look for the first wadl:doc title attribute content of the
current node or fall back to the element id.
:param element: The element to return the title or id. Defaults to the
current node.
-->
<xsl:template name="get-title-or-id">
<xsl:param name="element" select="current()" />
<xsl:choose>
<xsl:when test="$element/wadl:doc[@title]">
<xsl:value-of select="$element/wadl:doc[@title][1]/@title"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$element/@id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Output the mediaType attribute of the default representation.
Should be call on an element that contain a wadl:representation element
without a mediaType attribute.
-->
<xsl:template name="representation-type">
<xsl:apply-templates
select="key('id',
substring-after(
.//wadl:representation[not(@mediaType)]/@href,
'#'))"
mode="representation-type"/>
</xsl:template>
<!-- Omit docutils parameter table in methods. The parameter names
description is either redundant or misleading with the one we
give.
We process the return and raise parameters separately.
-->
<xsl:template match="wadl:method//html:table[
contains(@class, 'field-list')]"
mode="copy" />
<!-- Output the mediaType attribute of a representation -->
<xsl:template match="wadl:representation[@mediaType]"
mode="representation-type">
<code><xsl:value-of select="@mediaType"/></code>
</xsl:template>
<!-- Copy html elements. -->
<xsl:template match="html:*" mode="copy">
<!-- remove the prefix on HTML elements -->
<xsl:element name="{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{local-name()}"
><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="node()" mode="copy"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()[
namespace-uri()!='http://www.w3.org/1999/xhtml']" mode="copy">
<!-- everything else goes straight through -->
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="copy"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
|