source: rfc2629xslt/clean-for-DTD.xslt @ 2761

Last change on this file since 2761 was 2761, checked in by julian.reschke@…, 13 months ago

update XSLTs

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