-
Notifications
You must be signed in to change notification settings - Fork 5
/
clean-for-DTD.xslt
2687 lines (2488 loc) · 97.4 KB
/
clean-for-DTD.xslt
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
<!--
Strip rfc2629.xslt extensions, generating XML input for "official" xml2rfc
Copyright (c) 2006-2023, Julian Reschke ([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Julian Reschke nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:exslt="http://exslt.org/common"
xmlns:ed="http://greenbytes.de/2002/rfcedit"
xmlns:grddl="http://www.w3.org/2003/g/data-view#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:x="http://purl.org/net/xml2rfc/ext"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="ed exslt grddl rdf svg x xi xhtml"
>
<!-- re-use some of the default RFC2629.xslt rules -->
<xsl:import href="rfc2629-no-doctype.xslt"/>
<!-- undo strip-space decls -->
<xsl:preserve-space elements="*"/>
<!-- generate UTF-8 XML with no doctype decl and artwork/sourcecode serialized as CDATA -->
<xsl:output method="xml" version="1.0" encoding="UTF-8" cdata-section-elements="artwork sourcecode" />
<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
<xsl:param name="xml2rfc-ext-strip-vbare">false</xsl:param>
<!-- xml2rfc target -->
<xsl:param name="xml2rfc-ext-xml2rfc-backend">
<xsl:variable name="default">
<xsl:choose>
<xsl:when test="$pub-yearmonth >= 201705">201706</xsl:when>
<xsl:when test="$pub-yearmonth > 201612">201610</xsl:when>
<xsl:otherwise>201510</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="parse-pis">
<xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
<xsl:with-param name="attr" select="'xml2rfc-backend'"/>
<xsl:with-param name="default" select="$default"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="xml2rfc-ext-xml2rfc-voc">2</xsl:param>
<!-- kick into cleanup mode -->
<xsl:template match="/">
<xsl:text> </xsl:text>
<xsl:comment>
This XML document is the output of clean-for-DTD.xslt; a tool that strips
extensions to RFC 7749 from documents for processing with xml2rfc.
</xsl:comment>
<xsl:text> </xsl:text>
<xsl:comment>TARGET-GENERATOR: <xsl:value-of select="$xml2rfc-ext-xml2rfc-backend"/></xsl:comment>
<xsl:text> </xsl:text>
<xsl:comment>TARGET-VOCABULARY: <xsl:value-of select="$xml2rfc-ext-xml2rfc-voc"/></xsl:comment>
<xsl:apply-templates select="/" mode="cleanup"/>
</xsl:template>
<xsl:template name="process-pi">
<xsl:param name="str"><xsl:value-of select="."/></xsl:param>
<xsl:variable name="str2">
<xsl:call-template name="eat-leading-whitespace">
<xsl:with-param name="str" select="$str"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$str2=''">
<!-- done -->
</xsl:when>
<xsl:otherwise>
<xsl:variable name="attrname" select="substring-before($str2,'=')"/>
<xsl:choose>
<xsl:when test="$attrname=''">
<xsl:call-template name="warning">
<xsl:with-param name="msg">bad PI syntax: <xsl:value-of select="$str2"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="remainder" select="substring($str2,2+string-length($attrname))"/>
<xsl:choose>
<xsl:when test="string-length($remainder) < 2">
<xsl:call-template name="warning">
<xsl:with-param name="msg">bad PI value syntax: <xsl:value-of select="$remainder"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="rem">
<xsl:call-template name="eat-leading-whitespace">
<xsl:with-param name="str" select="$remainder"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="qchars">'"</xsl:variable>
<xsl:variable name="qchar" select="substring($rem,1,1)"/>
<xsl:variable name="rem2" select="substring($rem,2)"/>
<xsl:choose>
<xsl:when test="not(contains($qchars,$qchar))">
<xsl:call-template name="warning">
<xsl:with-param name="msg">pseudo-attribute value needs to be quoted: <xsl:value-of select="$rem"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="not(contains($rem2,$qchar))">
<xsl:call-template name="warning">
<xsl:with-param name="msg">unmatched quote in: <xsl:value-of select="$rem2"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="value" select="substring-before($rem2,$qchar)"/>
<xsl:choose>
<xsl:when test="name()='rfc' and $attrname='include'">
<xsl:text> </xsl:text>
<xsl:variable name="content">
<xsl:call-template name="obtain-reference-for-include-PI">
<xsl:with-param name="uri" select="$value"/>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates select="exslt:node-set($content)//reference" mode="cleanup"/>
</xsl:when>
<!-- processed elsewhere -->
<xsl:when test="name()='rfc' and $attrname='sortrefs'"/>
<xsl:when test="name()='rfc' and $attrname='symrefs'"/>
<xsl:when test="name()='rfc' and $attrname='toc'"/>
<xsl:when test="name()='rfc' and $attrname='tocdepth'"/>
<!-- copy -->
<xsl:otherwise>
<xsl:text> </xsl:text>
<xsl:processing-instruction name="{name()}"><xsl:value-of select="concat($attrname,'=',$qchar,$value,$qchar)"/></xsl:processing-instruction>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="process-pi">
<xsl:with-param name="str" select="substring($rem2, 2 + string-length($value))"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="processing-instruction()" mode="cleanup">
<xsl:text> </xsl:text>
<xsl:copy/>
</xsl:template>
<xsl:template match="comment()|@*" mode="cleanup"><xsl:copy/></xsl:template>
<xsl:template match="text()" mode="cleanup"><xsl:copy/></xsl:template>
<xsl:template match="text()[not(ancestor::artwork or ancestor::sourcecode)][contains(.,'—')]" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<xsl:call-template name="replace-substring">
<xsl:with-param name="string" select="."/>
<xsl:with-param name="replace">—</xsl:with-param>
<xsl:with-param name="by">--</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/" mode="cleanup">
<xsl:copy><xsl:apply-templates select="node()" mode="cleanup" /></xsl:copy>
</xsl:template>
<xsl:template match="*" mode="cleanup">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="node()|@*" mode="cleanup" />
</xsl:element>
</xsl:template>
<!-- remove PI extensions -->
<xsl:template match="processing-instruction('rfc-ext')" mode="cleanup"/>
<xsl:template match="processing-instruction('BEGININC')" mode="cleanup"/>
<xsl:template match="processing-instruction('ENDINC')" mode="cleanup"/>
<!-- process include PI -->
<xsl:template match="processing-instruction('rfc')" mode="cleanup">
<xsl:call-template name="process-pi"/>
</xsl:template>
<!-- add issues appendix -->
<xsl:template match="back" mode="cleanup">
<back>
<xsl:apply-templates select="node()|@*" mode="cleanup" />
<xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='closed']">
<section title="Resolved issues (to be removed by RFC Editor before publication)">
<t>
Issues that were either rejected or resolved in this version of this
document.
</t>
<xsl:apply-templates select="//ed:issue[@status='closed']" mode="issues" />
</section>
</xsl:if>
<xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='open']">
<section title="Open issues (to be removed by RFC Editor prior to publication)">
<xsl:apply-templates select="//ed:issue[@status!='closed']" mode="issues" />
</section>
</xsl:if>
</back>
</xsl:template>
<!-- V3 features -->
<xsl:template match="boilerplate" mode="cleanup"/>
<xsl:template match="link" mode="cleanup"/>
<xsl:template match="rfc/@scripts" mode="cleanup"/>
<xsl:template match="rfc/@version" mode="cleanup">
<xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
<xsl:template match="@pn" mode="cleanup"/>
<xsl:template match="br" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<br>
<xsl:apply-templates select="node()|@*" mode="cleanup" />
</br>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:u-map" mode="cleanup"/>
<xsl:template match="u" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<u>
<xsl:apply-templates select="node()|@*" mode="cleanup" />
</u>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="emit-u"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- experimental for QUIC tls draft -->
<xsl:template match="t/contact" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<contact>
<xsl:apply-templates select="node()|@*" mode="cleanup" />
</contact>
</xsl:when>
<xsl:when test="@asciiFullname">
<xsl:value-of select="@asciiFullname"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@fullname"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- extensions -->
<xsl:template match="x:abnf-char-sequence" mode="cleanup">
<xsl:choose>
<xsl:when test="substring(.,1,1) != '"' or substring(.,string-length(.),1) != '"'">
<xsl:call-template name="error">
<xsl:with-param name="inline">no</xsl:with-param>
<xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>%x</xsl:text>
<xsl:call-template name="to-abnf-char-sequence">
<xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:anchor-alias" mode="cleanup"/>
<xsl:template match="x:bcp14|bcp14" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<bcp14>
<xsl:apply-templates mode="cleanup"/>
</bcp14>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="cleanup"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:assign-section-number" mode="cleanup"/>
<xsl:template match="x:link" mode="cleanup"/>
<xsl:template match="x:source" mode="cleanup"/>
<xsl:template match="x:feedback" mode="cleanup"/>
<xsl:template match="date/@x:include-day" mode="cleanup"/>
<xsl:template match="x:parse-xml" mode="cleanup">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="x:prose" mode="cleanup">
<xsl:variable name="text" select="."/>
<xsl:comment>Converted from rfc2629.xslt x:prose extension</xsl:comment>
<xsl:choose>
<xsl:when test="contains($text,' ')">
<seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
</xsl:when>
<xsl:otherwise>
<seriesInfo name="" value="{$text}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="t/@keepWithNext|t/@keepWithPrevious" mode="cleanup"/>
<xsl:template match="refcontent" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<refcontent>
<xsl:apply-templates mode="cleanup"/>
</refcontent>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="text">
<xsl:apply-templates mode="cleanup"/>
</xsl:variable>
<xsl:comment>Converted from rfc2629.xslt refcontent extension</xsl:comment>
<xsl:choose>
<xsl:when test="contains($text,' ')">
<seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
</xsl:when>
<xsl:otherwise>
<seriesInfo name="" value="{$text}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="postalLine" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<postalLine>
<xsl:apply-templates mode="cleanup"/>
</postalLine>
</xsl:when>
<xsl:otherwise>
<xsl:comment>converted from v3 <postalLine></xsl:comment>
<street><xsl:value-of select="."/></street>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- workaround until xml2rfc understands postalLine and country combined -->
<xsl:template match="country[../postalLine]" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<postalLine>
<xsl:apply-templates mode="cleanup"/>
</postalLine>
</xsl:when>
<xsl:otherwise>
<country><xsl:value-of select="."/></country>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:ref" mode="cleanup">
<xsl:variable name="val" select="normalize-space(.)"/>
<xsl:variable name="target" select="//*[@anchor and (@anchor=$val or x:anchor-alias/@value=$val)][not(ancestor::ed:del)] | //reference/x:source[x:defines=$val]"/>
<xsl:if test="count($target)>1">
<xsl:message terminate="yes">FATAL: multiple x:ref targets found for <xsl:value-of select="$val"/>.</xsl:message>
</xsl:if>
<xsl:choose>
<xsl:when test="$target/self::x:source">
<!-- drop it-->
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="$target">
<xsl:variable name="current" select="."/>
<xsl:for-each select="$target">
<!-- make it the context -->
<xsl:choose>
<xsl:when test="self::preamble">
<!-- it's not an element we can link to -->
<xsl:call-template name="warning">
<xsl:with-param name="msg">couldn't create the link as <xsl:value-of select="name()"/> does not support the anchor attribute.</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="$current"/>
</xsl:when>
<xsl:otherwise>
<xref target="{$target/@anchor}" format="none"><xsl:value-of select="$current"/></xref>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:when test="//x:source">
<xsl:variable name="ref" select="."/>
<xsl:variable name="out">
<!-- try referenced documents one by one -->
<xsl:for-each select="//reference[x:source]">
<xsl:variable name="extdoc" select="document(x:source/@href)"/>
<xsl:variable name="nodes" select="$extdoc//*[@anchor and (x:anchor-alias/@value=$val)]"/>
<xsl:choose>
<xsl:when test="not($nodes)">
<xsl:call-template name="trace">
<xsl:with-param name="msg">Anchor '<xsl:value-of select="$val"/>' not found in source file '<xsl:value-of select="x:source/@href"/>'.</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="info">
<xsl:with-param name="msg">Anchor '<xsl:value-of select="$val"/>' found in source file '<xsl:value-of select="x:source/@href"/>'.</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="$ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:copy-of select="$out"/>
<xsl:if test="string-length($out)=0">
<xsl:call-template name="warning">
<xsl:with-param name="msg">Anchor '<xsl:value-of select="$val"/>' not found anywhere in references.</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="$val"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="warning">
<xsl:with-param name="msg">internal link target for '<xsl:value-of select="$val"/>' does not exist.</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:blockquote|blockquote" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<blockquote>
<xsl:apply-templates select="@*|node()" mode="cleanup"/>
</blockquote>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="blockquote-to-v2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="blockquote-to-v2">
<t>
<xsl:apply-templates select="@anchor" mode="cleanup"/>
<list>
<xsl:choose>
<xsl:when test="t|ul|ol|dl|artwork|figure|sourcecode">
<xsl:apply-templates mode="cleanup" />
</xsl:when>
<xsl:otherwise>
<t>
<xsl:apply-templates mode="cleanup" />
</t>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@quotedFrom">
<t>
<xsl:text>— </xsl:text>
<xsl:choose>
<xsl:when test="@cite"><eref target="{@cite}"><xsl:value-of select="@quotedFrom"/></eref></xsl:when>
<xsl:otherwise><xsl:value-of select="@quotedFrom"/></xsl:otherwise>
</xsl:choose>
</t>
</xsl:if>
</list>
</t>
</xsl:template>
<xsl:template match="li/blockquote" mode="cleanup">
<list style="empty">
<xsl:choose>
<xsl:when test="t|ul|ol|dl|artwork|figure|sourcecode">
<xsl:apply-templates mode="cleanup" />
</xsl:when>
<xsl:otherwise>
<t>
<xsl:apply-templates mode="cleanup" />
</t>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@quotedFrom">
<t>
<xsl:text>— </xsl:text>
<xsl:choose>
<xsl:when test="@cite"><eref target="{@cite}"><xsl:value-of select="@quotedFrom"/></eref></xsl:when>
<xsl:otherwise><xsl:value-of select="@quotedFrom"/></xsl:otherwise>
</xsl:choose>
</t>
</xsl:if>
</list>
</xsl:template>
<xsl:template match="x:h" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<strong>
<xsl:apply-templates mode="cleanup"/>
</strong>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="cleanup" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:highlight" mode="cleanup">
<xsl:apply-templates mode="cleanup" />
</xsl:template>
<xsl:template match="x:lt" mode="cleanup">
<t>
<xsl:apply-templates select="@hangText|@anchor" mode="cleanup"/>
<xsl:for-each select="t">
<xsl:apply-templates mode="cleanup"/>
<xsl:if test="position()!=last()">
<vspace blankLines="1"/>
</xsl:if>
</xsl:for-each>
</t>
</xsl:template>
<xsl:template match="x:note|aside" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<aside>
<xsl:apply-templates select="@*|node()" mode="cleanup"/>
</aside>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="aside-to-v2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="aside-to-v2">
<t>
<xsl:apply-templates select="@anchor" mode="cleanup"/>
<list>
<xsl:apply-templates mode="cleanup"/>
</list>
</t>
</xsl:template>
<xsl:template match="x:q" mode="cleanup">
<xsl:text>"</xsl:text>
<xsl:apply-templates mode="cleanup"/>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template match="x:dfn" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $xml2rfc-ext-map-dfn='em'">
<em><xsl:apply-templates mode="cleanup"/></em>
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
<xsl:apply-templates mode="cleanup"/>
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:sup|sup" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<sup><xsl:apply-templates select="@*|node()" mode="cleanup"/></sup>
</xsl:when>
<xsl:when test="@ascii!=''">
<xsl:value-of select="@ascii"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>^</xsl:text>
<xsl:apply-templates mode="cleanup" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="sub" mode="cleanup">
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<sub><xsl:apply-templates select="@*|node()" mode="cleanup"/></sub>
</xsl:when>
<xsl:when test="@ascii!=''">
<xsl:value-of select="@ascii"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>_</xsl:text>
<xsl:apply-templates mode="cleanup" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:span" mode="cleanup">
<xsl:apply-templates mode="cleanup" />
</xsl:template>
<xsl:template match="x:span/@anchor" mode="cleanup"/>
<xsl:template match="author/@asciiFullname" mode="cleanup"/>
<xsl:template match="author/@asciiInitials" mode="cleanup"/>
<xsl:template match="author/@asciiSurname" mode="cleanup"/>
<xsl:template match="author/@surname" mode="cleanup">
<xsl:choose>
<xsl:when test="../@asciiSurname!=''">
<xsl:attribute name="surname"><xsl:value-of select="../@asciiSurname"/></xsl:attribute>
<xsl:call-template name="warning">
<xsl:with-param name="msg">Replacing surname <xsl:value-of select="../@surname"/> by <xsl:value-of select="../@asciiSurname"/>.</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:copy/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="author/@fullname" mode="cleanup">
<xsl:choose>
<xsl:when test="../@asciiFullname!=''">
<xsl:attribute name="fullname"><xsl:value-of select="../@asciiFullname"/></xsl:attribute>
<xsl:call-template name="warning">
<xsl:with-param name="msg">Replacing fullname <xsl:value-of select="../@fullname"/> by <xsl:value-of select="../@asciiFullname"/>.</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:copy/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="author/@initials" mode="cleanup">
<xsl:choose>
<xsl:when test="../@asciiInitials!=''">
<xsl:attribute name="initials"><xsl:value-of select="../@asciiInitials"/></xsl:attribute>
<xsl:call-template name="warning">
<xsl:with-param name="msg">Replacing initials <xsl:value-of select="../@initials"/> by <xsl:value-of select="../@asciiInitials"/>.</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:copy/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="author/@anchor" mode="cleanup"/>
<xsl:template match="x:include-author" mode="cleanup">
<t>
<xsl:value-of select="/*/front/author[@anchor=current()/@target]"/>
</t>
<t>
(see Authors Section)
</t>
</xsl:template>
<xsl:template match="organization/@ascii" mode="cleanup"/>
<xsl:template match="organization" mode="cleanup">
<organization>
<xsl:apply-templates select="@*" mode="cleanup"/>
<xsl:choose>
<xsl:when test="@ascii!=''">
<xsl:value-of select="@ascii"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</organization>
</xsl:template>
<xsl:template match="title/@ascii" mode="cleanup"/>
<xsl:template match="title" mode="cleanup">
<title>
<xsl:apply-templates select="@*" mode="cleanup"/>
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:when>
<xsl:when test="@ascii!=''">
<xsl:value-of select="@ascii"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="self::br">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="self::*">
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:when>
<xsl:when test="self::processing-instruction()"/>
<xsl:otherwise>
<xsl:value-of select="normalize-space(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</title>
</xsl:template>
<xsl:template match="@x:optional-ascii" mode="cleanup"/>
<xsl:template match="@ascii" mode="cleanup"/>
<xsl:template match="postal/*[@ascii or @x:optional-ascii]" mode="cleanup">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*" mode="cleanup"/>
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
<xsl:copy-of select="@ascii"/>
<xsl:if test="@x:optional-ascii and not(@ascii)">
<!-- workaround for https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/443 -->
<xsl:attribute name="ascii"><xsl:value-of select="@x:optional-ascii"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:when test="@ascii!=''">
<xsl:value-of select="@ascii"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<xsl:template match="postal" mode="cleanup">
<postal>
<xsl:apply-templates select="@*" mode="cleanup"/>
<xsl:if test="not(street) and not(postalLine) and not($xml2rfc-ext-xml2rfc-voc >= 3)">
<!-- street is mandatory in V2 -->
<street/>
</xsl:if>
<xsl:apply-templates select="node()" mode="cleanup"/>
</postal>
</xsl:template>
<!-- not supported -->
<xsl:template match="relref/@format" mode="cleanup"/>
<xsl:template name="obtain-sec-n">
<xsl:variable name="t">
<xsl:call-template name="get-section-number"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="starts-with($t,$unnumbered)">
<xsl:choose>
<xsl:when test="ancestor::back">A@</xsl:when>
<xsl:otherwise>S@</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="get-title-as-string">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$t"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel or @section or @relative) and not(*|text())]|relref[not(*|text())]" mode="cleanup">
<xsl:call-template name="insert-iref-for-xref"/>
<xsl:variable name="is-xref" select="self::xref"/>
<xsl:variable name="node" select="$src//*[@anchor=current()/@target]" />
<xsl:variable name="rel" select="@x:rel|@relative"/>
<xsl:variable name="ssec">
<xsl:call-template name="get-section-xref-section"/>
</xsl:variable>
<xsl:variable name="tsec">
<xsl:choose>
<xsl:when test="starts-with($rel,'#') and $ssec='' and $node/x:source/@href">
<xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
<xsl:variable name="targets" select="$extdoc//*[@anchor=substring-after($rel,'#')]"/>
<xsl:choose>
<xsl:when test="count($targets)=0">
<xsl:variable name="targets2" select="$extdoc//*[x:anchor-alias/@value=substring-after($rel,'#')]"/>
<xsl:choose>
<xsl:when test="count($targets2)!=1">
<xsl:call-template name="error">
<xsl:with-param name="inline">no</xsl:with-param>
<xsl:with-param name="msg">Can not resolve section number for relative value <xsl:value-of select="$rel"/> on reference <xsl:value-of select="@target"/> (found <xsl:value-of select="count($targets2)"/> targets)</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$targets2">
<xsl:call-template name="obtain-sec-n"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="count($targets)!=1">
<xsl:call-template name="error">
<xsl:with-param name="inline">no</xsl:with-param>
<xsl:with-param name="msg">Can not resolve section number for relative value <xsl:value-of select="$rel"/> on reference <xsl:value-of select="@target"/> (found <xsl:value-of select="count($targets)"/> targets)</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$targets">
<xsl:call-template name="obtain-sec-n"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ssec"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sec">
<xsl:choose>
<xsl:when test="contains($tsec,'@')">"<xsl:value-of select="substring-after($tsec,'@')"/>"</xsl:when>
<xsl:otherwise><xsl:value-of select="$tsec"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="secterm">
<xsl:choose>
<!-- starts with letter or unnumbered? -->
<xsl:when test="translate(substring($sec,1,1),$ucase,'')='' or starts-with($tsec,'A@')">Appendix</xsl:when>
<xsl:otherwise>Section</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sfmt">
<xsl:call-template name="get-section-xref-format">
<xsl:with-param name="default">
<xsl:choose>
<xsl:when test="ancestor::artwork or ancestor::sourcecode">comma</xsl:when>
<xsl:otherwise>of</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!--<xsl:comment><xsl:value-of select="concat($sfmt, ' ', $tsec, ' ', @x:sec)"/></xsl:comment>-->
<xsl:choose>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='of'">
<xref target="{@target}" section="{$tsec}">
<xsl:if test="$rel!='' and (@x:sec or @section)">
<xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
</xsl:if>
</xref>
</xsl:when>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='comma'">
<xref target="{@target}" sectionFormat="comma" section="{$tsec}">
<xsl:if test="$rel!='' and (@x:sec or @section)">
<xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
</xsl:if>
</xref>
</xsl:when>
<xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='bare'">
<xref target="{@target}" sectionFormat="bare" section="{$tsec}">
<xsl:if test="$rel!='' and (@x:sec or @section)">
<xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
</xsl:if>
</xref>
</xsl:when>
<xsl:when test="$sfmt='comma'">
<xref>
<xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
</xref>
<xsl:text>, </xsl:text>
<xsl:value-of select="$secterm"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$sec"/>
</xsl:when>
<xsl:when test="$sfmt='section'">
<xsl:value-of select="$secterm"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$sec"/>
</xsl:when>
<xsl:when test="$sfmt='bare'">
<xsl:value-of select="$sec"/>
</xsl:when>
<xsl:when test="$sfmt='parens'">
<xref>
<xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
</xref>
<xsl:text> (</xsl:text>
<xsl:value-of select="$secterm"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$sec"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="$sfmt='of'">
<xsl:value-of select="$secterm"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$sec"/>
<xsl:text> of </xsl:text>
<xref>
<xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
</xref>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="abstract/@anchor" mode="cleanup"/>
<xsl:template match="note/@anchor" mode="cleanup"/>
<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel) and (*|text())]|relref[*|text()]" mode="cleanup">
<xsl:call-template name="insert-iref-for-xref"/>
<xsl:choose>
<xsl:when test="self::relref">
<xsl:apply-templates mode="cleanup"/>
</xsl:when>
<xsl:when test="@x:fmt='none'">
<xsl:apply-templates mode="cleanup"/>
</xsl:when>
<xsl:when test="not(@x:fmt)">
<xref>
<xsl:copy-of select="@target|@format"/>
<xsl:apply-templates mode="cleanup"/>
</xref>
</xsl:when>
<xsl:otherwise>
<xsl:message>Unsupported x:fmt attribute.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xref[(text()|*) and (@target=//abstract/@anchor or @target=//note/@anchor or @target=//preamble/@anchor or @target=//spanx/@anchor or @target=//name//@anchor or @target=//references/@anchor or @target=//artwork/@anchor or @target=//sourcecode/@anchor or @target=//artset/@anchor or @target=//strong/@anchor)]" mode="cleanup">
<!-- remove the link -->
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:template>
<xsl:template match="xref[(text()|*) and @format='none' and (@target=//artwork//*/@anchor or @target=//sourcecode//*/@anchor)]" mode="cleanup" priority="9">
<!-- remove links to elements inside <artwork> or <sourcecode> -->
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:template>
<xsl:template match="xref[not((text()|*)) and (@target=//abstract/@anchor or @target=//note/@anchor or @target=//preamble/@anchor or @target=//spanx/@anchor or @target=//references/@anchor or @target=//artwork/@anchor or @target=//sourcecode/@anchor or @target=//artset/@anchor or @target=//strong/@anchor)]" mode="cleanup">
<xsl:variable name="content">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:value-of select="$content"/>
</xsl:template>
<xsl:template match="xref[not((text()|*)) and (not(@format) or @format='default') and (@target=//section[@numbered='false']/@anchor)]" mode="cleanup">
<!-- link to unnumbered section -->
<xsl:copy>
<xsl:copy-of select="@target"/>
<xsl:variable name="content">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:value-of select="$content"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xref" mode="cleanup" priority="0">
<xsl:call-template name="insert-iref-for-xref"/>
<xref>
<xsl:apply-templates select="@target|@format" mode="cleanup"/>