source: rfc2629xslt/clean-for-DTD.xslt

Last change on this file was 2762, checked in by julian.reschke@…, 11 months ago

update specs and rfc2629.xslt

  • Property svn:eol-style set to native
File size: 88.2 KB
Line 
1<!--
2    Strip rfc2629.xslt extensions, generating XML input for "official" xml2rfc
3
4    Copyright (c) 2006-2021, Julian Reschke (julian.reschke@greenbytes.de)
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions are met:
9
10    * Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    * Neither the name of Julian Reschke nor the names of its contributors
16      may be used to endorse or promote products derived from this software
17      without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33                version="1.0"
34                xmlns:exslt="http://exslt.org/common"
35                xmlns:ed="http://greenbytes.de/2002/rfcedit"
36                xmlns:grddl="http://www.w3.org/2003/g/data-view#"
37                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
38                xmlns:svg="http://www.w3.org/2000/svg"
39                xmlns:x="http://purl.org/net/xml2rfc/ext"
40                xmlns:xi="http://www.w3.org/2001/XInclude"
41                xmlns:xhtml="http://www.w3.org/1999/xhtml"
42                exclude-result-prefixes="ed exslt grddl rdf svg x xi xhtml"
43>
44
45<!-- re-use some of the default RFC2629.xslt rules -->
46<xsl:import href="rfc2629-no-doctype.xslt"/>
47
48<!-- undo strip-space decls -->
49<xsl:preserve-space elements="*"/>
50
51<!-- generate UTF-8 XML with no doctype decl and artwork/sourcecode serialized as CDATA -->
52<xsl:output method="xml" version="1.0" encoding="UTF-8" cdata-section-elements="artwork sourcecode" />
53
54<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
55<xsl:param name="xml2rfc-ext-strip-vbare">false</xsl:param>
56
57<!-- xml2rfc target -->
58<xsl:param name="xml2rfc-ext-xml2rfc-backend">
59  <xsl:variable name="default">
60    <xsl:choose>
61      <xsl:when test="$pub-yearmonth &gt;= 201705">201706</xsl:when>
62      <xsl:when test="$pub-yearmonth &gt; 201612">201610</xsl:when>
63      <xsl:otherwise>201510</xsl:otherwise>
64    </xsl:choose>
65  </xsl:variable>
66  <xsl:call-template name="parse-pis">
67    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
68    <xsl:with-param name="attr" select="'xml2rfc-backend'"/>
69    <xsl:with-param name="default" select="$default"/>
70  </xsl:call-template>
71</xsl:param>
72<xsl:param name="xml2rfc-ext-xml2rfc-voc">2</xsl:param>
73
74<!-- kick into cleanup mode -->
75<xsl:template match="/">
76  <xsl:text>&#10;</xsl:text>
77  <xsl:comment>
78    This XML document is the output of clean-for-DTD.xslt; a tool that strips
79    extensions to RFC 7749 from documents for processing with xml2rfc.
80</xsl:comment>
81<xsl:text>&#10;</xsl:text>
82<xsl:comment>TARGET-GENERATOR: <xsl:value-of select="$xml2rfc-ext-xml2rfc-backend"/></xsl:comment>
83<xsl:text>&#10;</xsl:text>
84<xsl:comment>TARGET-VOCABULARY: <xsl:value-of select="$xml2rfc-ext-xml2rfc-voc"/></xsl:comment>
85  <xsl:apply-templates select="/" mode="cleanup"/>
86</xsl:template>
87
88<!-- rules for identity transformations -->
89
90<xsl:template match="processing-instruction()" mode="cleanup">
91  <xsl:text>&#10;</xsl:text>
92  <xsl:copy/>
93</xsl:template>
94
95<xsl:template match="comment()|@*" mode="cleanup"><xsl:copy/></xsl:template>
96
97<xsl:template match="text()" mode="cleanup"><xsl:copy/></xsl:template>
98
99<xsl:template match="/" mode="cleanup">
100        <xsl:copy><xsl:apply-templates select="node()" mode="cleanup" /></xsl:copy>
101</xsl:template>
102
103<xsl:template match="*" mode="cleanup">
104  <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
105        <xsl:apply-templates select="node()|@*" mode="cleanup" />
106  </xsl:element>
107</xsl:template>
108
109
110<!-- remove PI extensions -->
111
112<xsl:template match="processing-instruction('rfc-ext')" mode="cleanup"/>
113<xsl:template match="processing-instruction('BEGININC')" mode="cleanup"/>
114<xsl:template match="processing-instruction('ENDINC')" mode="cleanup"/>
115
116<!-- process include PI -->
117<xsl:template match="processing-instruction('rfc')" mode="cleanup">
118  <xsl:variable name="include">
119    <xsl:call-template name="parse-pis">
120      <xsl:with-param name="nodes" select="."/>
121      <xsl:with-param name="attr" select="'include'"/>
122    </xsl:call-template>
123  </xsl:variable>
124  <xsl:choose>
125    <xsl:when test="$include=''">
126      <xsl:text>&#10;</xsl:text>
127      <xsl:copy/>
128    </xsl:when>
129    <xsl:otherwise>
130      <xsl:variable name="content">
131        <xsl:call-template name="obtain-reference-for-include-PI">
132          <xsl:with-param name="uri" select="$include"/>
133        </xsl:call-template>
134      </xsl:variable> 
135      <xsl:apply-templates select="exslt:node-set($content)//reference" mode="cleanup"/>
136    </xsl:otherwise>
137  </xsl:choose>
138</xsl:template>
139
140
141<!-- add issues appendix -->
142
143<xsl:template match="back" mode="cleanup">
144  <back>
145    <xsl:apply-templates select="node()|@*" mode="cleanup" />
146    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='closed']">
147      <section title="Resolved issues (to be removed by RFC Editor before publication)">
148        <t>
149          Issues that were either rejected or resolved in this version of this
150          document.
151        </t>
152        <xsl:apply-templates select="//ed:issue[@status='closed']" mode="issues" />
153      </section>
154    </xsl:if>
155    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='open']">
156      <section title="Open issues (to be removed by RFC Editor prior to publication)">
157        <xsl:apply-templates select="//ed:issue[@status!='closed']" mode="issues" />
158      </section>
159    </xsl:if>
160  </back>
161</xsl:template>
162
163
164<!-- V3 features -->
165
166<xsl:template match="boilerplate" mode="cleanup"/>
167<xsl:template match="link" mode="cleanup"/>
168<xsl:template match="rfc/@scripts" mode="cleanup"/>
169<xsl:template match="rfc/@version" mode="cleanup">
170  <xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3">
171    <xsl:copy-of select="."/>
172  </xsl:if>
173</xsl:template>
174<xsl:template match="@pn" mode="cleanup"/>
175
176<xsl:template match="br" mode="cleanup">
177  <xsl:choose>
178    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
179      <br>
180        <xsl:apply-templates select="node()|@*" mode="cleanup" />
181      </br>
182    </xsl:when>
183    <xsl:otherwise>
184      <xsl:text> </xsl:text>
185    </xsl:otherwise>
186  </xsl:choose>
187</xsl:template>
188
189<xsl:template match="x:u-map" mode="cleanup"/>
190<xsl:template match="u" mode="cleanup">
191  <xsl:choose>
192    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
193      <u>
194        <xsl:apply-templates select="node()|@*" mode="cleanup" />
195      </u>
196    </xsl:when>
197    <xsl:otherwise>
198      <xsl:call-template name="emit-u"/>
199    </xsl:otherwise>
200  </xsl:choose>
201</xsl:template>
202
203<!-- experimental for QUIC tls draft -->
204<xsl:template match="t/contact" mode="cleanup">
205  <xsl:choose>
206    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
207      <contact>
208        <xsl:apply-templates select="node()|@*" mode="cleanup" />
209      </contact>
210    </xsl:when>
211    <xsl:when test="@asciiFullname">
212      <xsl:value-of select="@asciiFullname"/>
213    </xsl:when>
214    <xsl:otherwise>
215      <xsl:value-of select="@fullname"/>
216    </xsl:otherwise>
217  </xsl:choose>
218</xsl:template>
219
220<!-- extensions -->
221
222<xsl:template match="x:abnf-char-sequence" mode="cleanup">
223  <xsl:choose>
224    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
225      <xsl:call-template name="error">
226        <xsl:with-param name="inline">no</xsl:with-param>
227        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
228      </xsl:call-template>
229    </xsl:when>
230    <xsl:otherwise>
231      <xsl:text>%x</xsl:text>
232      <xsl:call-template name="to-abnf-char-sequence">
233        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
234      </xsl:call-template>
235    </xsl:otherwise>
236  </xsl:choose>
237</xsl:template>
238
239<xsl:template match="x:anchor-alias" mode="cleanup"/>
240
241<xsl:template match="x:bcp14|bcp14" mode="cleanup">
242  <xsl:choose>
243    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
244      <bcp14>
245        <xsl:apply-templates mode="cleanup"/>
246      </bcp14>
247    </xsl:when>
248    <xsl:otherwise>
249      <xsl:apply-templates mode="cleanup"/>
250    </xsl:otherwise>
251  </xsl:choose>
252</xsl:template>
253
254<xsl:template match="x:assign-section-number" mode="cleanup"/> 
255<xsl:template match="x:link" mode="cleanup"/>
256<xsl:template match="x:source" mode="cleanup"/>
257<xsl:template match="x:feedback" mode="cleanup"/>
258<xsl:template match="date/@x:include-day" mode="cleanup"/>
259
260<xsl:template match="x:parse-xml" mode="cleanup">
261  <xsl:apply-templates/>
262</xsl:template>
263
264<xsl:template match="x:prose" mode="cleanup">
265  <xsl:variable name="text" select="."/>
266  <xsl:comment>Converted from rfc2629.xslt x:prose extension</xsl:comment>
267  <xsl:choose>
268    <xsl:when test="contains($text,' ')">
269      <seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
270    </xsl:when>
271    <xsl:otherwise>
272      <seriesInfo name="" value="{$text}"/>
273    </xsl:otherwise>
274  </xsl:choose>
275</xsl:template>
276
277<xsl:template match="t/@keepWithNext|t/@keepWithPrevious" mode="cleanup"/>
278
279<xsl:template match="refcontent" mode="cleanup">
280  <xsl:choose>
281    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
282      <refcontent>
283        <xsl:apply-templates mode="cleanup"/>
284      </refcontent>
285    </xsl:when>
286    <xsl:otherwise>
287      <xsl:variable name="text">
288        <xsl:apply-templates mode="cleanup"/>
289      </xsl:variable>
290      <xsl:comment>Converted from rfc2629.xslt refcontent extension</xsl:comment>
291      <xsl:choose>
292        <xsl:when test="contains($text,' ')">
293          <seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
294        </xsl:when>
295        <xsl:otherwise>
296          <seriesInfo name="" value="{$text}"/>
297        </xsl:otherwise>
298      </xsl:choose>
299    </xsl:otherwise>
300  </xsl:choose>
301</xsl:template>
302
303<xsl:template match="postalLine" mode="cleanup">
304  <xsl:choose>
305    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
306      <postalLine>
307        <xsl:apply-templates mode="cleanup"/>
308      </postalLine>
309    </xsl:when>
310    <xsl:otherwise>
311      <xsl:comment>converted from v3 &lt;postalLine&gt;</xsl:comment>
312      <street><xsl:value-of select="."/></street>
313    </xsl:otherwise>
314  </xsl:choose>
315</xsl:template>
316
317<!-- workaround until xml2rfc understands postalLine and country combined -->
318<xsl:template match="country[../postalLine]" mode="cleanup">
319  <xsl:choose>
320    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
321      <postalLine>
322        <xsl:apply-templates mode="cleanup"/>
323      </postalLine>
324    </xsl:when>
325    <xsl:otherwise>
326      <country><xsl:value-of select="."/></country>
327    </xsl:otherwise>
328  </xsl:choose>
329</xsl:template>
330
331<xsl:template match="x:ref" mode="cleanup">
332  <xsl:variable name="val" select="normalize-space(.)"/>
333  <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]"/>
334  <xsl:if test="count($target)>1">
335    <xsl:message terminate="yes">FATAL: multiple x:ref targets found for <xsl:value-of select="$val"/>.</xsl:message>
336  </xsl:if>
337  <xsl:choose>
338    <xsl:when test="$target/self::x:source">
339      <!-- drop it-->
340      <xsl:value-of select="."/>
341    </xsl:when>
342    <xsl:when test="$target">
343      <xsl:variable name="current" select="."/>
344      <xsl:for-each select="$target">
345        <!-- make it the context -->
346        <xsl:choose>
347          <xsl:when test="self::preamble">
348            <!-- it's not an element we can link to -->
349            <xsl:call-template name="warning">
350              <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>
351            </xsl:call-template>
352            <xsl:value-of select="$current"/>
353          </xsl:when>
354          <xsl:otherwise>
355            <xref target="{$target/@anchor}" format="none"><xsl:value-of select="$current"/></xref>
356          </xsl:otherwise>
357        </xsl:choose>
358      </xsl:for-each>
359    </xsl:when>
360    <xsl:when test="//x:source">
361      <xsl:variable name="ref" select="."/>
362      <xsl:variable name="out">
363        <!-- try referenced documents one by one -->
364        <xsl:for-each select="//reference[x:source]">
365          <xsl:variable name="extdoc" select="document(x:source/@href)"/>
366          <xsl:variable name="nodes" select="$extdoc//*[@anchor and (x:anchor-alias/@value=$val)]"/>
367          <xsl:choose>
368            <xsl:when test="not($nodes)">
369              <xsl:call-template name="trace">
370                <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>
371              </xsl:call-template>
372            </xsl:when>
373            <xsl:otherwise>
374              <xsl:call-template name="info">
375                <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>
376              </xsl:call-template>
377              <xsl:value-of select="$ref"/>
378            </xsl:otherwise>
379          </xsl:choose>
380        </xsl:for-each>
381      </xsl:variable>
382      <xsl:copy-of select="$out"/>
383      <xsl:if test="string-length($out)=0">
384        <xsl:call-template name="warning">
385          <xsl:with-param name="msg">Anchor '<xsl:value-of select="$val"/>' not found anywhere in references.</xsl:with-param>
386        </xsl:call-template>
387        <xsl:value-of select="$val"/>
388      </xsl:if>
389    </xsl:when>
390    <xsl:otherwise>
391      <xsl:call-template name="warning">
392        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="$val"/>' does not exist.</xsl:with-param>
393      </xsl:call-template>
394      <xsl:value-of select="."/>
395    </xsl:otherwise>
396  </xsl:choose>
397</xsl:template>
398
399<xsl:template match="x:blockquote|blockquote" mode="cleanup">
400  <xsl:choose>
401    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
402      <blockquote>
403        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
404      </blockquote>
405    </xsl:when>
406    <xsl:otherwise>
407      <xsl:call-template name="blockquote-to-v2"/>
408    </xsl:otherwise>
409  </xsl:choose>
410</xsl:template>
411
412<xsl:template name="blockquote-to-v2">
413  <t>
414    <xsl:apply-templates select="@anchor" mode="cleanup"/>
415    <list>
416      <xsl:choose>
417        <xsl:when test="t|ul|ol|dl|artwork|figure|sourcecode">
418          <xsl:apply-templates mode="cleanup" />
419        </xsl:when>
420        <xsl:otherwise>
421          <t>
422            <xsl:apply-templates mode="cleanup" />
423          </t>
424        </xsl:otherwise>
425      </xsl:choose>
426      <xsl:if test="@quotedFrom">
427        <t>
428          <xsl:text>&#8212; </xsl:text>
429          <xsl:choose>
430            <xsl:when test="@cite"><eref target="{@cite}"><xsl:value-of select="@quotedFrom"/></eref></xsl:when>
431            <xsl:otherwise><xsl:value-of select="@quotedFrom"/></xsl:otherwise>
432          </xsl:choose>
433        </t>
434      </xsl:if>
435    </list>
436  </t>
437</xsl:template>
438
439<xsl:template match="li/blockquote" mode="cleanup">
440  <list style="empty">
441    <xsl:choose>
442      <xsl:when test="t|ul|ol|dl|artwork|figure|sourcecode">
443        <xsl:apply-templates mode="cleanup" />
444      </xsl:when>
445      <xsl:otherwise>
446        <t>
447          <xsl:apply-templates mode="cleanup" />
448        </t>
449      </xsl:otherwise>
450    </xsl:choose>
451    <xsl:if test="@quotedFrom">
452      <t>
453        <xsl:text>&#8212; </xsl:text>
454        <xsl:choose>
455          <xsl:when test="@cite"><eref target="{@cite}"><xsl:value-of select="@quotedFrom"/></eref></xsl:when>
456          <xsl:otherwise><xsl:value-of select="@quotedFrom"/></xsl:otherwise>
457        </xsl:choose>
458      </t>
459    </xsl:if>
460  </list>
461</xsl:template>
462
463<xsl:template match="x:h" mode="cleanup">
464  <xsl:choose>
465    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
466      <strong>
467        <xsl:apply-templates mode="cleanup"/>
468      </strong>
469    </xsl:when>
470    <xsl:otherwise>
471      <xsl:apply-templates mode="cleanup" />
472    </xsl:otherwise>
473  </xsl:choose>
474</xsl:template>
475
476<xsl:template match="x:highlight" mode="cleanup">
477  <xsl:apply-templates mode="cleanup" />
478</xsl:template>
479
480<xsl:template match="x:lt" mode="cleanup">
481  <t>
482    <xsl:apply-templates select="@hangText|@anchor" mode="cleanup"/>
483    <xsl:for-each select="t">
484      <xsl:apply-templates mode="cleanup"/>
485      <xsl:if test="position()!=last()">
486        <vspace blankLines="1"/>
487      </xsl:if>
488    </xsl:for-each>
489  </t>
490</xsl:template>
491
492<xsl:template match="x:note|aside" mode="cleanup">
493  <xsl:choose>
494    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
495      <aside>
496        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
497      </aside>
498    </xsl:when>
499    <xsl:otherwise>
500      <xsl:call-template name="aside-to-v2"/>
501    </xsl:otherwise>
502  </xsl:choose>
503</xsl:template>
504
505<xsl:template name="aside-to-v2">
506  <t>
507    <xsl:apply-templates select="@anchor" mode="cleanup"/>
508    <list>
509      <xsl:apply-templates mode="cleanup"/>
510    </list>
511  </t>
512</xsl:template>
513
514<xsl:template match="x:q" mode="cleanup">
515  <xsl:text>"</xsl:text>
516  <xsl:apply-templates mode="cleanup"/>
517  <xsl:text>"</xsl:text>
518</xsl:template>
519
520<xsl:template match="x:dfn" mode="cleanup">
521  <!-- help xml2rfc to keep dfn and following text on the same page -->
522  <!-- removed for now because it broke httpbis-p2 (def of 200 OK in -25)
523  <xsl:if test="not(preceding-sibling::x:dfn) and count(following-sibling::list)=1 and normalize-space(../text()='')">
524    <xsl:processing-instruction name="rfc">needLines="4"</xsl:processing-instruction>
525  </xsl:if>-->
526    <xsl:choose>
527      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
528        <em><xsl:apply-templates mode="cleanup"/></em>
529      </xsl:when>
530      <xsl:when test="@ascii!=''">
531        <xsl:value-of select="@ascii"/>
532      </xsl:when>
533      <xsl:otherwise>
534        <xsl:apply-templates mode="cleanup"/>
535      </xsl:otherwise>
536    </xsl:choose>
537</xsl:template>
538
539<xsl:template match="x:sup|sup" mode="cleanup">
540    <xsl:choose>
541      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
542        <sup><xsl:apply-templates select="@*|node()" mode="cleanup"/></sup>
543      </xsl:when>
544      <xsl:when test="@ascii!=''">
545        <xsl:value-of select="@ascii"/>
546      </xsl:when>
547      <xsl:otherwise>
548        <xsl:text>^</xsl:text>
549        <xsl:apply-templates mode="cleanup" />
550      </xsl:otherwise>
551    </xsl:choose>
552</xsl:template>
553
554<xsl:template match="sub" mode="cleanup">
555    <xsl:choose>
556      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
557        <sub><xsl:apply-templates select="@*|node()" mode="cleanup"/></sub>
558      </xsl:when>
559      <xsl:when test="@ascii!=''">
560        <xsl:value-of select="@ascii"/>
561      </xsl:when>
562      <xsl:otherwise>
563        <xsl:text>_</xsl:text>
564        <xsl:apply-templates mode="cleanup" />
565      </xsl:otherwise>
566    </xsl:choose>
567</xsl:template>
568
569<xsl:template match="x:span" mode="cleanup">
570  <xsl:apply-templates mode="cleanup" />
571</xsl:template>
572<xsl:template match="x:span/@anchor" mode="cleanup"/>
573
574<xsl:template match="author/@asciiFullname" mode="cleanup"/>
575<xsl:template match="author/@asciiInitials" mode="cleanup"/>
576<xsl:template match="author/@asciiSurname" mode="cleanup"/>
577
578<xsl:template match="author/@surname" mode="cleanup">
579  <xsl:choose>
580    <xsl:when test="../@asciiSurname!=''">
581      <xsl:attribute name="surname"><xsl:value-of select="../@asciiSurname"/></xsl:attribute>
582      <xsl:call-template name="warning">
583        <xsl:with-param name="msg">Replacing surname <xsl:value-of select="../@surname"/> by <xsl:value-of select="../@asciiSurname"/>.</xsl:with-param>
584      </xsl:call-template>
585    </xsl:when>
586    <xsl:otherwise><xsl:copy/></xsl:otherwise>
587  </xsl:choose>
588</xsl:template>
589
590<xsl:template match="author/@fullname" mode="cleanup">
591  <xsl:choose>
592    <xsl:when test="../@asciiFullname!=''">
593      <xsl:attribute name="fullname"><xsl:value-of select="../@asciiFullname"/></xsl:attribute>
594      <xsl:call-template name="warning">
595        <xsl:with-param name="msg">Replacing fullname <xsl:value-of select="../@fullname"/> by <xsl:value-of select="../@asciiFullname"/>.</xsl:with-param>
596      </xsl:call-template>
597    </xsl:when>
598    <xsl:otherwise><xsl:copy/></xsl:otherwise>
599  </xsl:choose>
600</xsl:template>
601
602<xsl:template match="author/@initials" mode="cleanup">
603  <xsl:choose>
604    <xsl:when test="../@asciiInitials!=''">
605      <xsl:attribute name="initials"><xsl:value-of select="../@asciiInitials"/></xsl:attribute>
606      <xsl:call-template name="warning">
607        <xsl:with-param name="msg">Replacing initials <xsl:value-of select="../@initials"/> by <xsl:value-of select="../@asciiInitials"/>.</xsl:with-param>
608      </xsl:call-template>
609    </xsl:when>
610    <xsl:otherwise><xsl:copy/></xsl:otherwise>
611  </xsl:choose>
612</xsl:template>
613
614<xsl:template match="author/@anchor" mode="cleanup"/>
615<xsl:template match="x:include-author" mode="cleanup">
616  <t>
617    <xsl:value-of select="/*/front/author[@anchor=current()/@target]"/>
618  </t>
619  <t>
620    (see Authors Section)
621  </t>
622</xsl:template>
623
624<xsl:template match="organization/@ascii" mode="cleanup"/>
625<xsl:template match="organization" mode="cleanup">
626  <organization>
627    <xsl:apply-templates select="@*" mode="cleanup"/>
628    <xsl:choose>
629      <xsl:when test="@ascii!=''">
630        <xsl:value-of select="@ascii"/>
631      </xsl:when>
632      <xsl:otherwise>
633        <xsl:value-of select="text()"/>
634      </xsl:otherwise>
635    </xsl:choose>
636  </organization>
637</xsl:template>
638
639<xsl:template match="title/@ascii" mode="cleanup"/>
640<xsl:template match="title" mode="cleanup">
641  <title>
642    <xsl:apply-templates select="@*" mode="cleanup"/>
643    <xsl:choose>
644      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
645        <xsl:apply-templates select="node()" mode="cleanup"/>
646      </xsl:when>
647      <xsl:when test="@ascii!=''">
648        <xsl:value-of select="@ascii"/>
649      </xsl:when>
650      <xsl:otherwise>
651        <xsl:for-each select="node()">
652          <xsl:choose>
653            <xsl:when test="self::br">
654              <xsl:text> </xsl:text>
655            </xsl:when>
656            <xsl:when test="self::*">
657              <xsl:apply-templates select="node()" mode="cleanup"/>
658            </xsl:when>
659            <xsl:when test="self::processing-instruction()"/>
660            <xsl:otherwise>
661              <xsl:value-of select="normalize-space(.)"/>
662            </xsl:otherwise>
663          </xsl:choose>
664        </xsl:for-each>
665      </xsl:otherwise>
666    </xsl:choose>
667  </title>
668</xsl:template>
669
670<xsl:template match="@x:optional-ascii" mode="cleanup"/>
671<xsl:template match="@ascii" mode="cleanup"/>
672<xsl:template match="postal/*[@ascii or @x:optional-ascii]" mode="cleanup">
673  <xsl:element name="{local-name()}">
674    <xsl:apply-templates select="@*" mode="cleanup"/>
675    <xsl:choose>
676      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
677        <xsl:copy-of select="@ascii"/>
678        <xsl:if test="@x:optional-ascii and not(@ascii)">
679          <!-- workaround for https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/443 -->
680          <xsl:attribute name="ascii"><xsl:value-of select="@x:optional-ascii"/></xsl:attribute>
681        </xsl:if>
682        <xsl:value-of select="text()"/>
683      </xsl:when>
684      <xsl:when test="@ascii!=''">
685        <xsl:value-of select="@ascii"/>
686      </xsl:when>
687      <xsl:otherwise>
688        <xsl:value-of select="text()"/>
689      </xsl:otherwise>
690    </xsl:choose>
691  </xsl:element>
692</xsl:template>
693
694<xsl:template match="postal" mode="cleanup">
695  <postal>
696    <xsl:apply-templates select="@*" mode="cleanup"/>
697    <xsl:if test="not(street) and not(postalLine) and not($xml2rfc-ext-xml2rfc-voc >= 3)">
698      <!-- street is mandatory in V2 -->
699      <street/>
700    </xsl:if>
701    <xsl:apply-templates select="node()" mode="cleanup"/>
702  </postal>
703</xsl:template>
704
705<!-- not supported -->
706<xsl:template match="relref/@format" mode="cleanup"/>
707
708<xsl:template name="obtain-sec-n">
709  <xsl:variable name="t">
710    <xsl:call-template name="get-section-number"/>
711  </xsl:variable>
712  <xsl:choose>
713    <xsl:when test="starts-with($t,$unnumbered)">
714      <xsl:choose>
715        <xsl:when test="ancestor::back">A@</xsl:when>
716        <xsl:otherwise>S@</xsl:otherwise>
717      </xsl:choose>
718      <xsl:call-template name="get-title-as-string">
719        <xsl:with-param name="node" select="."/>
720      </xsl:call-template>
721    </xsl:when>
722    <xsl:otherwise>
723      <xsl:value-of select="$t"/>
724    </xsl:otherwise>
725  </xsl:choose>
726</xsl:template>
727
728<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel or @section or @relative) and not(*|text())]|relref[not(*|text())]" mode="cleanup">
729  <xsl:call-template name="insert-iref-for-xref"/>
730  <xsl:variable name="is-xref" select="self::xref"/>
731  <xsl:variable name="node" select="$src//*[@anchor=current()/@target]" />
732  <xsl:variable name="rel" select="@x:rel|@relative"/>
733
734  <xsl:variable name="ssec">
735    <xsl:call-template name="get-section-xref-section"/>
736  </xsl:variable>
737
738  <xsl:variable name="tsec">
739    <xsl:choose>
740      <xsl:when test="starts-with($rel,'#') and $ssec='' and $node/x:source/@href">
741        <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
742        <xsl:variable name="targets" select="$extdoc//*[@anchor=substring-after($rel,'#')]"/>
743        <xsl:choose>
744          <xsl:when test="count($targets)=0">
745            <xsl:variable name="targets2" select="$extdoc//*[x:anchor-alias/@value=substring-after($rel,'#')]"/>
746            <xsl:choose>
747              <xsl:when test="count($targets2)!=1">
748                <xsl:call-template name="error">
749                  <xsl:with-param name="inline">no</xsl:with-param>
750                  <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>
751                </xsl:call-template>
752              </xsl:when>
753              <xsl:otherwise>
754                <xsl:for-each select="$targets2">
755                  <xsl:call-template name="obtain-sec-n"/>
756                </xsl:for-each>
757              </xsl:otherwise>
758            </xsl:choose>
759          </xsl:when>
760          <xsl:when test="count($targets)!=1">
761            <xsl:call-template name="error">
762              <xsl:with-param name="inline">no</xsl:with-param>
763              <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>
764            </xsl:call-template>
765          </xsl:when>
766          <xsl:otherwise>
767            <xsl:for-each select="$targets">
768              <xsl:call-template name="obtain-sec-n"/>
769            </xsl:for-each>
770          </xsl:otherwise>
771        </xsl:choose>
772      </xsl:when>
773      <xsl:otherwise>
774        <xsl:value-of select="$ssec"/>
775      </xsl:otherwise>
776    </xsl:choose>
777  </xsl:variable>
778 
779  <xsl:variable name="sec">
780    <xsl:choose>
781      <xsl:when test="contains($tsec,'@')">"<xsl:value-of select="substring-after($tsec,'@')"/>"</xsl:when>
782      <xsl:otherwise><xsl:value-of select="$tsec"/></xsl:otherwise>
783    </xsl:choose>
784  </xsl:variable>
785
786  <xsl:variable name="secterm">
787    <xsl:choose>
788      <!-- starts with letter or unnumbered? -->
789      <xsl:when test="translate(substring($sec,1,1),$ucase,'')='' or starts-with($tsec,'A@')">Appendix</xsl:when>
790      <xsl:otherwise>Section</xsl:otherwise>
791    </xsl:choose>
792  </xsl:variable>
793
794  <xsl:variable name="sfmt">
795    <xsl:call-template name="get-section-xref-format">
796      <xsl:with-param name="default">
797        <xsl:choose>
798          <xsl:when test="ancestor::artwork or ancestor::sourcecode">comma</xsl:when>
799          <xsl:otherwise>of</xsl:otherwise>
800        </xsl:choose>
801      </xsl:with-param>
802    </xsl:call-template>
803  </xsl:variable>
804 
805  <!--<xsl:comment><xsl:value-of select="concat($sfmt, ' ', $tsec, ' ', @x:sec)"/></xsl:comment>-->
806  <xsl:choose>
807    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='of'">
808      <xref target="{@target}" section="{$tsec}">
809        <xsl:if test="$rel!='' and (@x:sec or @section)">
810          <xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
811        </xsl:if>
812      </xref>
813    </xsl:when>
814    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='comma'">
815      <xref target="{@target}" sectionFormat="comma" section="{$tsec}">
816        <xsl:if test="$rel!='' and (@x:sec or @section)">
817          <xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
818        </xsl:if>
819      </xref>
820    </xsl:when>
821    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and $tsec!='' and not(contains($tsec,'@')) and $sfmt='bare'">
822      <xref target="{@target}" sectionFormat="bare" section="{$tsec}">
823        <xsl:if test="$rel!='' and (@x:sec or @section)">
824          <xsl:attribute name="relative"><xsl:value-of select="$rel"/></xsl:attribute>
825        </xsl:if>
826      </xref>
827    </xsl:when>
828    <xsl:when test="$sfmt='comma'">
829      <xref>
830        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
831      </xref>
832      <xsl:text>, </xsl:text>
833      <xsl:value-of select="$secterm"/>
834      <xsl:text> </xsl:text>
835      <xsl:value-of select="$sec"/>
836    </xsl:when>
837    <xsl:when test="$sfmt='section'">
838      <xsl:value-of select="$secterm"/>
839      <xsl:text> </xsl:text>
840      <xsl:value-of select="$sec"/>
841    </xsl:when>
842    <xsl:when test="$sfmt='bare'">
843      <xsl:value-of select="$sec"/>
844    </xsl:when>
845    <xsl:when test="$sfmt='parens'">
846      <xref>
847        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
848      </xref>
849      <xsl:text> (</xsl:text>
850      <xsl:value-of select="$secterm"/>
851      <xsl:text> </xsl:text>
852      <xsl:value-of select="$sec"/>
853      <xsl:text>)</xsl:text>
854    </xsl:when>
855    <xsl:when test="$sfmt='of'">
856      <xsl:value-of select="$secterm"/>
857      <xsl:text> </xsl:text>
858      <xsl:value-of select="$sec"/>
859      <xsl:text> of </xsl:text>
860      <xref>
861        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
862      </xref>
863    </xsl:when>
864    <xsl:otherwise>
865      <xsl:copy>
866        <xsl:apply-templates select="node()" mode="cleanup"/>
867      </xsl:copy>
868    </xsl:otherwise>
869  </xsl:choose>
870</xsl:template>
871
872<xsl:template match="abstract/@anchor" mode="cleanup"/>
873<xsl:template match="note/@anchor" mode="cleanup"/>
874
875<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel) and (*|text())]|relref[*|text()]" mode="cleanup">
876  <xsl:call-template name="insert-iref-for-xref"/>
877  <xsl:choose>
878    <xsl:when test="self::relref">
879      <xsl:apply-templates mode="cleanup"/>
880    </xsl:when>
881    <xsl:when test="@x:fmt='none'">
882      <xsl:apply-templates mode="cleanup"/>
883    </xsl:when>
884    <xsl:when test="not(@x:fmt)">
885      <xref>
886        <xsl:copy-of select="@target|@format"/>
887        <xsl:apply-templates mode="cleanup"/>
888      </xref>
889    </xsl:when>
890    <xsl:otherwise>
891      <xsl:message>Unsupported x:fmt attribute.</xsl:message>
892    </xsl:otherwise>
893  </xsl:choose>
894</xsl:template>
895
896<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">
897  <!-- remove the link -->
898  <xsl:apply-templates select="node()" mode="cleanup"/>
899</xsl:template>
900
901<xsl:template match="xref[(text()|*) and @format='none' and (@target=//artwork//*/@anchor or @target=//sourcecode//*/@anchor)]" mode="cleanup" priority="9">
902  <!-- remove links to elements inside <artwork> or <sourcecode> -->
903  <xsl:apply-templates select="node()" mode="cleanup"/>
904</xsl:template>
905
906<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">
907  <xsl:variable name="content">
908    <xsl:apply-templates select="."/>
909  </xsl:variable>
910  <xsl:value-of select="$content"/>
911</xsl:template>
912
913<xsl:template match="xref[not((text()|*)) and (not(@format) or @format='default') and (@target=//section[@numbered='false']/@anchor)]" mode="cleanup">
914  <!-- link to unnumbered section -->
915  <xsl:copy>
916    <xsl:copy-of select="@target"/>
917    <xsl:variable name="content">
918      <xsl:apply-templates select="."/>
919    </xsl:variable>
920    <xsl:value-of select="$content"/>
921  </xsl:copy>
922</xsl:template>
923
924<xsl:template match="xref" mode="cleanup" priority="0">
925  <xsl:call-template name="insert-iref-for-xref"/>
926  <xref>
927    <xsl:apply-templates select="@target|@format" mode="cleanup"/>
928    <xsl:choose>
929      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
930        <xsl:apply-templates mode="cleanup"/>
931      </xsl:when>
932      <xsl:otherwise>
933        <!-- remove markup -->
934        <xsl:variable name="t">
935          <xsl:apply-templates mode="cleanup"/>
936        </xsl:variable>
937        <xsl:value-of select="$t"/>
938      </xsl:otherwise>
939    </xsl:choose>
940  </xref>
941</xsl:template>
942
943<xsl:template name="insert-iref-for-xref">
944  <xsl:if test="$xml2rfc-ext-include-references-in-index='yesxxx' and $xml2rfc-ext-include-index='yes'">
945    <xsl:if test="@target=/rfc/back//reference/@anchor">
946      <iref item="{@target}"/>
947      <xsl:if test="@x:sec">
948        <xsl:choose>
949          <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
950            <iref item="{@target}" subitem="Appendix {@x:sec}"/>
951          </xsl:when>
952          <xsl:otherwise>
953            <iref item="{@target}" subitem="Section {@x:sec}"/>
954          </xsl:otherwise>
955        </xsl:choose>
956      </xsl:if>
957    </xsl:if>
958  </xsl:if>
959</xsl:template>
960
961
962<!-- workaround for https://tools.ietf.org/tools/ietfdb/ticket/2900 -->
963<xsl:template match="iref/comment()" mode="cleanup"/>
964
965<!-- drop index gen extension -->
966<xsl:template match="iref" mode="cleanup">
967  <xsl:if test="$xml2rfc-ext-include-index='yes'">
968    <iref>
969      <xsl:apply-templates select="@*|node()" mode="cleanup"/>
970    </iref>
971  </xsl:if>
972</xsl:template>
973
974
975<!-- issue tracking extensions -->
976
977<xsl:template match="@xml:lang" mode="cleanup"/>
978<xsl:template match="@xml:lang" />
979
980<xsl:template match="ed:*" mode="cleanup"/>
981<xsl:template match="ed:*" />
982
983<xsl:template match="@ed:*" mode="cleanup"/>
984<xsl:template match="@ed:*" />
985
986<xsl:template match="ed:annotation" mode="cleanup" />
987
988<xsl:template match="ed:replace" mode="cleanup">
989  <xsl:apply-templates mode="cleanup" />
990</xsl:template>
991
992<xsl:template match="ed:replace">
993  <xsl:apply-templates/>
994</xsl:template>
995
996<xsl:template match="ed:ins" mode="cleanup">
997  <xsl:apply-templates mode="cleanup"/>
998</xsl:template>
999
1000<xsl:template match="ed:ins">
1001  <xsl:apply-templates/>
1002</xsl:template>
1003
1004<xsl:template match="ed:issue" mode="issues">
1005  <section title="{@name}">
1006    <xsl:variable name="sec">
1007      <xsl:call-template name="get-section-number"/>
1008    </xsl:variable>
1009
1010    <xsl:if test="$sec!=''">
1011      <t>
1012        In Section <xsl:value-of select="$sec"/>:
1013      </t>
1014    </xsl:if>
1015   
1016    <t>
1017      Type: <xsl:value-of select="@type" />
1018    </t>
1019    <xsl:if test="@href">
1020      <t>
1021        <!-- temp. removed because of xml2rfc's handling of erefs when producing TXT-->
1022        <!--<eref target="{@href}" /> -->
1023        <xsl:text>&lt;</xsl:text>
1024        <xsl:value-of select="@href"/>
1025        <xsl:text>></xsl:text>
1026        <xsl:if test="@alternate-href">
1027          <xsl:text>, &lt;</xsl:text>
1028          <xsl:value-of select="@alternate-href"/>
1029          <xsl:text>></xsl:text>
1030        </xsl:if>
1031      </t>
1032    </xsl:if>
1033    <xsl:for-each select="ed:item">
1034      <t>
1035        <xsl:if test="@entered-by or @date">
1036          <xsl:choose>
1037            <xsl:when test="not(@entered-by)">
1038              <xsl:value-of select="concat('(',@date,') ')" />
1039            </xsl:when>
1040            <xsl:when test="not(@date)">
1041              <xsl:value-of select="concat(@entered-by,': ')" />
1042            </xsl:when>
1043            <xsl:otherwise>
1044              <xsl:value-of select="concat(@entered-by,' (',@date,'): ')" />
1045            </xsl:otherwise>
1046          </xsl:choose>     
1047        </xsl:if>
1048        <xsl:if test="not(xhtml:p)">
1049          <xsl:apply-templates select="node()" mode="issues"/>
1050        </xsl:if>
1051      </t>
1052      <xsl:if test="xhtml:p|xhtml:pre">
1053        <xsl:for-each select="node()">
1054          <xsl:choose>
1055            <xsl:when test="self::xhtml:p">
1056              <t>
1057                <xsl:apply-templates select="node()" mode="issues"/>
1058              </t>
1059            </xsl:when>
1060            <xsl:when test="self::xhtml:pre">
1061              <figure>
1062                <artwork><xsl:apply-templates select="node()" mode="issues"/></artwork>
1063              </figure>
1064            </xsl:when>
1065            <xsl:otherwise>
1066              <t>
1067                <xsl:apply-templates select="." mode="issues"/>
1068              </t>
1069            </xsl:otherwise>
1070          </xsl:choose>
1071        </xsl:for-each>
1072      </xsl:if>
1073    </xsl:for-each>
1074    <xsl:if test="ed:resolution">
1075      <t>
1076        <xsl:text>Resolution</xsl:text>
1077        <xsl:if test="ed:resolution/@datetime"> (<xsl:value-of select="ed:resolution/@datetime"/>)</xsl:if>
1078        <xsl:text>: </xsl:text>
1079        <xsl:value-of select="ed:resolution" />
1080      </t>
1081    </xsl:if>
1082  </section>
1083</xsl:template>
1084
1085<xsl:template match="ed:issueref" mode="cleanup">
1086  <xsl:apply-templates mode="cleanup"/>
1087</xsl:template>
1088
1089<xsl:template match="*" mode="issues">
1090  <xsl:apply-templates mode="issues"/>
1091</xsl:template>
1092
1093<xsl:template match="xhtml:q" mode="issues">
1094  <list><t>
1095    <xsl:text>"</xsl:text>
1096    <xsl:apply-templates mode="issues"/>
1097    <xsl:text>"</xsl:text>
1098    <xsl:if test="@cite">
1099      <xsl:text> -- </xsl:text>
1100      <eref target="{@cite}"><xsl:value-of select="@cite"/></eref>
1101    </xsl:if>
1102  </t></list>
1103</xsl:template>
1104
1105<xsl:template match="xhtml:br" mode="issues">
1106  <vspace/>
1107</xsl:template>
1108
1109<xsl:template match="xhtml:del" mode="issues">
1110  <xsl:text>&lt;del></xsl:text>
1111    <xsl:apply-templates mode="issues"/>
1112  <xsl:text>&lt;/del></xsl:text>
1113</xsl:template>
1114
1115<xsl:template match="xhtml:em" mode="issues">
1116  <spanx style="emph">
1117    <xsl:apply-templates mode="issues"/>
1118  </spanx>
1119</xsl:template>
1120
1121<xsl:template match="xhtml:ins" mode="issues">
1122  <xsl:text>&lt;ins></xsl:text>
1123    <xsl:apply-templates mode="issues"/>
1124  <xsl:text>&lt;/ins></xsl:text>
1125</xsl:template>
1126
1127<xsl:template match="xhtml:tt" mode="issues">
1128  <xsl:apply-templates mode="issues"/>
1129</xsl:template>
1130
1131<xsl:template match="ed:eref" mode="issues">
1132  <xsl:text>&lt;</xsl:text>
1133  <xsl:value-of select="."/>
1134  <xsl:text>&gt;</xsl:text>
1135</xsl:template>
1136
1137<xsl:template match="ed:issueref" mode="issues">
1138  <xsl:apply-templates mode="issues"/>
1139</xsl:template>
1140
1141<xsl:template match="text()" mode="issues">
1142  <xsl:value-of select="." />
1143</xsl:template>
1144
1145<!-- workgroup format -->
1146<xsl:template match="workgroup" mode="cleanup">
1147  <workgroup>
1148    <xsl:variable name="v" select="normalize-space(.)"/>
1149    <xsl:variable name="h">
1150      <!-- when a single name, append WG/RG postfix automatically -->
1151      <xsl:choose>
1152        <xsl:when test="not(contains($v, ' ')) and starts-with(/rfc/@docName,'draft-ietf-') and $submissionType='IETF'">
1153          <xsl:value-of select="concat($v, ' Working Group')"/>
1154        </xsl:when>
1155        <xsl:when test="not(contains($v, ' ')) and starts-with(/rfc/@docName,'draft-irtf-') and $submissionType='IRTF'">
1156          <xsl:value-of select="concat($v, ' Research Group')"/>
1157        </xsl:when>
1158        <xsl:otherwise>
1159          <xsl:value-of select="$v"/>
1160        </xsl:otherwise>
1161      </xsl:choose>
1162    </xsl:variable>
1163    <xsl:value-of select="$h"/>
1164  </workgroup>
1165</xsl:template>
1166
1167<!-- markup inside artwork element -->
1168
1169<xsl:template match="figure" mode="cleanup">
1170  <!-- move up iref elements -->
1171  <xsl:for-each select=".//artwork//xref">
1172    <xsl:if test="not(ancestor::ed:del)">
1173      <xsl:call-template name="insert-iref-for-xref"/>
1174    </xsl:if>
1175  </xsl:for-each>
1176  <figure>
1177    <xsl:apply-templates select="@align|@alt|@anchor|@height|@src|@suppress-title|@width" mode="cleanup" />
1178    <xsl:if test="not(@anchor) and artset/artwork/@anchor">
1179      <!-- propagate anchor -->
1180      <xsl:copy-of select="artset/artwork/@anchor[1]"/>
1181    </xsl:if>
1182    <xsl:variable name="title">
1183      <xsl:choose>
1184        <xsl:when test="name">
1185          <xsl:variable name="hold">
1186            <xsl:apply-templates select="name/node()"/>
1187          </xsl:variable>
1188          <xsl:value-of select="normalize-space($hold)"/>
1189        </xsl:when>
1190        <xsl:otherwise>
1191          <xsl:value-of select="@title"/>
1192        </xsl:otherwise>
1193      </xsl:choose>
1194    </xsl:variable>
1195    <xsl:if test="$title!=''">
1196      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1197    </xsl:if>
1198    <xsl:apply-templates select=".//artwork//iref|.//sourcecode//iref" mode="cleanup"/>
1199    <xsl:apply-templates select="iref|preamble|artwork|artset|sourcecode|postamble|ed:replace|ed:ins|ed:del" mode="cleanup" />
1200  </figure>
1201</xsl:template>
1202<xsl:template match="figure/name" mode="cleanup"/>
1203
1204<xsl:template name="insert-begin-code"/>
1205<xsl:template name="insert-end-code"/>
1206<xsl:template match="@x:is-code-component" mode="cleanup"/>
1207
1208<xsl:template match="artwork" mode="cleanup">
1209  <xsl:call-template name="handle-artwork"/>
1210</xsl:template>
1211
1212<xsl:template match="artwork[not(ancestor::figure)]" mode="cleanup">
1213  <xsl:choose>
1214    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1215      <xsl:call-template name="handle-artwork"/>
1216    </xsl:when>
1217    <xsl:when test="parent::blockquote">
1218      <t>
1219        <xsl:call-template name="bare-artwork-to-v2"/>
1220      </t>
1221    </xsl:when>
1222    <xsl:otherwise>
1223      <xsl:call-template name="bare-artwork-to-v2"/>
1224    </xsl:otherwise>
1225  </xsl:choose>
1226</xsl:template>
1227
1228<xsl:template name="bare-artwork-to-v2">
1229  <figure>
1230    <!-- propagate anchor -->
1231    <xsl:if test="parent::artset and not(../@anchor)">
1232      <xsl:copy-of select="@anchor"/>
1233    </xsl:if>
1234    <!-- move irefs up -->
1235    <xsl:apply-templates select="iref" mode="cleanup"/>
1236    <xsl:call-template name="handle-artwork"/>
1237  </figure>
1238</xsl:template>
1239
1240<xsl:template match="artwork/@anchor" mode="cleanup"/>
1241
1242<xsl:template name="handle-artwork">
1243  <xsl:choose>
1244    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and svg:svg">
1245      <artwork>
1246        <xsl:apply-templates select="@*" mode="cleanup"/>
1247        <xsl:apply-templates select="*" mode="cleanup"/>
1248      </artwork>
1249    </xsl:when>
1250    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1251      <xsl:apply-templates select=".//iref" mode="cleanup"/>
1252      <xsl:call-template name="handle-markup-in-artwork"/>
1253    </xsl:when>
1254    <xsl:when test="svg:svg">
1255      <xsl:call-template name="warning">
1256        <xsl:with-param name="msg">SVG image removed.</xsl:with-param>
1257      </xsl:call-template>
1258      <artwork>(see SVG image in HTML version)</artwork>
1259    </xsl:when>
1260    <xsl:otherwise>
1261      <xsl:apply-templates select=".//iref" mode="cleanup"/>
1262      <xsl:call-template name="handle-markup-in-artwork"/>
1263    </xsl:otherwise>
1264  </xsl:choose>
1265</xsl:template>
1266
1267<xsl:template name="handle-markup-in-artwork">
1268  <xsl:variable name="content2"><xsl:apply-templates select="node()"/></xsl:variable>
1269  <xsl:variable name="content" select="translate($content2,'&#160;&#x2500;&#x2502;&#x2508;&#x250c;&#x2510;&#x2514;&#x2518;&#x251c;&#x2524;',' -|+++++++')"/>
1270  <artwork>
1271    <xsl:apply-templates select="@*" mode="cleanup" />
1272    <xsl:if test="@x:is-code-component='yes'">
1273      <xsl:if test="starts-with(.,'&#10;')">
1274        <xsl:text>&#10;</xsl:text>
1275      </xsl:if>
1276      <xsl:value-of select="@x:indent-with"/>
1277      <xsl:text>&lt;CODE BEGINS&gt;&#10;</xsl:text>
1278    </xsl:if>
1279    <xsl:if test="starts-with(.,'&#10;')">
1280      <xsl:text>&#10;</xsl:text>
1281      <xsl:value-of select="@x:indent-with"/>
1282    </xsl:if>
1283    <xsl:choose>
1284      <xsl:when test="@x:indent-with!=''">
1285        <xsl:call-template name="indent">
1286          <xsl:with-param name="content" select="$content"/>
1287          <xsl:with-param name="with" select="@x:indent-with"/>
1288        </xsl:call-template>
1289      </xsl:when>
1290      <xsl:otherwise>
1291        <xsl:value-of select="$content"/>
1292      </xsl:otherwise>
1293    </xsl:choose>
1294    <xsl:if test="@x:is-code-component='yes'">&#10;&lt;CODE ENDS&gt;&#10;</xsl:if>
1295  </artwork> 
1296</xsl:template>
1297
1298<xsl:template match="@x:indent-with" mode="cleanup"/>
1299<xsl:template match="@x:lang" mode="cleanup"/>
1300
1301<xsl:template name="indent">
1302  <xsl:param name="content"/>
1303  <xsl:param name="with"/>
1304
1305  <xsl:value-of select="substring($content,1,1)"/>
1306  <xsl:if test="substring($content,1,1)='&#10;'">
1307    <xsl:value-of select="$with"/>
1308  </xsl:if>
1309 
1310  <xsl:choose>
1311    <xsl:when test="$content=''" />
1312    <xsl:otherwise>
1313      <xsl:call-template name="indent">
1314        <xsl:with-param name="content" select="substring($content,2)"/>
1315        <xsl:with-param name="with" select="$with"/>
1316      </xsl:call-template>
1317    </xsl:otherwise>
1318  </xsl:choose>
1319 
1320</xsl:template>
1321
1322<xsl:template match="artset" mode="cleanup">
1323  <!-- see https://tools.ietf.org/html/draft-levkowetz-xml2rfc-v3-implementation-notes-08#section-3.1.1 -->
1324  <xsl:choose>
1325    <xsl:when test="artwork[not(svg:svg or normalize-space(.)='' or @src!='')]">
1326      <xsl:apply-templates select="artwork[not(svg:svg or normalize-space(.)='' or @src!='')][1]" mode="cleanup"/>
1327    </xsl:when>
1328    <xsl:when test="artwork">
1329      <xsl:apply-templates select="artwork[1]" mode="cleanup"/>
1330    </xsl:when>
1331    <xsl:when test="not(artwork) and parent::figure">
1332      <xsl:call-template name="error">
1333        <xsl:with-param name="inline">no</xsl:with-param>
1334        <xsl:with-param name="msg">artset needs to contain at least one artwork child element</xsl:with-param>
1335      </xsl:call-template>
1336      <artwork/>
1337    </xsl:when>
1338    <xsl:otherwise/>
1339  </xsl:choose>
1340</xsl:template>
1341
1342<!-- email repetitions -->
1343<xsl:template match="email" mode="cleanup">
1344  <!-- combine in a single element -->
1345  <xsl:if test="not(preceding-sibling::email)">
1346    <email>
1347      <xsl:for-each select="../email">
1348        <xsl:value-of select="."/>
1349        <xsl:if test="position()!=last()">
1350          <xsl:text>, </xsl:text>
1351        </xsl:if>
1352      </xsl:for-each>
1353    </email>
1354  </xsl:if>
1355</xsl:template>
1356
1357<!-- defaults for <eref> brackets -->
1358<xsl:template match="eref[not(*|text()) and not(ancestor::cref)]" mode="cleanup">
1359  <eref>
1360    <xsl:copy-of select="@target"/>
1361    <xsl:choose>
1362      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and not(@brackets)">
1363        <xsl:attribute name="brackets">angle</xsl:attribute>
1364      </xsl:when>
1365      <xsl:otherwise>
1366        <xsl:copy-of select="@brackets"/>
1367      </xsl:otherwise>
1368    </xsl:choose>
1369  </eref>
1370</xsl:template>
1371
1372<!-- cref/@display -->
1373<xsl:template match="cref/@display" mode="cleanup">
1374  <xsl:choose>
1375    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1376      <xsl:copy-of select="."/>
1377    </xsl:when>
1378    <xsl:otherwise>
1379      <!-- otherwise just drop -->
1380    </xsl:otherwise>
1381  </xsl:choose>
1382</xsl:template>
1383
1384<!-- markup inside cref -->
1385<xsl:template match="cref//eref" mode="cleanup">
1386  <xsl:choose>
1387    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1388      <xsl:copy>
1389        <xsl:apply-templates select="node()|@*" mode="cleanup"/>
1390      </xsl:copy>
1391    </xsl:when>
1392    <xsl:otherwise>
1393      <xsl:text>&lt;</xsl:text>
1394      <xsl:value-of select="@target"/>
1395      <xsl:text>&gt;</xsl:text>
1396    </xsl:otherwise>
1397  </xsl:choose>
1398</xsl:template>
1399
1400<xsl:template match="cref//x:dfn|cref//x:ref" mode="cleanup" priority="9">
1401  <xsl:variable name="text">
1402    <xsl:apply-templates select="."/>
1403  </xsl:variable>
1404  <xsl:value-of select="$text"/>
1405</xsl:template>
1406
1407<xsl:template match="cref//xref" mode="cleanup" priority="9">
1408  <xsl:choose>
1409    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1410      <xsl:copy>
1411        <xsl:apply-templates select="@*|*" mode="cleanup"/>
1412      </xsl:copy>
1413    </xsl:when>
1414    <xsl:otherwise>
1415      <xsl:variable name="text">
1416        <xsl:apply-templates select="."/>
1417      </xsl:variable>
1418      <xsl:value-of select="$text"/>
1419    </xsl:otherwise>
1420  </xsl:choose>
1421</xsl:template>
1422
1423<!-- annotations -->
1424<xsl:template match="@x:annotation" mode="cleanup">
1425  <xsl:comment>
1426    <xsl:value-of select="."/>
1427  </xsl:comment>
1428  <xsl:call-template name="warning">
1429    <xsl:with-param name="msg">Dropping annotation on <xsl:value-of select="local-name(..)"/> element.</xsl:with-param>
1430  </xsl:call-template>
1431</xsl:template>
1432
1433<!-- artwork extensions -->
1434<xsl:template match="artwork/@x:extraction-note" mode="cleanup"/>
1435
1436<!-- list formatting -->
1437<xsl:template match="list/@x:indent" mode="cleanup"/>
1438
1439<!-- rewrite to 'hanging' for now -->
1440<xsl:template match="list[@style='x:dictionary']" mode="cleanup">
1441  <list style="hanging">
1442    <xsl:copy-of select="@hangIndent"/>
1443    <xsl:apply-templates select="*" mode="cleanup"/>
1444  </list>
1445</xsl:template>
1446
1447<!-- referencing extensions -->
1448<xsl:template match="iref/@x:for-anchor" mode="cleanup"/>
1449
1450<!-- GRRDL info stripped -->
1451<xsl:template match="@grddl:transformation" mode="cleanup"/>
1452
1453<!-- maturity level stripped -->
1454<xsl:template match="@x:maturity-level" mode="cleanup"/>
1455
1456<!-- normativity stripped -->
1457<xsl:template match="@x:nrm" mode="cleanup"/>
1458
1459<!-- table extensions -->
1460<xsl:template match="texttable/@x:caption-side" mode="cleanup"/>
1461
1462<!-- title extensions -->
1463<xsl:template match="title/@x:quotes" mode="cleanup"/>
1464
1465<!-- organization extensions -->
1466<xsl:template match="organization/@showOnFrontPage" mode="cleanup"/>
1467
1468<!-- RDF info stripped -->
1469<xsl:template match="rdf:*" mode="cleanup"/>
1470
1471<!-- cases where xml2rfc does not allow anchors -->
1472<xsl:template match="c/@anchor" mode="cleanup"/>
1473<xsl:template match="preamble/@anchor" mode="cleanup"/>
1474<xsl:template match="spanx/@anchor" mode="cleanup"/>
1475
1476<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
1477<xsl:template match="spanx[@style='vbare']" mode="cleanup">
1478  <xsl:choose>
1479    <xsl:when test="$xml2rfc-ext-strip-vbare='true'">
1480      <xsl:apply-templates mode="cleanup"/>
1481    </xsl:when>
1482    <xsl:otherwise>
1483      <spanx style="vbare">
1484        <xsl:apply-templates mode="cleanup"/>
1485      </spanx>
1486    </xsl:otherwise>
1487  </xsl:choose>
1488</xsl:template>
1489
1490<!-- v3 features -->
1491<xsl:template match="rfc/@sortRefs" mode="cleanup"/>
1492<xsl:template match="rfc/@symRefs" mode="cleanup"/>
1493<xsl:template match="rfc/@tocInclude" mode="cleanup"/>
1494<xsl:template match="rfc/@tocDepth" mode="cleanup"/>
1495<xsl:template match="rfc/@consensus" mode="cleanup"/>
1496
1497<!-- handled below -->
1498<xsl:template match="rfc/@category" mode="cleanup"/>
1499<xsl:template match="rfc/@ipr" mode="cleanup"/>
1500
1501<xsl:template match="rfc" mode="cleanup">
1502  <xsl:if test="@sortRefs='true'">
1503    <xsl:processing-instruction name="rfc">sortrefs="yes"</xsl:processing-instruction>
1504  </xsl:if>
1505  <xsl:if test="@symRefs='false'">
1506    <xsl:processing-instruction name="rfc">symrefs="no"</xsl:processing-instruction>
1507  </xsl:if>
1508  <xsl:if test="$parsedTocDepth!=3 and $xml2rfc-ext-xml2rfc-voc &lt; 3">
1509    <xsl:processing-instruction name="rfc">tocdepth="<xsl:value-of select="$parsedTocDepth"/>"</xsl:processing-instruction>
1510  </xsl:if>
1511  <xsl:if test="@version and (not(@tocInclude) or @tocInclude='true')">
1512    <xsl:processing-instruction name="rfc">toc="yes"</xsl:processing-instruction>
1513  </xsl:if>
1514  <rfc>
1515    <xsl:if test="not(@version) and $xml2rfc-ext-xml2rfc-voc >= 3">
1516      <xsl:attribute name="version"><xsl:value-of select="$xml2rfc-ext-xml2rfc-voc"/></xsl:attribute>
1517    </xsl:if>
1518    <xsl:if test="not(@tocDepth) and $xml2rfc-ext-xml2rfc-voc >= 3 and $parsedTocDepth!=3">
1519      <xsl:attribute name="tocDepth"><xsl:value-of select="$parsedTocDepth"/></xsl:attribute>
1520    </xsl:if>
1521    <xsl:if test="@tocDepth and $xml2rfc-ext-xml2rfc-voc >= 3">
1522      <xsl:attribute name="tocDepth"><xsl:value-of select="@tocDepth"/></xsl:attribute>
1523    </xsl:if>
1524    <xsl:if test="not(@indexInclude) and $xml2rfc-ext-xml2rfc-voc >= 3 and $xml2rfc-ext-include-index='no'">
1525      <xsl:attribute name="indexInclude">false</xsl:attribute>
1526    </xsl:if>
1527    <xsl:if test="not(@sortRefs) and $xml2rfc-ext-xml2rfc-voc >= 3 and $xml2rfc-sortrefs='yes'">
1528      <xsl:attribute name="sortRefs">true</xsl:attribute>
1529    </xsl:if>
1530    <xsl:choose>
1531      <xsl:when test="@consensus='yes' and $xml2rfc-ext-xml2rfc-voc >= 3"><xsl:attribute name="consensus">true</xsl:attribute></xsl:when>
1532      <xsl:when test="@consensus='no' and $xml2rfc-ext-xml2rfc-voc >= 3"><xsl:attribute name="consensus">false</xsl:attribute></xsl:when>
1533      <xsl:when test="@consensus='true' and $xml2rfc-ext-xml2rfc-voc &lt; 3"><xsl:attribute name="consensus">yes</xsl:attribute></xsl:when>
1534      <xsl:when test="@consensus='false' and $xml2rfc-ext-xml2rfc-voc &lt; 3"><xsl:attribute name="consensus">no</xsl:attribute></xsl:when>
1535      <xsl:otherwise><xsl:copy-of select="@consensus"/></xsl:otherwise>
1536    </xsl:choose>
1537    <xsl:choose>
1538      <xsl:when test="@submissionType='IETF' and not(@category) and $xml2rfc-ext-xml2rfc-voc >= 3">
1539        <xsl:call-template name="warning">
1540          <xsl:with-param name="msg">defaulting /rfc/@category to "info" for xml2rfc v3</xsl:with-param>
1541        </xsl:call-template>
1542        <xsl:attribute name="category">info</xsl:attribute>
1543      </xsl:when>
1544      <xsl:otherwise><xsl:copy-of select="@category"/></xsl:otherwise>
1545    </xsl:choose>
1546    <xsl:choose>
1547      <xsl:when test="@submissionType='IETF' and not(@ipr) and $xml2rfc-ext-xml2rfc-voc >= 3">
1548        <xsl:call-template name="warning">
1549          <xsl:with-param name="msg">defaulting /rfc/@ipr to "trust200902" for xml2rfc v3</xsl:with-param>
1550        </xsl:call-template>
1551        <xsl:attribute name="ipr">trust200902</xsl:attribute>
1552      </xsl:when>
1553      <xsl:otherwise><xsl:copy-of select="@ipr"/></xsl:otherwise>
1554    </xsl:choose>
1555    <xsl:apply-templates select="@*|node()" mode="cleanup"/>
1556  </rfc>
1557</xsl:template>
1558
1559<xsl:template match="strong" mode="cleanup">
1560  <xsl:choose>
1561    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1562      <strong>
1563        <xsl:apply-templates select="node()|@*" mode="cleanup" />
1564      </strong>
1565    </xsl:when>
1566    <xsl:when test="*">
1567      <xsl:call-template name="warning">
1568        <xsl:with-param name="msg">strong not translated when including child elements</xsl:with-param>
1569      </xsl:call-template>
1570      <xsl:apply-templates mode="cleanup"/>
1571    </xsl:when>
1572    <xsl:otherwise>
1573      <spanx style="strong">
1574        <xsl:apply-templates mode="cleanup"/>
1575      </spanx>
1576    </xsl:otherwise>
1577  </xsl:choose>
1578</xsl:template>
1579
1580<xsl:template match="em" mode="cleanup">
1581  <xsl:choose>
1582    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1583      <em>
1584        <xsl:apply-templates select="node()|@*" mode="cleanup" />
1585      </em>
1586    </xsl:when>
1587    <xsl:when test="*">
1588      <xsl:call-template name="warning">
1589        <xsl:with-param name="msg">em not translated when including child elements</xsl:with-param>
1590      </xsl:call-template>
1591      <xsl:apply-templates mode="cleanup"/>
1592    </xsl:when>
1593    <xsl:otherwise>
1594      <spanx style="emph">
1595        <xsl:apply-templates mode="cleanup"/>
1596      </spanx>
1597    </xsl:otherwise>
1598  </xsl:choose>
1599</xsl:template>
1600
1601<xsl:template match="tt" mode="cleanup">
1602  <xsl:choose>
1603    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1604      <tt>
1605        <xsl:apply-templates select="node()|@*" mode="cleanup" />
1606      </tt>
1607    </xsl:when>
1608    <xsl:when test="*">
1609      <xsl:call-template name="warning">
1610        <xsl:with-param name="msg">tt not translated when they include child elements</xsl:with-param>
1611      </xsl:call-template>
1612      <xsl:apply-templates mode="cleanup"/>
1613    </xsl:when>
1614    <xsl:otherwise>
1615      <spanx style="verb">
1616        <xsl:apply-templates mode="cleanup"/>
1617      </spanx>
1618    </xsl:otherwise>
1619  </xsl:choose>
1620</xsl:template>
1621
1622<xsl:template match="references/@anchor" mode="cleanup"/>
1623
1624<!-- New reference attributes -->
1625<xsl:template match="reference/@quoteTitle" mode="cleanup">
1626  <xsl:if test="$xml2rfc-ext-xml2rfc-backend >= 201706">
1627    <xsl:attribute name="quote-title"><xsl:value-of select="."/></xsl:attribute>
1628  </xsl:if>
1629</xsl:template>
1630
1631<xsl:template match="reference/front/abstract" mode="cleanup"/>
1632
1633<xsl:template match="referencegroup" mode="cleanup">
1634  <reference anchor="{@anchor}">
1635    <xsl:copy-of select="@target"/>
1636    <xsl:if test="$xml2rfc-ext-xml2rfc-backend >= 201706">
1637      <xsl:attribute name="quote-title">false</xsl:attribute>
1638    </xsl:if>
1639    <xsl:comment>...expanded &lt;referencegroup>...</xsl:comment>
1640    <front>
1641      <title>
1642        <xsl:text>Consisting of: </xsl:text>
1643        <xsl:variable xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rfc2629.xslt" name="included" select="exslt:node-set($includeDirectives)/myns:include[@in=generate-id(current())]/*[self::reference or self::referencegroup]"/>
1644        <xsl:for-each select="reference|$included">
1645          <xsl:value-of select="concat('[',@anchor,']')"/>
1646          <xsl:choose>
1647            <xsl:when test="position() &lt; last() - 1">, </xsl:when>
1648            <xsl:when test="position() = last() - 1">, and </xsl:when>
1649            <xsl:otherwise/>
1650          </xsl:choose>
1651        </xsl:for-each>
1652      </title>
1653      <author/>
1654      <date/>
1655    </front>
1656  </reference>
1657  <xsl:apply-templates mode="cleanup"/>
1658</xsl:template>
1659
1660<xsl:template match="reference" mode="cleanup">
1661  <reference>
1662    <xsl:apply-templates select="@anchor|@target|@quoteTitle" mode="cleanup"/>
1663    <xsl:choose>
1664      <xsl:when test="not(@target) and $xml2rfc-ext-link-rfc-to-info-page='yes' and seriesInfo[@name='BCP'] and starts-with(@anchor,'BCP')">
1665        <xsl:variable name="uri">
1666          <xsl:call-template name="compute-rfc-info-uri">
1667            <xsl:with-param name="type" select="'bcp'"/>
1668            <xsl:with-param name="no" select="seriesInfo[@name='BCP']/@value"/>
1669          </xsl:call-template>
1670        </xsl:variable>
1671        <xsl:attribute name="target"><xsl:value-of select="$uri"/></xsl:attribute>
1672      </xsl:when>
1673      <xsl:when test="not(@target) and $xml2rfc-ext-link-rfc-to-info-page='yes' and seriesInfo[@name='RFC']">
1674        <xsl:variable name="uri">
1675          <xsl:call-template name="compute-rfc-info-uri">
1676            <xsl:with-param name="type" select="'rfc'"/>
1677            <xsl:with-param name="no" select="seriesInfo[@name='RFC']/@value"/>
1678          </xsl:call-template>
1679        </xsl:variable>
1680        <xsl:attribute name="target"><xsl:value-of select="$uri"/></xsl:attribute>
1681      </xsl:when>
1682      <xsl:when test="not(@target) and $xml2rfc-ext-link-rfc-to-info-page='yes' and not(seriesInfo) and document(x:source/@href)/rfc/@number">
1683        <xsl:variable name="uri">
1684          <xsl:call-template name="compute-rfc-info-uri">
1685            <xsl:with-param name="type" select="'rfc'"/>
1686            <xsl:with-param name="no" select="document(x:source/@href)/rfc/@number"/>
1687          </xsl:call-template>
1688        </xsl:variable>
1689        <xsl:attribute name="target"><xsl:value-of select="$uri"/></xsl:attribute>
1690      </xsl:when>
1691      <xsl:otherwise/>
1692    </xsl:choose>
1693    <xsl:choose>
1694      <xsl:when test="front">
1695        <xsl:apply-templates select="front" mode="cleanup"/>
1696      </xsl:when>
1697      <xsl:when test="x:source">
1698        <xsl:variable name="d" select="document(x:source/@href)"/>
1699        <xsl:comment>included from <xsl:value-of select="x:source/@href"/></xsl:comment>
1700        <front>
1701          <xsl:apply-templates select="$d/rfc/front/title" mode="cleanup"/>
1702          <xsl:apply-templates select="$d/rfc/front/author" mode="cleanup"/>
1703          <xsl:choose>
1704            <xsl:when test="$d/rfc/front/date/@*">
1705              <!-- any date info present? -->
1706              <xsl:apply-templates select="$d/rfc/front/date" mode="cleanup"/>
1707            </xsl:when>
1708            <xsl:otherwise>
1709              <!-- let defaults apply -->
1710              <date year="{$xml2rfc-ext-pub-year}" month="{$xml2rfc-ext-pub-month}"/>
1711            </xsl:otherwise>
1712          </xsl:choose>
1713        </front>
1714        <xsl:if test="not(seriesInfo) and document(x:source/@href)/rfc/@docName">
1715          <seriesInfo name="Internet-Draft" value="{document(x:source/@href)/rfc/@docName}"/>
1716        </xsl:if>
1717        <xsl:if test="not(seriesInfo) and document(x:source/@href)/rfc/@number">
1718          <seriesInfo name="RFC" value="{document(x:source/@href)/rfc/@number}"/>
1719        </xsl:if>
1720      </xsl:when>
1721      <xsl:otherwise/>
1722    </xsl:choose>
1723    <xsl:apply-templates select="seriesInfo|front/seriesInfo" mode="cleanup"/>
1724
1725    <!-- Insert DOI for RFCs -->
1726    <xsl:variable name="doi">
1727      <xsl:choose>
1728        <xsl:when test="seriesInfo|front/seriesInfo">
1729          <xsl:call-template name="compute-doi"/>
1730        </xsl:when>
1731        <xsl:when test="document(x:source/@href)/rfc/@number">
1732          <xsl:call-template name="compute-doi">
1733            <xsl:with-param name="rfc" select="document(x:source/@href)/rfc/@number"/>
1734          </xsl:call-template>
1735        </xsl:when>
1736        <xsl:otherwise/>
1737      </xsl:choose>
1738    </xsl:variable>
1739    <xsl:if test="$xml2rfc-ext-insert-doi='yes' and $doi!='' and not(seriesInfo[@name='DOI']|front/seriesInfo[@name='DOI'])">
1740      <seriesInfo name="DOI" value="{$doi}"/>
1741    </xsl:if>
1742
1743    <xsl:apply-templates select="*[not(self::front) and not(self::seriesInfo)]" mode="cleanup"/>
1744  </reference>
1745</xsl:template>
1746
1747<xsl:template match="seriesInfo" mode="cleanup">
1748  <xsl:choose>
1749    <xsl:when test="@name='DOI' and starts-with(@value,'10.17487/RFC') and $xml2rfc-ext-insert-doi='no'">
1750      <xsl:call-template name="info">
1751        <xsl:with-param name="msg">Removing DOI <xsl:value-of select="@value"/> from &lt;reference> element</xsl:with-param>
1752      </xsl:call-template>
1753    </xsl:when>
1754    <xsl:otherwise>
1755      <seriesInfo name="{@name}" value="{@value}"/>
1756    </xsl:otherwise>
1757  </xsl:choose>
1758</xsl:template>
1759
1760
1761<xsl:template match="date[ancestor::reference]" mode="cleanup">
1762  <xsl:choose>
1763    <xsl:when test="@year!='' or normalize-space(.)=''">
1764      <date>
1765        <xsl:apply-templates select="@*" mode="cleanup"/>
1766      </date>
1767    </xsl:when>
1768    <xsl:otherwise>
1769      <date year="{normalize-space(.)}"/>
1770    </xsl:otherwise>
1771  </xsl:choose>
1772</xsl:template>
1773
1774<xsl:template match="front" mode="cleanup">
1775  <!-- silence certain xml2rfcv3 warning messages -->
1776  <xsl:if test="$xml2rfc-ext-xml2rfc-backend >= 201706 and not(ancestor::reference)">
1777    <xsl:if test="not(/rfc/@consensus)">
1778      <xsl:text>&#10;</xsl:text>
1779      <xsl:comment>see https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/420</xsl:comment>
1780      <xsl:text>&#10;</xsl:text>
1781      <xsl:processing-instruction name="v3xml2rfc">silence="Warning: Setting consensus="true" for IETF STD document"</xsl:processing-instruction>
1782    </xsl:if>
1783    <xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3 and not(/rfc/@submissionType) and not ($is-rfc)">
1784      <!-- issue to be raised -->
1785      <xsl:text>&#10;</xsl:text>
1786      <xsl:processing-instruction name="v3xml2rfc">silence="Warning: Expected a valid submissionType (stream) setting"</xsl:processing-instruction>
1787    </xsl:if>
1788    <xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3 and substring(/rfc/@docName, string-length(/rfc/@docName)-string-length('-latest')+1)='-latest'">
1789      <xsl:text>&#10;</xsl:text>
1790      <xsl:comment>see https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/439</xsl:comment>
1791      <xsl:text>&#10;</xsl:text>
1792      <xsl:processing-instruction name="v3xml2rfc">silence="The 'docName' attribute of the &lt;rfc/> element"</xsl:processing-instruction>
1793    </xsl:if>
1794  </xsl:if>
1795  <front>
1796    <xsl:apply-templates select="title" mode="cleanup"/>
1797    <xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3 and seriesInfo">
1798      <xsl:apply-templates select="seriesInfo" mode="cleanup"/>
1799    </xsl:if>
1800    <xsl:apply-templates select="author" mode="cleanup"/>
1801    <xsl:apply-templates select="date" mode="cleanup"/>
1802    <xsl:if test="not(date)">
1803      <!-- mandatory in v2 -->
1804      <date/>
1805    </xsl:if>
1806    <xsl:apply-templates select="text()|node()[not(self::seriesInfo or self::title or self::author or self::date)]" mode="cleanup"/>
1807  </front>
1808</xsl:template>
1809
1810<!-- Note titles -->
1811<xsl:template match="note" mode="cleanup">
1812  <note>
1813    <xsl:apply-templates select="@anchor" mode="cleanup"/>
1814    <xsl:variable name="title">
1815      <xsl:choose>
1816        <xsl:when test="name">
1817          <xsl:variable name="hold">
1818            <xsl:apply-templates select="name/node()"/>
1819          </xsl:variable>
1820          <xsl:value-of select="normalize-space($hold)"/>
1821        </xsl:when>
1822        <xsl:otherwise>
1823          <xsl:value-of select="@title"/>
1824        </xsl:otherwise>
1825      </xsl:choose>
1826    </xsl:variable>
1827    <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1828    <xsl:if test="@removeInRFC='true' and (not(t) or t[1]!=$note-removeInRFC)">
1829      <t><xsl:value-of select="$note-removeInRFC"/></t>
1830    </xsl:if>
1831    <xsl:apply-templates mode="cleanup"/>
1832  </note>
1833</xsl:template>
1834<xsl:template match="note/name" mode="cleanup"/>
1835
1836<!-- References -->
1837<xsl:template match="references" mode="cleanup">
1838  <xsl:choose>
1839    <xsl:when test="parent::back and count(../references) > 1 and $xml2rfc-ext-xml2rfc-voc >= 3">
1840      <!-- insert top-level references section -->
1841      <xsl:if test="not(preceding-sibling::references)">
1842        <references>
1843          <name>References</name>
1844          <xsl:for-each select="../references">
1845            <references>
1846              <xsl:variable name="title">
1847                <xsl:choose>
1848                  <xsl:when test="name">
1849                    <xsl:variable name="hold">
1850                      <xsl:apply-templates select="name/node()"/>
1851                    </xsl:variable>
1852                    <xsl:value-of select="normalize-space($hold)"/>
1853                  </xsl:when>
1854                  <xsl:otherwise>
1855                    <xsl:value-of select="@title"/>
1856                  </xsl:otherwise>
1857                </xsl:choose>
1858              </xsl:variable>
1859              <xsl:apply-templates select="@anchor|@toc" mode="cleanup"/>
1860              <xsl:if test="not(name)">
1861                <name><xsl:value-of select="$title"/></name>
1862              </xsl:if>
1863              <xsl:apply-templates select="*" mode="cleanup"/>
1864            </references>
1865          </xsl:for-each>
1866        </references>
1867      </xsl:if>
1868    </xsl:when>
1869    <xsl:when test="references and $xml2rfc-ext-xml2rfc-voc &lt; 3">
1870      <!-- V2 does not allow nested references -->
1871      <xsl:apply-templates select="references" mode="cleanup"/>
1872    </xsl:when>
1873    <xsl:otherwise>
1874      <references>
1875        <xsl:variable name="title">
1876          <xsl:choose>
1877            <xsl:when test="name">
1878              <xsl:variable name="hold">
1879                <xsl:apply-templates select="name/node()"/>
1880              </xsl:variable>
1881              <xsl:value-of select="normalize-space($hold)"/>
1882            </xsl:when>
1883            <xsl:otherwise>
1884              <xsl:value-of select="@title"/>
1885            </xsl:otherwise>
1886          </xsl:choose>
1887        </xsl:variable>
1888        <xsl:apply-templates select="@anchor|@toc" mode="cleanup"/>
1889        <xsl:choose>
1890          <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3 and name">
1891            <xsl:apply-templates select="name" mode="cleanup"/>
1892          </xsl:when>
1893          <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1894            <name><xsl:value-of select="$title"/></name>
1895          </xsl:when>
1896          <xsl:otherwise>
1897            <xsl:if test="$title!=''">
1898              <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1899            </xsl:if>
1900          </xsl:otherwise>
1901        </xsl:choose>
1902        <xsl:apply-templates mode="cleanup" select="node()[not(self::name)]"/>
1903      </references>     
1904    </xsl:otherwise>
1905  </xsl:choose>
1906</xsl:template>
1907
1908<!-- Section titles -->
1909<xsl:template match="section" mode="cleanup">
1910  <section>
1911    <xsl:copy-of select="@anchor|@toc"/>
1912    <xsl:choose>
1913      <xsl:when test="$xml2rfc-ext-xml2rfc-backend >= 201610">
1914        <xsl:copy-of select="@numbered"/>
1915      </xsl:when>
1916      <xsl:otherwise/>
1917    </xsl:choose>
1918    <xsl:choose>
1919      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1920        <xsl:apply-templates select="@title" mode="cleanup"/>
1921        <xsl:if test="name">
1922          <name>
1923            <xsl:apply-templates select="name/node()" mode="cleanup"/>
1924          </name>
1925        </xsl:if>
1926      </xsl:when>
1927      <xsl:otherwise>
1928        <xsl:attribute name="title">
1929          <xsl:call-template name="get-title-as-string"/>
1930        </xsl:attribute>
1931      </xsl:otherwise>
1932    </xsl:choose>
1933    <xsl:if test="@removeInRFC='true' and (not(t) or t[1]!=$section-removeInRFC)">
1934      <t><xsl:value-of select="$section-removeInRFC"/></t>
1935    </xsl:if>
1936    <xsl:apply-templates mode="cleanup"/>
1937  </section>
1938  <xsl:if test="(@numbered='no' or @numbered='false') and $xml2rfc-ext-xml2rfc-backend &lt; 201610">
1939    <xsl:call-template name="warning">
1940      <xsl:with-param name="msg">unnumbered sections not supported</xsl:with-param>
1941    </xsl:call-template>
1942  </xsl:if>
1943</xsl:template>
1944<xsl:template match="section/name" mode="cleanup"/>
1945
1946<!-- Definition Lists -->
1947<xsl:template match="dl" mode="cleanup">
1948  <xsl:choose>
1949    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
1950      <dl>
1951        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
1952      </dl>
1953    </xsl:when>
1954    <xsl:otherwise>
1955      <xsl:call-template name="dl-to-v2"/>
1956    </xsl:otherwise>
1957  </xsl:choose>
1958</xsl:template>
1959
1960<xsl:template name="dl-to-v2">
1961  <xsl:choose>
1962    <xsl:when test="parent::dd">
1963      <xsl:call-template name="process-dl"/>
1964    </xsl:when>
1965    <xsl:otherwise>
1966      <t>
1967        <xsl:call-template name="process-dl"/>
1968      </t>
1969    </xsl:otherwise>
1970  </xsl:choose>
1971</xsl:template>
1972
1973<xsl:template name="process-dl">
1974  <xsl:copy-of select="@anchor"/>
1975  <xsl:variable name="newl" select="@newline"/>
1976  <xsl:variable name="spac" select="@spacing"/>
1977  <xsl:if test="parent::section">
1978    <!-- avoid adding PIs into nested lists due to xml2rfc bug -->
1979    <xsl:processing-instruction name="rfc">
1980      <xsl:choose>
1981        <xsl:when test="not($spac='compact')">subcompact='no'</xsl:when>
1982        <xsl:otherwise>subcompact='yes'</xsl:otherwise>
1983      </xsl:choose>
1984    </xsl:processing-instruction>
1985  </xsl:if>
1986  <list style="hanging">
1987    <xsl:variable name="indent" select="@indent"/>
1988    <xsl:if test="number($indent)=$indent">
1989      <xsl:attribute name="hangIndent"><xsl:value-of select="$indent"/></xsl:attribute>
1990    </xsl:if>
1991    <xsl:for-each select="dt">
1992      <xsl:variable name="txt">
1993        <xsl:apply-templates select="." mode="cleanup"/>
1994      </xsl:variable>
1995      <!-- TODO: check for more block-level elements -->
1996      <xsl:variable name="desc" select="following-sibling::dd[1]"/>
1997      <xsl:variable name="block-level-children" select="$desc/artwork | $desc/dl | $desc/figure | $desc/ol | $desc/sourcecode | $desc/t | $desc/table | $desc/ul"/>
1998      <t hangText="{normalize-space($txt)}">
1999        <xsl:choose>
2000          <xsl:when test="@anchor">
2001            <xsl:copy-of select="@anchor"/>
2002          </xsl:when>
2003          <xsl:otherwise>
2004            <xsl:copy-of select="$desc/@anchor"/>
2005          </xsl:otherwise>
2006        </xsl:choose>
2007        <xsl:if test="$newl='true'">
2008          <xsl:choose>
2009            <xsl:when test="$block-level-children">
2010              <vspace blankLines="1"/>
2011            </xsl:when>
2012            <xsl:otherwise>
2013              <vspace blankLines="0"/>
2014            </xsl:otherwise>
2015          </xsl:choose>
2016        </xsl:if>
2017        <xsl:apply-templates select="iref" mode="cleanup"/>
2018        <xsl:choose>
2019          <xsl:when test="$block-level-children">
2020            <xsl:for-each select="$block-level-children">
2021              <xsl:choose>
2022                <xsl:when test="self::t">
2023                  <xsl:apply-templates select="node()" mode="cleanup"/>
2024                </xsl:when>
2025                <xsl:otherwise>
2026                  <xsl:apply-templates select="." mode="cleanup"/>
2027                </xsl:otherwise>
2028              </xsl:choose>
2029              <xsl:if test="position()!=last()">
2030                <xsl:choose>
2031                  <xsl:when test="not($spac='compact')"><vspace blankLines="1"/></xsl:when>
2032                  <xsl:otherwise><vspace blankLines="0"/></xsl:otherwise>
2033                </xsl:choose>
2034              </xsl:if>
2035            </xsl:for-each>
2036          </xsl:when>
2037          <xsl:otherwise>
2038            <xsl:apply-templates select="$desc/node()" mode="cleanup"/>
2039          </xsl:otherwise>
2040        </xsl:choose>
2041      </t>
2042    </xsl:for-each>
2043  </list>
2044</xsl:template>
2045
2046<!-- rewrite link target going to <dd> to use preceding <dt>'s anchor when present -->
2047<xsl:template match="xref/@target[.=//dd/@anchor]" mode="cleanup">
2048  <xsl:variable name="t" select="//dd[@anchor=current()]"/>
2049  <xsl:variable name="p" select="$t/preceding-sibling::dt[1]"/>
2050  <xsl:choose>
2051    <xsl:when test="$p/@anchor">
2052      <xsl:attribute name="target"><xsl:value-of select="$p/@anchor"/></xsl:attribute>
2053    </xsl:when>
2054    <xsl:otherwise>
2055      <xsl:attribute name="target"><xsl:value-of select="."/></xsl:attribute>
2056    </xsl:otherwise>
2057  </xsl:choose>
2058</xsl:template>
2059
2060<!-- List items -->
2061<xsl:template match="li" mode="cleanup">
2062  <xsl:choose>
2063    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2064      <li>
2065        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2066      </li>
2067    </xsl:when>
2068    <xsl:otherwise>
2069      <xsl:call-template name="li-to-v2"/>
2070    </xsl:otherwise>
2071  </xsl:choose>
2072</xsl:template>
2073
2074<xsl:template name="li-to-v2">
2075  <t>
2076    <xsl:copy-of select="@anchor"/>
2077    <xsl:apply-templates mode="cleanup"/>
2078  </t>
2079</xsl:template>
2080
2081<xsl:template match="li/t" mode="cleanup">
2082  <xsl:choose>
2083    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2084      <t>
2085        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2086      </t>
2087    </xsl:when>
2088    <xsl:otherwise>
2089      <xsl:call-template name="li-t-to-v2"/>
2090    </xsl:otherwise>
2091  </xsl:choose>
2092</xsl:template>
2093
2094<xsl:template name="li-t-to-v2">
2095  <xsl:apply-templates mode="cleanup"/>
2096  <xsl:if test="position()!=last()">
2097    <vspace blankLines="1"/>
2098  </xsl:if>
2099</xsl:template>
2100
2101<xsl:template match="li/ul" mode="cleanup">
2102  <xsl:choose>
2103    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2104      <ul>
2105        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2106      </ul>
2107    </xsl:when>
2108    <xsl:otherwise>
2109      <xsl:call-template name="li-ul-to-v2"/>
2110    </xsl:otherwise>
2111  </xsl:choose>
2112</xsl:template>
2113 
2114<xsl:template name="li-ul-to-v2">
2115  <xsl:variable name="style">
2116    <xsl:choose>
2117      <xsl:when test="@empty='true'">empty</xsl:when>
2118      <xsl:otherwise>symbols</xsl:otherwise>
2119    </xsl:choose>
2120  </xsl:variable>
2121  <list style="{$style}">
2122    <xsl:apply-templates mode="cleanup"/>
2123  </list>
2124  <xsl:if test="position()!=last()">
2125    <vspace blankLines="1"/>
2126  </xsl:if>
2127</xsl:template>
2128
2129<!-- Ordered Lists -->
2130<xsl:template match="ol" mode="cleanup">
2131  <xsl:choose>
2132    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2133      <ol>
2134        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2135      </ol>
2136    </xsl:when>
2137    <xsl:when test="parent::li">
2138      <xsl:call-template name="ol-to-v2"/>
2139      <xsl:if test="position()!=last()">
2140        <vspace blankLines="1"/>
2141      </xsl:if>
2142    </xsl:when>
2143    <xsl:otherwise>
2144      <t>
2145        <xsl:call-template name="ol-to-v2"/>
2146      </t>
2147    </xsl:otherwise>
2148  </xsl:choose>
2149</xsl:template>
2150
2151<xsl:template name="ol-to-v2">
2152  <xsl:copy-of select="@anchor"/>
2153  <xsl:if test="@start and @start!='1'">
2154    <xsl:call-template name="error">
2155      <xsl:with-param name="inline">no</xsl:with-param>
2156      <xsl:with-param name="msg">list start != 1 not supported</xsl:with-param>
2157    </xsl:call-template>
2158  </xsl:if>
2159  <xsl:if test="@group">
2160    <xsl:call-template name="error">
2161      <xsl:with-param name="inline">no</xsl:with-param>
2162      <xsl:with-param name="msg">ol/@group not supported</xsl:with-param>
2163    </xsl:call-template>
2164  </xsl:if>
2165  <xsl:variable name="style">
2166    <xsl:choose>
2167      <xsl:when test="not(@type) or @type='1'">numbers</xsl:when>
2168      <xsl:when test="@type='a'">letters</xsl:when>
2169      <xsl:when test="@type='A'">
2170        <xsl:call-template name="error">
2171          <xsl:with-param name="inline">no</xsl:with-param>
2172          <xsl:with-param name="msg">ol/@type=<xsl:value-of select="@type"/> not supported (defaulting to 'a')</xsl:with-param>
2173        </xsl:call-template>
2174        <xsl:text>letters</xsl:text>
2175      </xsl:when>
2176      <xsl:when test="string-length(@type)>1">format <xsl:value-of select="@type"/></xsl:when>
2177      <xsl:otherwise>
2178        <xsl:call-template name="error">
2179          <xsl:with-param name="inline">no</xsl:with-param>
2180          <xsl:with-param name="msg">ol/@type=<xsl:value-of select="@type"/> not supported (defaulting to '1')</xsl:with-param>
2181        </xsl:call-template>
2182        <xsl:text>numbers</xsl:text>
2183      </xsl:otherwise>
2184    </xsl:choose>
2185  </xsl:variable>
2186  <list style="{$style}">
2187    <xsl:if test="@group">
2188      <xsl:attribute name="counter"><xsl:value-of select="@group"/></xsl:attribute>
2189    </xsl:if>
2190    <xsl:apply-templates mode="cleanup"/>
2191  </list>
2192</xsl:template>
2193
2194<!-- Unordered Lists -->
2195<xsl:template match="ul" mode="cleanup">
2196  <xsl:choose>
2197    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2198      <ul>
2199        <xsl:apply-templates select="@*" mode="cleanup"/>
2200        <xsl:if test="not(li) and @x:when-empty">
2201          <li>
2202            <xsl:value-of select="@x:when-empty"/>
2203          </li>
2204        </xsl:if>
2205        <xsl:apply-templates select="node()" mode="cleanup"/>
2206      </ul>
2207    </xsl:when>
2208    <xsl:otherwise>
2209      <xsl:call-template name="ul-to-v2"/>
2210    </xsl:otherwise>
2211  </xsl:choose>
2212</xsl:template>
2213<xsl:template match="ul/@x:when-empty" mode="cleanup"/>
2214
2215<xsl:template name="ul-to-v2">
2216  <xsl:choose>
2217    <xsl:when test="not(li) and @x:when-empty">
2218      <t>
2219        <xsl:value-of select="@x:when-empty"/>
2220      </t>
2221    </xsl:when>
2222    <xsl:when test="parent::dd">
2223      <!-- ul nested in dd -->
2224      <xsl:choose>
2225        <xsl:when test="@empty='true'">
2226          <list style="empty">
2227            <xsl:apply-templates mode="cleanup"/>
2228          </list>
2229        </xsl:when>
2230        <xsl:otherwise>
2231          <list style="symbols">
2232            <xsl:apply-templates mode="cleanup"/>
2233          </list>
2234        </xsl:otherwise>
2235      </xsl:choose>
2236    </xsl:when>
2237    <xsl:otherwise>
2238      <t>
2239        <xsl:choose>
2240          <xsl:when test="@empty='true'">
2241            <list style="empty">
2242              <xsl:apply-templates mode="cleanup"/>
2243            </list>
2244          </xsl:when>
2245          <xsl:otherwise>
2246            <list style="symbols">
2247              <xsl:apply-templates mode="cleanup"/>
2248            </list>
2249          </xsl:otherwise>
2250        </xsl:choose>
2251      </t>
2252    </xsl:otherwise>
2253  </xsl:choose>
2254</xsl:template>
2255
2256<xsl:template name="get-content-of-artwork">
2257  <xsl:variable name="content2"><xsl:apply-templates select="node()"/></xsl:variable>
2258  <xsl:variable name="content" select="translate($content2,'&#160;&#x2500;&#x2502;&#x2508;&#x250c;&#x2510;&#x2514;&#x2518;&#x251c;&#x2524;',' -|+++++++')"/>
2259  <xsl:value-of select="$content"/>
2260</xsl:template>
2261
2262<xsl:template name="insert-sourcecode-as-artwork">
2263  <artwork>
2264    <xsl:copy-of select="@type"/>
2265    <xsl:if test="@markers='true'">
2266      <xsl:text>&lt;CODE BEGINS></xsl:text>
2267      <xsl:if test="self::sourcecode and @name">
2268        <xsl:variable name="offending" select="translate(@name,concat($alnum,'-+.,;_~#'),'')"/>
2269        <xsl:choose>
2270          <xsl:when test="$offending!=''">
2271            <xsl:call-template name="error">
2272              <xsl:with-param name="msg">illegal characters in @name attribute '<xsl:value-of select="@name"/>': '<xsl:value-of select="$offending"/>'</xsl:with-param>
2273            </xsl:call-template>
2274          </xsl:when>
2275          <xsl:otherwise>
2276            <xsl:text> file "</xsl:text>
2277            <xsl:value-of select="@name"/>
2278            <xsl:text>"</xsl:text>
2279          </xsl:otherwise>
2280        </xsl:choose>
2281      </xsl:if>
2282      <xsl:text>&#10;</xsl:text>
2283    </xsl:if>
2284
2285    <xsl:if test="starts-with(.,'&#10;')">
2286      <xsl:text>&#10;</xsl:text>
2287      <xsl:value-of select="@x:indent-with"/>
2288    </xsl:if>
2289    <xsl:call-template name="get-content-of-artwork"/>
2290    <xsl:if test="@markers='true'">&#10;&lt;CODE ENDS></xsl:if>
2291  </artwork>
2292</xsl:template>
2293
2294<!-- Source Code -->
2295<xsl:template match="sourcecode" mode="cleanup">
2296  <xsl:choose>
2297    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2298      <xsl:apply-templates select=".//iref" mode="cleanup"/>
2299      <sourcecode>
2300        <xsl:copy-of select="@*"/>
2301        <xsl:call-template name="get-content-of-artwork"/>
2302      </sourcecode>
2303    </xsl:when>
2304    <xsl:when test="parent::figure">
2305      <xsl:call-template name="insert-sourcecode-as-artwork"/>
2306    </xsl:when>
2307    <xsl:when test="parent::blockquote">
2308      <t>
2309        <figure>
2310          <xsl:apply-templates select=".//iref" mode="cleanup"/>
2311          <xsl:call-template name="insert-sourcecode-as-artwork"/>
2312        </figure>
2313      </t>
2314    </xsl:when>
2315    <xsl:otherwise>
2316      <figure>
2317        <xsl:apply-templates select=".//iref" mode="cleanup"/>
2318        <xsl:call-template name="insert-sourcecode-as-artwork"/>
2319      </figure>
2320    </xsl:otherwise>
2321  </xsl:choose>
2322</xsl:template>
2323
2324<!-- Tables -->
2325<xsl:template match="table" mode="cleanup">
2326  <xsl:choose>
2327    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2328      <table>
2329        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2330      </table>
2331    </xsl:when>
2332    <xsl:otherwise>
2333      <xsl:call-template name="table-to-v2"/>
2334    </xsl:otherwise>
2335  </xsl:choose>
2336</xsl:template>
2337
2338<xsl:template name="table-to-v2">
2339  <texttable>
2340    <xsl:apply-templates select="@anchor|@align" mode="cleanup"/>
2341    <xsl:if test="not(@align)">
2342      <xsl:attribute name="align">left</xsl:attribute>
2343    </xsl:if>
2344    <xsl:variable name="title">
2345      <xsl:choose>
2346        <xsl:when test="name">
2347          <xsl:variable name="hold">
2348            <xsl:apply-templates select="name/node()"/>
2349          </xsl:variable>
2350          <xsl:value-of select="normalize-space($hold)"/>
2351        </xsl:when>
2352        <xsl:otherwise>
2353          <xsl:value-of select="@title"/>
2354        </xsl:otherwise>
2355      </xsl:choose>
2356    </xsl:variable>
2357    <xsl:if test="$title!=''">
2358      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
2359    </xsl:if>
2360    <xsl:if test="count(thead/tr) > 1">
2361      <xsl:call-template name="error">
2362        <xsl:with-param name="inline">no</xsl:with-param>
2363        <xsl:with-param name="msg">Multiple table header lines not supported</xsl:with-param>
2364      </xsl:call-template>
2365    </xsl:if>
2366    <xsl:for-each select="thead/tr/*">
2367      <xsl:variable name="p" select="position()"/>
2368      <!-- in texttable the whole column has the same alignment; we try
2369      either the first non-header row or the header itself-->
2370      <xsl:variable name="align">
2371        <xsl:choose>
2372          <xsl:when test="tbody/tr[1]/*[1] and tbody/tr[1]/*[1]/@align"><xsl:value-of select="tbody/tr[1]/*[1]/@align"/></xsl:when>
2373          <xsl:when test="@align"><xsl:value-of select="@align"/></xsl:when>
2374          <xsl:otherwise>left</xsl:otherwise>
2375        </xsl:choose>
2376      </xsl:variable>
2377      <ttcol align="{$align}">
2378        <xsl:apply-templates mode="cleanup"/>
2379      </ttcol>
2380    </xsl:for-each>
2381    <xsl:for-each select="tbody/tr/*">
2382      <c>
2383        <xsl:if test="position()=1">
2384          <xsl:apply-templates select="../../../iref" mode="cleanup"/>
2385        </xsl:if>
2386        <xsl:choose>
2387          <xsl:when test="t|sourcecode|ol|dl|uo">
2388            <xsl:apply-templates select="t/node()|sourcecode/node()|ol/li/node()|ul/li/node()|dl/*/node()" mode="cleanup"/>
2389          </xsl:when>
2390          <xsl:otherwise>
2391            <xsl:apply-templates mode="cleanup"/>
2392          </xsl:otherwise>
2393        </xsl:choose>
2394      </c>
2395      <xsl:if test="@rowspan and @rowspan!='1'">
2396        <xsl:call-template name="error">
2397          <xsl:with-param name="inline">no</xsl:with-param>
2398          <xsl:with-param name="msg">rowspan attribute not supported (dropped, table will be ugly)</xsl:with-param>
2399        </xsl:call-template>
2400      </xsl:if>
2401      <xsl:if test="@colspan and @colspan!='1'">
2402        <xsl:call-template name="error">
2403          <xsl:with-param name="inline">no</xsl:with-param>
2404          <xsl:with-param name="msg">colspan attribute not supported (dropped, table will be ugly)</xsl:with-param>
2405        </xsl:call-template>
2406      </xsl:if>
2407    </xsl:for-each>
2408    <xsl:if test="tfoot">
2409      <xsl:call-template name="error">
2410        <xsl:with-param name="inline">no</xsl:with-param>
2411        <xsl:with-param name="msg">tfoot element not supported (dropped)</xsl:with-param>
2412      </xsl:call-template>
2413    </xsl:if>
2414  </texttable>
2415</xsl:template>
2416
2417<!-- date formats -->
2418<xsl:template match="/rfc/front/date/@month" mode="cleanup">
2419  <xsl:attribute name="month">
2420    <xsl:choose>
2421      <xsl:when test="string(number(.))!='NaN' and number(.)&gt;0 and number(.)&lt;13">
2422        <xsl:call-template name="get-month-as-name">
2423          <xsl:with-param name="month" select="."/>
2424        </xsl:call-template>
2425      </xsl:when>
2426      <xsl:otherwise>
2427        <xsl:value-of select="."/>
2428      </xsl:otherwise>
2429    </xsl:choose>
2430  </xsl:attribute>
2431</xsl:template>
2432
2433<!-- x:contributor/contact -->
2434<xsl:template match="x:contributor|contact" mode="cleanup">
2435  <xsl:choose>
2436    <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2437      <contact>
2438        <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2439      </contact>
2440    </xsl:when>
2441    <xsl:otherwise>
2442      <xsl:variable name="content">
2443        <xsl:apply-templates select="."/>
2444      </xsl:variable>
2445      <t>
2446        <xsl:apply-templates select="exslt:node-set($content)/*" mode="text"/>
2447      </t>
2448    </xsl:otherwise>
2449  </xsl:choose>
2450</xsl:template>
2451
2452<xsl:template match="*" mode="text">
2453  <xsl:apply-templates mode="text"/>
2454</xsl:template>
2455<xsl:template match="text()" mode="text">
2456  <xsl:value-of select="."/>
2457</xsl:template>
2458<xsl:template match="br" mode="text">
2459  <vspace blankLines="0"/>
2460</xsl:template>
2461
2462<!-- x:include -->
2463<xsl:template match="/rfc/back/references/xi:include|/rfc/back/references/referencegroup/xi:include" mode="cleanup">
2464  <xsl:apply-templates select="document(@href)" mode="cleanup"/>
2465</xsl:template>
2466
2467<!-- Display names for references -->
2468<xsl:template match="displayreference" mode="cleanup">
2469  <xsl:if test="$xml2rfc-ext-xml2rfc-voc >= 3">
2470    <xsl:copy>
2471      <xsl:apply-templates select="@*|node()" mode="cleanup"/>
2472    </xsl:copy>
2473  </xsl:if>
2474</xsl:template>
2475
2476<xsl:template match="reference/@anchor[.=/rfc/back/displayreference/@target]" mode="cleanup">
2477  <xsl:attribute name="anchor">
2478    <xsl:choose>
2479      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2480        <xsl:value-of select="."/>
2481      </xsl:when>
2482      <xsl:otherwise>
2483        <xsl:call-template name="generate-ref-name"/>
2484      </xsl:otherwise>
2485    </xsl:choose>
2486  </xsl:attribute>
2487</xsl:template>
2488<xsl:template match="xref/@target[.=/rfc/back/displayreference/@target]" mode="cleanup">
2489  <xsl:attribute name="target">
2490    <xsl:choose>
2491      <xsl:when test="$xml2rfc-ext-xml2rfc-voc >= 3">
2492        <xsl:value-of select="."/>
2493      </xsl:when>
2494      <xsl:otherwise>
2495        <xsl:call-template name="generate-ref-name"/>
2496      </xsl:otherwise>
2497    </xsl:choose>
2498  </xsl:attribute>
2499</xsl:template>
2500
2501<xsl:template name="generate-ref-name">
2502  <xsl:variable name="tnewname">
2503    <xsl:value-of select="/rfc/back/displayreference[@target=current()]/@to"/>
2504  </xsl:variable>
2505  <xsl:choose>
2506    <xsl:when test="count(/rfc/back/displayreference[@to=current()])>1 or //reference[@anchor=$tnewname]">
2507      <xsl:value-of select="current()"/>
2508      <xsl:call-template name="warning">
2509        <xsl:with-param name="msg">Not rewriting reference name <xsl:value-of select="current()"/> as it would conflict</xsl:with-param>
2510      </xsl:call-template>
2511    </xsl:when>
2512    <xsl:when test="translate(substring($tnewname,1,1),$digits,'')=''">
2513      <xsl:value-of select="concat('_',$tnewname)"/>
2514      <xsl:call-template name="warning">
2515        <xsl:with-param name="msg">rewriting reference name '<xsl:value-of select="$tnewname"/>' to '<xsl:value-of select="concat('_',$tnewname)"/>' due to illegal start character</xsl:with-param>
2516      </xsl:call-template>
2517    </xsl:when>
2518    <xsl:otherwise>
2519      <xsl:value-of select="$tnewname"/>
2520    </xsl:otherwise>
2521  </xsl:choose>
2522</xsl:template>
2523
2524<!-- removal of xml2rfc preptool artefacts -->
2525<xsl:template match="/rfc/@prepTime" mode="cleanup"/>
2526<xsl:template match="/rfc/front/toc" mode="cleanup"/>
2527
2528</xsl:transform>
Note: See TracBrowser for help on using the repository browser.