source: rfc2629xslt/clean-for-DTD.xslt

Last change on this file was 2750, checked in by julian.reschke@…, 4 years ago

update rfc2629.xslt

  • Property svn:eol-style set to native
File size: 38.1 KB
Line 
1<!--
2    Strip rfc2629.xslt extensions, generating XML input for MTR's xml2rfc
3
4    Copyright (c) 2006-2016, 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:ed="http://greenbytes.de/2002/rfcedit"
35                xmlns:grddl="http://www.w3.org/2003/g/data-view#"
36                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
37                xmlns:svg="http://www.w3.org/2000/svg"
38                xmlns:x="http://purl.org/net/xml2rfc/ext"
39                xmlns:xi="http://www.w3.org/2001/XInclude"
40                xmlns:xhtml="http://www.w3.org/1999/xhtml"
41                exclude-result-prefixes="ed grddl rdf svg x xi xhtml"
42>
43
44<!-- re-use some of the default RFC2629.xslt rules -->
45<xsl:import href="rfc2629.xslt"/>
46
47<!-- undo strip-space decls -->
48<xsl:preserve-space elements="*"/>
49
50<!-- generate DTD-valid output, override all values imported from rfc2629.xslt -->
51<xsl:output doctype-system="rfc2629.dtd" doctype-public="" method="xml" version="1.0" encoding="UTF-8" cdata-section-elements="artwork" />
52
53<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
54<xsl:param name="xml2rfc-ext-strip-vbare">false</xsl:param>
55
56<!-- kick into cleanup mode -->
57<xsl:template match="/">
58  <xsl:text>&#10;</xsl:text>
59  <xsl:comment>
60    This XML document is the output of clean-for-DTD.xslt; a tool that strips
61    extensions to RFC2629(bis) from documents for processing with xml2rfc.
62</xsl:comment>
63  <xsl:apply-templates select="/" mode="cleanup"/>
64</xsl:template>
65
66<!-- rules for identity transformations -->
67
68<xsl:template match="processing-instruction()" mode="cleanup">
69  <xsl:text>&#10;</xsl:text>
70  <xsl:copy/>
71</xsl:template>
72
73<xsl:template match="comment()|@*" mode="cleanup"><xsl:copy/></xsl:template>
74
75<xsl:template match="text()" mode="cleanup"><xsl:copy/></xsl:template>
76
77<xsl:template match="/" mode="cleanup">
78        <xsl:copy><xsl:apply-templates select="node()" mode="cleanup" /></xsl:copy>
79</xsl:template>
80
81<xsl:template match="*" mode="cleanup">
82  <xsl:element name="{local-name()}">
83        <xsl:apply-templates select="node()|@*" mode="cleanup" />
84  </xsl:element>
85</xsl:template>
86
87
88<!-- remove PI extensions -->
89
90<xsl:template match="processing-instruction('rfc-ext')" mode="cleanup"/>
91<xsl:template match="processing-instruction('BEGININC')" mode="cleanup"/>
92<xsl:template match="processing-instruction('ENDINC')" mode="cleanup"/>
93
94<!-- add issues appendix -->
95
96<xsl:template match="back" mode="cleanup">
97  <back>
98    <xsl:apply-templates select="node()|@*" mode="cleanup" />
99    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='closed']">
100      <section title="Resolved issues (to be removed by RFC Editor before publication)">
101        <t>
102          Issues that were either rejected or resolved in this version of this
103          document.
104        </t>
105        <xsl:apply-templates select="//ed:issue[@status='closed']" mode="issues" />
106      </section>
107    </xsl:if>
108    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='open']">
109      <section title="Open issues (to be removed by RFC Editor prior to publication)">
110        <xsl:apply-templates select="//ed:issue[@status!='closed']" mode="issues" />
111      </section>
112    </xsl:if>
113  </back>
114</xsl:template>
115
116
117
118
119<!-- extensions -->
120
121<xsl:template match="x:abnf-char-sequence" mode="cleanup">
122  <xsl:choose>
123    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
124      <xsl:call-template name="error">
125        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
126      </xsl:call-template>
127    </xsl:when>
128    <xsl:otherwise>
129      <xsl:text>%x</xsl:text>
130      <xsl:call-template name="to-abnf-char-sequence">
131        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
132      </xsl:call-template>
133    </xsl:otherwise>
134  </xsl:choose>
135</xsl:template>
136
137<xsl:template match="x:anchor-alias" mode="cleanup"/>
138
139<xsl:template match="x:bcp14|bcp14" mode="cleanup">
140  <xsl:apply-templates/>
141</xsl:template>
142
143<xsl:template match="x:assign-section-number" mode="cleanup"/> 
144<xsl:template match="x:link" mode="cleanup"/>
145<xsl:template match="x:source" mode="cleanup"/>
146<xsl:template match="x:feedback" mode="cleanup"/>
147
148<xsl:template match="x:parse-xml" mode="cleanup">
149  <xsl:apply-templates/>
150</xsl:template>
151
152<xsl:template match="x:prose" mode="cleanup">
153  <xsl:variable name="text" select="."/>
154  <xsl:comment>Converted from rfc2629.xslt x:prose extension</xsl:comment>
155  <xsl:choose>
156    <xsl:when test="contains($text,' ')">
157      <seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
158    </xsl:when>
159    <xsl:otherwise>
160      <seriesInfo name="" value="{$text}"/>
161    </xsl:otherwise>
162  </xsl:choose>
163</xsl:template>
164
165<xsl:template match="refcontent" mode="cleanup">
166  <xsl:variable name="text">
167    <xsl:apply-templates mode="cleanup"/>
168  </xsl:variable>
169  <xsl:comment>Converted from rfc2629.xslt refcontent extension</xsl:comment>
170  <xsl:choose>
171    <xsl:when test="contains($text,' ')">
172      <seriesInfo name="{substring-before($text,' ')}" value="{substring-after($text,' ')}"/>
173    </xsl:when>
174    <xsl:otherwise>
175      <seriesInfo name="" value="{$text}"/>
176    </xsl:otherwise>
177  </xsl:choose>
178</xsl:template>
179
180<xsl:template match="postalLine" mode="cleanup">
181  <xsl:comment>converted from v3 &lt;postalLine&gt;</xsl:comment>
182  <street><xsl:value-of select="."/></street>
183</xsl:template>
184
185<xsl:template match="x:ref" mode="cleanup">
186  <xsl:variable name="val" select="normalize-space(.)"/>
187  <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]"/>
188  <xsl:if test="count($target)>1">
189    <xsl:message terminate="yes">FATAL: multiple x:ref targets found for <xsl:value-of select="$val"/>.</xsl:message>
190  </xsl:if>
191  <xsl:choose>
192    <xsl:when test="$target/self::x:source">
193      <!-- drop it-->
194      <xsl:value-of select="."/>
195    </xsl:when>
196    <xsl:when test="$target">
197      <xsl:variable name="current" select="."/>
198      <xsl:for-each select="$target">
199        <!-- make it the context -->
200        <xsl:choose>
201          <xsl:when test="self::preamble">
202            <!-- it's not an element we can link to -->
203            <xsl:call-template name="warning">
204              <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>
205            </xsl:call-template>
206            <xsl:value-of select="$current"/>
207          </xsl:when>
208          <xsl:otherwise>
209            <xref target="{$target/@anchor}" format="none"><xsl:value-of select="$current"/></xref>
210          </xsl:otherwise>
211        </xsl:choose>
212      </xsl:for-each>
213    </xsl:when>
214    <xsl:otherwise>
215      <xsl:call-template name="warning">
216        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="$val"/>' does not exist.</xsl:with-param>
217      </xsl:call-template>
218      <xsl:value-of select="."/>
219    </xsl:otherwise>
220  </xsl:choose>
221</xsl:template>
222
223<xsl:template match="x:blockquote|blockquote" mode="cleanup">
224  <t><list>
225    <xsl:apply-templates mode="cleanup" />
226  </list></t>
227</xsl:template>
228
229<xsl:template match="x:h" mode="cleanup">
230  <xsl:apply-templates mode="cleanup" />
231</xsl:template>
232
233<xsl:template match="x:highlight" mode="cleanup">
234  <xsl:apply-templates mode="cleanup" />
235</xsl:template>
236
237<xsl:template match="x:lt" mode="cleanup">
238  <t>
239    <xsl:apply-templates select="@hangText|@anchor" mode="cleanup"/>
240    <xsl:for-each select="t">
241      <xsl:apply-templates mode="cleanup"/>
242      <xsl:if test="position()!=last()">
243        <vspace blankLines="1"/>
244      </xsl:if>
245    </xsl:for-each>
246  </t>
247</xsl:template>
248
249<xsl:template match="x:note|aside" mode="cleanup">
250  <t>
251    <xsl:apply-templates select="@anchor" mode="cleanup"/>
252    <list>
253      <xsl:apply-templates mode="cleanup"/>
254    </list>
255  </t>
256</xsl:template>
257
258<xsl:template match="x:q" mode="cleanup">
259  <xsl:text>"</xsl:text>
260  <xsl:apply-templates mode="cleanup"/>
261  <xsl:text>"</xsl:text>
262</xsl:template>
263
264<xsl:template match="x:dfn" mode="cleanup">
265  <!-- help xml2rfc to keep dfn and following text on the same page -->
266  <!-- removed for now because it broke httpbis-p2 (def of 200 OK in -25)
267  <xsl:if test="not(preceding-sibling::x:dfn) and count(following-sibling::list)=1 and normalize-space(../text()='')">
268    <xsl:processing-instruction name="rfc">needLines="4"</xsl:processing-instruction>
269  </xsl:if>-->
270  <xsl:apply-templates mode="cleanup"/>
271</xsl:template>
272
273<xsl:template match="x:sup|sup" mode="cleanup">
274  <xsl:text>^</xsl:text>
275  <xsl:apply-templates mode="cleanup" />
276</xsl:template>
277
278<xsl:template match="sub" mode="cleanup">
279  <xsl:text>_</xsl:text>
280  <xsl:apply-templates mode="cleanup" />
281</xsl:template>
282
283<xsl:template match="x:span" mode="cleanup">
284  <xsl:apply-templates mode="cleanup" />
285</xsl:template>
286<xsl:template match="x:span/@anchor" mode="cleanup"/>
287
288<xsl:template match="author/@anchor" mode="cleanup"/>
289<xsl:template match="x:include-author" mode="cleanup">
290  <t>
291    <xsl:value-of select="/*/front/author[@anchor=current()/@target]"/>
292  </t>
293  <t>
294    (see Authors Section)
295  </t>
296</xsl:template>
297
298<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel or @section or @sectionFormat or @relative) and not(node())]" mode="cleanup">
299  <xsl:call-template name="insert-iref-for-xref"/>
300  <xsl:variable name="node" select="$src//*[@anchor=current()/@target]" />
301
302  <xsl:variable name="ssec">
303    <xsl:call-template name="get-section-xref-section"/>
304  </xsl:variable>
305
306  <xsl:variable name="sec">
307    <xsl:choose>
308      <xsl:when test="starts-with(@x:rel,'#') and $ssec='' and $node/x:source/@href">
309        <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
310        <xsl:for-each select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]">
311          <xsl:call-template name="get-section-number"/>
312        </xsl:for-each>
313      </xsl:when>
314      <xsl:otherwise>
315        <xsl:value-of select="$ssec"/>
316      </xsl:otherwise>
317    </xsl:choose>
318  </xsl:variable>
319
320  <xsl:variable name="secterm">
321    <xsl:choose>
322      <!-- starts with letter? -->
323      <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">Appendix</xsl:when>
324      <xsl:otherwise>Section</xsl:otherwise>
325    </xsl:choose>
326  </xsl:variable>
327
328  <xsl:variable name="sfmt">
329    <xsl:call-template name="get-section-xref-format">
330      <xsl:with-param name="default">
331        <xsl:choose>
332          <xsl:when test="ancestor::artwork">comma</xsl:when>
333          <xsl:otherwise>of</xsl:otherwise>
334        </xsl:choose>
335      </xsl:with-param>
336    </xsl:call-template>
337  </xsl:variable>
338 
339  <xsl:choose>
340    <xsl:when test="$sfmt='comma'">
341      <xref>
342        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
343      </xref>
344      <xsl:text>, </xsl:text>
345      <xsl:value-of select="$secterm"/>
346      <xsl:text> </xsl:text>
347      <xsl:value-of select="$sec"/>
348    </xsl:when>
349    <xsl:when test="$sfmt='section'">
350      <xsl:value-of select="$secterm"/>
351      <xsl:text> </xsl:text>
352      <xsl:value-of select="$sec"/>
353    </xsl:when>
354    <xsl:when test="$sfmt='number-only'">
355      <xsl:value-of select="$sec"/>
356    </xsl:when>
357    <xsl:when test="$sfmt='parens'">
358      <xref>
359        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
360      </xref>
361      <xsl:text> (</xsl:text>
362      <xsl:value-of select="$secterm"/>
363      <xsl:text> </xsl:text>
364      <xsl:value-of select="$sec"/>
365      <xsl:text>)</xsl:text>
366    </xsl:when>
367    <xsl:when test="$sfmt='of'">
368      <xsl:value-of select="$secterm"/>
369      <xsl:text> </xsl:text>
370      <xsl:value-of select="$sec"/>
371      <xsl:text> of </xsl:text>
372      <xref>
373        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
374      </xref>
375    </xsl:when>
376    <xsl:otherwise>
377      <xsl:copy>
378        <xsl:apply-templates select="node()" mode="cleanup"/>
379      </xsl:copy>
380    </xsl:otherwise>
381  </xsl:choose>
382</xsl:template>
383
384<xsl:template match="xref[(@x:fmt or @x:sec or @x:rel) and node()]" mode="cleanup">
385  <xsl:call-template name="insert-iref-for-xref"/>
386  <xsl:choose>
387    <xsl:when test="@x:fmt='none'">
388      <xsl:apply-templates mode="cleanup"/>
389    </xsl:when>
390    <xsl:when test="not(@x:fmt)">
391      <xref>
392        <xsl:copy-of select="@target|@format"/>
393        <xsl:apply-templates mode="cleanup"/>
394      </xref>
395    </xsl:when>
396    <xsl:otherwise>
397      <xsl:message>Unsupported x:fmt attribute.</xsl:message>
398    </xsl:otherwise>
399  </xsl:choose>
400</xsl:template>
401
402<xsl:template match="xref[node() and (@target=//preamble/@anchor or @target=//spanx/@anchor)]" mode="cleanup">
403  <!-- remove the link -->
404  <xsl:apply-templates select="node()" mode="cleanup"/>
405</xsl:template>
406
407<xsl:template match="xref[node() and @format='none' and @target=//artwork//@anchor]" mode="cleanup">
408  <!-- remove the link -->
409  <xsl:apply-templates select="node()" mode="cleanup"/>
410</xsl:template>
411
412<xsl:template match="xref[not(node()) and (@target=//preamble/@anchor or @target=//spanx/@anchor)]" mode="cleanup">
413  <!-- fatal -->
414  <xsl:message terminate="yes">Broken xref <xsl:value-of select="@target"/> due to target being filtered out.</xsl:message>
415</xsl:template>
416
417<xsl:template match="xref" mode="cleanup" priority="0">
418  <xsl:call-template name="insert-iref-for-xref"/>
419  <xref>
420    <xsl:apply-templates select="@target|@format" mode="cleanup"/>
421    <xsl:apply-templates mode="cleanup"/>
422  </xref>
423</xsl:template>
424
425<xsl:template name="insert-iref-for-xref">
426  <xsl:if test="$xml2rfc-ext-include-references-in-index='yesxxx' and $xml2rfc-ext-include-index='yes'">
427    <xsl:if test="@target=/rfc/back//reference/@anchor">
428      <iref item="{@target}"/>
429      <xsl:if test="@x:sec">
430        <xsl:choose>
431          <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
432            <iref item="{@target}" subitem="Appendix {@x:sec}"/>
433          </xsl:when>
434          <xsl:otherwise>
435            <iref item="{@target}" subitem="Section {@x:sec}"/>
436          </xsl:otherwise>
437        </xsl:choose>
438      </xsl:if>
439    </xsl:if>
440  </xsl:if>
441</xsl:template>
442
443<!-- drop index gen extension -->
444<xsl:template match="iref" mode="cleanup">
445  <xsl:if test="$xml2rfc-ext-include-index='yes'">
446    <iref>
447      <xsl:apply-templates select="@*|node()" mode="cleanup"/>
448    </iref>
449  </xsl:if>
450</xsl:template>
451
452
453<!-- issue tracking extensions -->
454
455<xsl:template match="@xml:lang" mode="cleanup"/>
456<xsl:template match="@xml:lang" />
457
458<xsl:template match="ed:*" mode="cleanup"/>
459<xsl:template match="ed:*" />
460
461<xsl:template match="@ed:*" mode="cleanup"/>
462<xsl:template match="@ed:*" />
463
464<xsl:template match="ed:annotation" mode="cleanup" />
465
466<xsl:template match="ed:replace" mode="cleanup">
467  <xsl:apply-templates mode="cleanup" />
468</xsl:template>
469
470<xsl:template match="ed:replace">
471  <xsl:apply-templates/>
472</xsl:template>
473
474<xsl:template match="ed:ins" mode="cleanup">
475  <xsl:apply-templates mode="cleanup"/>
476</xsl:template>
477
478<xsl:template match="ed:ins">
479  <xsl:apply-templates/>
480</xsl:template>
481
482<xsl:template match="ed:issue" mode="issues">
483  <section title="{@name}">
484    <xsl:variable name="sec">
485      <xsl:call-template name="get-section-number"/>
486    </xsl:variable>
487
488    <xsl:if test="$sec!=''">
489      <t>
490        In Section <xsl:value-of select="$sec"/>:
491      </t>
492    </xsl:if>
493   
494    <t>
495      Type: <xsl:value-of select="@type" />
496    </t>
497    <xsl:if test="@href">
498      <t>
499        <!-- temp. removed because of xml2rfc's handling of erefs when producing TXT-->
500        <!--<eref target="{@href}" /> -->
501        <xsl:text>&lt;</xsl:text>
502        <xsl:value-of select="@href"/>
503        <xsl:text>></xsl:text>
504        <xsl:if test="@alternate-href">
505          <xsl:text>, &lt;</xsl:text>
506          <xsl:value-of select="@alternate-href"/>
507          <xsl:text>></xsl:text>
508        </xsl:if>
509      </t>
510    </xsl:if>
511    <xsl:for-each select="ed:item">
512      <t>
513        <xsl:if test="@entered-by or @date">
514          <xsl:choose>
515            <xsl:when test="not(@entered-by)">
516              <xsl:value-of select="concat('(',@date,') ')" />
517            </xsl:when>
518            <xsl:when test="not(@date)">
519              <xsl:value-of select="concat(@entered-by,': ')" />
520            </xsl:when>
521            <xsl:otherwise>
522              <xsl:value-of select="concat(@entered-by,' (',@date,'): ')" />
523            </xsl:otherwise>
524          </xsl:choose>     
525        </xsl:if>
526        <xsl:if test="not(xhtml:p)">
527          <xsl:apply-templates select="node()" mode="issues"/>
528        </xsl:if>
529      </t>
530      <xsl:if test="xhtml:p|xhtml:pre">
531        <xsl:for-each select="node()">
532          <xsl:choose>
533            <xsl:when test="self::xhtml:p">
534              <t>
535                <xsl:apply-templates select="node()" mode="issues"/>
536              </t>
537            </xsl:when>
538            <xsl:when test="self::xhtml:pre">
539              <figure>
540                <artwork><xsl:apply-templates select="node()" mode="issues"/></artwork>
541              </figure>
542            </xsl:when>
543            <xsl:otherwise>
544              <t>
545                <xsl:apply-templates select="." mode="issues"/>
546              </t>
547            </xsl:otherwise>
548          </xsl:choose>
549        </xsl:for-each>
550      </xsl:if>
551    </xsl:for-each>
552    <xsl:if test="ed:resolution">
553      <t>
554        <xsl:text>Resolution</xsl:text>
555        <xsl:if test="ed:resolution/@datetime"> (<xsl:value-of select="ed:resolution/@datetime"/>)</xsl:if>
556        <xsl:text>: </xsl:text>
557        <xsl:value-of select="ed:resolution" />
558      </t>
559    </xsl:if>
560  </section>
561</xsl:template>
562
563<xsl:template match="ed:issueref" mode="cleanup">
564  <xsl:apply-templates mode="cleanup"/>
565</xsl:template>
566
567<xsl:template match="*" mode="issues">
568  <xsl:apply-templates mode="issues"/>
569</xsl:template>
570
571<xsl:template match="xhtml:q" mode="issues">
572  <list><t>
573    <xsl:text>"</xsl:text>
574    <xsl:apply-templates mode="issues"/>
575    <xsl:text>"</xsl:text>
576    <xsl:if test="@cite">
577      <xsl:text> -- </xsl:text>
578      <eref target="{@cite}"><xsl:value-of select="@cite"/></eref>
579    </xsl:if>
580  </t></list>
581</xsl:template>
582
583<xsl:template match="xhtml:br" mode="issues">
584  <vspace/>
585</xsl:template>
586
587<xsl:template match="xhtml:del" mode="issues">
588  <xsl:text>&lt;del></xsl:text>
589    <xsl:apply-templates mode="issues"/>
590  <xsl:text>&lt;/del></xsl:text>
591</xsl:template>
592
593<xsl:template match="xhtml:em" mode="issues">
594  <spanx style="emph">
595    <xsl:apply-templates mode="issues"/>
596  </spanx>
597</xsl:template>
598
599<xsl:template match="xhtml:ins" mode="issues">
600  <xsl:text>&lt;ins></xsl:text>
601    <xsl:apply-templates mode="issues"/>
602  <xsl:text>&lt;/ins></xsl:text>
603</xsl:template>
604
605<xsl:template match="xhtml:tt" mode="issues">
606  <xsl:apply-templates mode="issues"/>
607</xsl:template>
608
609<xsl:template match="ed:eref" mode="issues">
610  <xsl:text>&lt;</xsl:text>
611  <xsl:value-of select="."/>
612  <xsl:text>&gt;</xsl:text>
613</xsl:template>
614
615<xsl:template match="ed:issueref" mode="issues">
616  <xsl:apply-templates mode="issues"/>
617</xsl:template>
618
619<xsl:template match="text()" mode="issues">
620  <xsl:value-of select="." />
621</xsl:template>
622
623<!-- workgroup format -->
624<xsl:template match="workgroup" mode="cleanup">
625  <workgroup>
626    <xsl:variable name="v" select="normalize-space(.)"/>
627    <xsl:variable name="h">
628      <!-- when a single name, append WG/RG postfix automatically -->
629      <xsl:choose>
630        <xsl:when test="not(contains($v, ' ')) and starts-with(/rfc/@docName,'draft-ietf-') and $submissionType='IETF'">
631          <xsl:value-of select="concat($v, ' Working Group')"/>
632        </xsl:when>
633        <xsl:when test="not(contains($v, ' ')) and starts-with(/rfc/@docName,'draft-irtf-') and $submissionType='IRTF'">
634          <xsl:value-of select="concat($v, ' Research Group')"/>
635        </xsl:when>
636        <xsl:otherwise>
637          <xsl:value-of select="$v"/>
638        </xsl:otherwise>
639      </xsl:choose>
640    </xsl:variable>
641    <xsl:value-of select="$h"/>
642  </workgroup>
643</xsl:template>
644
645<!-- markup inside artwork element -->
646
647<xsl:template match="figure[.//artwork//iref | .//artwork//xref]" mode="cleanup">
648  <!-- move up iref elements -->
649  <xsl:for-each select=".//artwork//xref">
650    <xsl:if test="not(ancestor::ed:del)">
651      <xsl:call-template name="insert-iref-for-xref"/>
652    </xsl:if>
653  </xsl:for-each>
654  <figure>
655    <xsl:apply-templates select="@*" mode="cleanup" />
656    <xsl:apply-templates select=".//artwork//iref" mode="cleanup"/>
657    <xsl:apply-templates select="iref|preamble|artwork|postamble|ed:replace|ed:ins|ed:del" mode="cleanup" />
658  </figure>
659</xsl:template>
660
661<xsl:template name="insert-begin-code"/>
662<xsl:template name="insert-end-code"/>
663<xsl:template match="@x:is-code-component" mode="cleanup"/>
664
665<xsl:template match="artwork[svg:svg]" mode="cleanup">
666<xsl:call-template name="warning">
667  <xsl:with-param name="msg">SVG image removed.</xsl:with-param>
668</xsl:call-template>
669<artwork>(see SVG image in HTML version)</artwork>
670</xsl:template>
671
672<xsl:template match="artwork" mode="cleanup">
673  <xsl:variable name="content2"><xsl:apply-templates select="."/></xsl:variable>
674  <xsl:variable name="content" select="translate($content2,'&#160;&#x2500;&#x2502;&#x2508;&#x250c;&#x2510;&#x2514;&#x2518;&#x251c;&#x2524;',' -|+++++++')"/>
675  <artwork>
676    <xsl:apply-templates select="@*" mode="cleanup" />
677    <xsl:if test="@x:is-code-component='yes'">
678      <xsl:if test="starts-with(.,'&#10;')">
679        <xsl:text>&#10;</xsl:text>
680      </xsl:if>
681      <xsl:value-of select="@x:indent-with"/>
682      <xsl:text>&lt;CODE BEGINS&gt;&#10;</xsl:text>
683    </xsl:if>
684    <xsl:if test="starts-with(.,'&#10;')">
685      <xsl:text>&#10;</xsl:text>
686      <xsl:value-of select="@x:indent-with"/>
687    </xsl:if>
688    <xsl:choose>
689      <xsl:when test="@x:indent-with!=''">
690        <xsl:call-template name="indent">
691          <xsl:with-param name="content" select="$content"/>
692          <xsl:with-param name="with" select="@x:indent-with"/>
693        </xsl:call-template>
694      </xsl:when>
695      <xsl:otherwise>
696        <xsl:value-of select="$content"/>
697      </xsl:otherwise>
698    </xsl:choose>
699    <xsl:if test="@x:is-code-component='yes'">&#10;&lt;CODE ENDS&gt;&#10;</xsl:if>
700  </artwork> 
701</xsl:template>
702
703<xsl:template match="@x:indent-with" mode="cleanup"/>
704<xsl:template match="@x:lang" mode="cleanup"/>
705
706<xsl:template name="indent">
707  <xsl:param name="content"/>
708  <xsl:param name="with"/>
709
710  <xsl:value-of select="substring($content,1,1)"/>
711  <xsl:if test="substring($content,1,1)='&#10;'">
712    <xsl:value-of select="$with"/>
713  </xsl:if>
714 
715  <xsl:choose>
716    <xsl:when test="$content=''" />
717    <xsl:otherwise>
718      <xsl:call-template name="indent">
719        <xsl:with-param name="content" select="substring($content,2)"/>
720        <xsl:with-param name="with" select="$with"/>
721      </xsl:call-template>
722    </xsl:otherwise>
723  </xsl:choose>
724 
725</xsl:template>
726
727<!-- email repetitions -->
728<xsl:template match="email" mode="cleanup">
729  <!-- combine in a single element -->
730  <xsl:if test="not(preceding-sibling::email)">
731    <email>
732      <xsl:for-each select="../email">
733        <xsl:value-of select="."/>
734        <xsl:if test="position()!=last()">
735          <xsl:text>, </xsl:text>
736        </xsl:if>
737      </xsl:for-each>
738    </email>
739  </xsl:if>
740</xsl:template>
741
742<!-- markup inside cref -->
743<xsl:template match="cref//eref" mode="cleanup">
744  <xsl:text>&lt;</xsl:text>
745  <xsl:value-of select="@target"/>
746  <xsl:text>&gt;</xsl:text>
747</xsl:template>
748
749<xsl:template match="cref//xref" mode="cleanup" priority="9">
750  <xsl:variable name="text">
751    <xsl:apply-templates select="."/>
752  </xsl:variable>
753  <xsl:value-of select="$text"/>
754</xsl:template>
755
756<!-- annotations -->
757<xsl:template match="@x:annotation" mode="cleanup">
758  <xsl:comment>
759    <xsl:value-of select="."/>
760  </xsl:comment>
761  <xsl:call-template name="warning">
762    <xsl:with-param name="msg">Dropping annotation on <xsl:value-of select="local-name(..)"/> element.</xsl:with-param>
763  </xsl:call-template>
764</xsl:template>
765
766<!-- artwork extensions -->
767<xsl:template match="artwork/@x:extraction-note" mode="cleanup"/>
768
769<!-- list formatting -->
770<xsl:template match="list/@x:indent" mode="cleanup"/>
771
772<!-- rewrite to 'hanging' for now -->
773<xsl:template match="list[@style='x:dictionary']" mode="cleanup">
774  <list style="hanging">
775    <xsl:copy-of select="@hangIndent"/>
776    <xsl:apply-templates select="*" mode="cleanup"/>
777  </list>
778</xsl:template>
779
780<!-- referencing extensions -->
781<xsl:template match="iref/@x:for-anchor" mode="cleanup"/>
782
783<!-- GRRDL info stripped -->
784<xsl:template match="@grddl:transformation" mode="cleanup"/>
785
786<!-- maturity level stripped -->
787<xsl:template match="@x:maturity-level" mode="cleanup"/>
788
789<!-- normativity stripped -->
790<xsl:template match="@x:nrm" mode="cleanup"/>
791
792<!-- title extensions -->
793<xsl:template match="title/@x:quotes" mode="cleanup"/>
794
795<!-- RDF info stripped -->
796<xsl:template match="rdf:*" mode="cleanup"/>
797
798<!-- cases where xml2rfc does not allow anchors -->
799<xsl:template match="c/@anchor" mode="cleanup"/>
800<xsl:template match="preamble/@anchor" mode="cleanup"/>
801<xsl:template match="spanx/@anchor" mode="cleanup"/>
802
803<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
804<xsl:template match="spanx[@style='vbare']" mode="cleanup">
805  <xsl:choose>
806    <xsl:when test="$xml2rfc-ext-strip-vbare='true'">
807      <xsl:apply-templates mode="cleanup"/>
808    </xsl:when>
809    <xsl:otherwise>
810      <spanx style="vbare">
811        <xsl:apply-templates mode="cleanup"/>
812      </spanx>
813    </xsl:otherwise>
814  </xsl:choose>
815</xsl:template>
816
817<!-- v3 features -->
818<xsl:template match="strong" mode="cleanup">
819  <xsl:choose>
820    <xsl:when test="*">
821      <xsl:call-template name="warning">
822        <xsl:with-param name="msg">strong not translated when including child elements</xsl:with-param>
823      </xsl:call-template>
824      <xsl:apply-templates mode="cleanup"/>
825    </xsl:when>
826    <xsl:otherwise>
827      <spanx style="strong">
828        <xsl:apply-templates mode="cleanup"/>
829      </spanx>
830    </xsl:otherwise>
831  </xsl:choose>
832</xsl:template>
833
834<xsl:template match="em" mode="cleanup">
835  <xsl:choose>
836    <xsl:when test="*">
837      <xsl:call-template name="warning">
838        <xsl:with-param name="msg">em not translated when including child elements</xsl:with-param>
839      </xsl:call-template>
840      <xsl:apply-templates mode="cleanup"/>
841    </xsl:when>
842    <xsl:otherwise>
843      <spanx style="emph">
844        <xsl:apply-templates mode="cleanup"/>
845      </spanx>
846    </xsl:otherwise>
847  </xsl:choose>
848</xsl:template>
849
850<xsl:template match="tt" mode="cleanup">
851  <xsl:choose>
852    <xsl:when test="*">
853      <xsl:call-template name="warning">
854        <xsl:with-param name="msg">tt not translated when they include child elements</xsl:with-param>
855      </xsl:call-template>
856      <xsl:apply-templates mode="cleanup"/>
857    </xsl:when>
858    <xsl:otherwise>
859      <spanx style="verb">
860        <xsl:apply-templates mode="cleanup"/>
861      </spanx>
862    </xsl:otherwise>
863  </xsl:choose>
864</xsl:template>
865
866<!-- New reference attributes -->
867<xsl:template match="reference/@quoteTitle" mode="cleanup"/>
868<xsl:template match="reference" mode="cleanup">
869  <reference>
870    <xsl:apply-templates select="@anchor|@target" mode="cleanup"/>
871    <xsl:choose>
872      <xsl:when test="not(@target) and $xml2rfc-ext-link-rfc-to-info-page='yes' and seriesInfo[@name='BCP'] and starts-with(@anchor,'BCP')">
873        <xsl:variable name="uri" select="concat('http://www.rfc-editor.org/info/bcp',seriesInfo[@name='BCP']/@value)"/>
874        <xsl:attribute name="target"><xsl:value-of select="$uri"/></xsl:attribute>
875      </xsl:when>
876      <xsl:when test="not(@target) and $xml2rfc-ext-link-rfc-to-info-page='yes' and seriesInfo[@name='RFC']">
877        <xsl:variable name="uri" select="concat('http://www.rfc-editor.org/info/rfc',seriesInfo[@name='RFC']/@value)"/>
878        <xsl:attribute name="target"><xsl:value-of select="$uri"/></xsl:attribute>
879      </xsl:when>
880      <xsl:otherwise/>
881    </xsl:choose>
882    <xsl:apply-templates select="front" mode="cleanup"/>
883    <xsl:apply-templates select="seriesInfo" mode="cleanup"/>
884
885    <!-- Insert DOI for RFCs -->
886    <xsl:variable name="doi">
887      <xsl:call-template name="compute-doi"/>
888    </xsl:variable>
889    <xsl:if test="$xml2rfc-ext-insert-doi='yes' and $doi!='' and not(seriesInfo[@name='DOI'])">
890      <seriesInfo name="DOI" value="{$doi}"/>
891    </xsl:if>
892
893    <xsl:apply-templates select="*[not(self::front) and not(self::seriesInfo)]" mode="cleanup"/>
894  </reference>
895</xsl:template>
896<xsl:template match="seriesInfo" mode="cleanup">
897  <xsl:choose>
898    <xsl:when test="@name='Internet-Draft' and $rfcno > 7375">
899      <!-- special case in RFC formatting since 2015 -->
900      <seriesInfo name="Work in Progress," value="{@value}"/>
901    </xsl:when>
902    <xsl:otherwise>
903      <seriesInfo name="{@name}" value="{@value}"/>
904    </xsl:otherwise>
905  </xsl:choose>
906</xsl:template>
907
908<!-- References titles -->
909<xsl:template match="references" mode="cleanup">
910  <references>
911    <xsl:copy-of select="@anchor|@toc"/>
912    <xsl:variable name="title">
913      <xsl:choose>
914        <xsl:when test="name">
915          <xsl:variable name="hold">
916            <xsl:apply-templates select="name/node()"/>
917          </xsl:variable>
918          <xsl:value-of select="normalize-space($hold)"/>
919        </xsl:when>
920        <xsl:otherwise>
921          <xsl:value-of select="@title"/>
922        </xsl:otherwise>
923      </xsl:choose>
924    </xsl:variable>
925    <xsl:if test="$title!=''">
926      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
927    </xsl:if>
928    <xsl:apply-templates mode="cleanup"/>
929  </references>
930</xsl:template>
931<xsl:template match="references/name" mode="cleanup"/>
932
933<!-- Section titles -->
934<xsl:template match="section" mode="cleanup">
935  <section>
936    <xsl:copy-of select="@anchor|@toc"/>
937    <xsl:attribute name="title">
938      <xsl:choose>
939        <xsl:when test="name">
940          <xsl:variable name="hold">
941            <xsl:apply-templates select="name/node()"/>
942          </xsl:variable>
943          <xsl:value-of select="normalize-space($hold)"/>
944        </xsl:when>
945        <xsl:otherwise>
946          <xsl:value-of select="@title"/>
947        </xsl:otherwise>
948      </xsl:choose>
949      <xsl:if test="@removeInRFC='yes'"> (to be removed in RFC before publication)</xsl:if>
950    </xsl:attribute>
951    <xsl:apply-templates mode="cleanup"/>
952  </section>
953  <xsl:if test="@numbered='no'">
954    <xsl:call-template name="warning">
955      <xsl:with-param name="msg">unnumbered sections not supported</xsl:with-param>
956    </xsl:call-template>
957  </xsl:if>
958</xsl:template>
959<xsl:template match="section/name" mode="cleanup"/>
960
961<!-- Definition Lists -->
962<xsl:template match="dl" mode="cleanup">
963  <xsl:choose>
964    <xsl:when test="parent::dd">
965      <xsl:call-template name="process-dl"/>
966    </xsl:when>
967    <xsl:otherwise>
968      <t>
969        <xsl:call-template name="process-dl"/>
970      </t>
971    </xsl:otherwise>
972  </xsl:choose>
973</xsl:template>
974
975<xsl:template name="process-dl">
976  <xsl:variable name="hang" select="@hanging"/>
977  <xsl:variable name="spac" select="@spacing"/>
978  <xsl:processing-instruction name="rfc">
979    <xsl:choose>
980      <xsl:when test="not($spac='compact')">subcompact='no'</xsl:when>
981      <xsl:otherwise>subcompact='yes'</xsl:otherwise>
982    </xsl:choose>
983  </xsl:processing-instruction>
984  <list style="hanging">
985    <xsl:for-each select="dt">
986      <xsl:variable name="txt">
987        <xsl:apply-templates select="." mode="cleanup"/>
988      </xsl:variable>
989      <!-- TODO: check for more block-level elements -->
990      <xsl:variable name="desc" select="following-sibling::dd[1]"/>
991      <xsl:variable name="block-level-children" select="$desc/t | $desc/dl | $desc/ol | $desc/ul"/>
992      <t hangText="{normalize-space($txt)}">
993        <xsl:copy-of select="@anchor"/>
994        <xsl:if test="$hang='false'">
995          <xsl:choose>
996            <xsl:when test="$block-level-children">
997              <vspace blankLines="1"/>
998            </xsl:when>
999            <xsl:otherwise>
1000              <vspace blankLines="0"/>
1001            </xsl:otherwise>
1002          </xsl:choose>
1003        </xsl:if>
1004        <xsl:apply-templates select="iref" mode="cleanup"/>
1005        <xsl:choose>
1006          <xsl:when test="$block-level-children">
1007            <xsl:for-each select="$block-level-children">
1008              <xsl:choose>
1009                <xsl:when test="self::t">
1010                  <xsl:apply-templates select="node()" mode="cleanup"/>
1011                </xsl:when>
1012                <xsl:otherwise>
1013                  <xsl:apply-templates select="." mode="cleanup"/>
1014                </xsl:otherwise>
1015              </xsl:choose>
1016              <xsl:if test="position()!=last()">
1017                <xsl:choose>
1018                  <xsl:when test="not($spac='compact')"><vspace blankLines="1"/></xsl:when>
1019                  <xsl:otherwise><vspace blankLines="0"/></xsl:otherwise>
1020                </xsl:choose>
1021              </xsl:if>
1022            </xsl:for-each>
1023          </xsl:when>
1024          <xsl:otherwise>
1025            <xsl:apply-templates select="$desc/node()" mode="cleanup"/>
1026          </xsl:otherwise>
1027        </xsl:choose>
1028      </t>
1029    </xsl:for-each>
1030  </list>
1031</xsl:template>
1032
1033<!-- List items -->
1034<xsl:template match="li" mode="cleanup">
1035  <t>
1036    <xsl:copy-of select="@anchor"/>
1037    <xsl:apply-templates mode="cleanup"/>
1038  </t>
1039</xsl:template>
1040<xsl:template match="li/t" mode="cleanup">
1041  <xsl:apply-templates mode="cleanup"/>
1042  <xsl:if test="position()!=last()">
1043    <vspace blankLines="1"/>
1044  </xsl:if>
1045</xsl:template>
1046<xsl:template match="li/ul" mode="cleanup">
1047  <list style="symbols">
1048    <xsl:apply-templates mode="cleanup"/>
1049  </list>
1050  <xsl:if test="position()!=last()">
1051    <vspace blankLines="1"/>
1052  </xsl:if>
1053</xsl:template>
1054<xsl:template match="li/ol" mode="cleanup">
1055  <list style="numbers">
1056    <xsl:apply-templates mode="cleanup"/>
1057  </list>
1058  <xsl:if test="position()!=last()">
1059    <vspace blankLines="1"/>
1060  </xsl:if>
1061</xsl:template>
1062
1063<!-- Ordered Lists -->
1064<xsl:template match="ol" mode="cleanup">
1065  <t>
1066    <xsl:if test="@start and @start!='1'">
1067      <xsl:call-template name="warning">
1068        <xsl:with-param name="msg">list start != 1 not supported</xsl:with-param>
1069      </xsl:call-template>
1070    </xsl:if>
1071    <list style="numbers">
1072      <xsl:apply-templates mode="cleanup"/>
1073    </list>
1074  </t>
1075</xsl:template>
1076
1077<!-- Unordered Lists -->
1078<xsl:template match="ul" mode="cleanup">
1079  <t>
1080    <xsl:choose>
1081      <xsl:when test="@empty='true'">
1082        <list style="empty">
1083          <xsl:apply-templates mode="cleanup"/>
1084        </list>
1085      </xsl:when>
1086      <xsl:otherwise>
1087        <list style="symbols">
1088          <xsl:apply-templates mode="cleanup"/>
1089        </list>
1090      </xsl:otherwise>
1091    </xsl:choose>
1092  </t>
1093</xsl:template>
1094
1095<!-- Source Code -->
1096<xsl:template match="sourcecode" mode="cleanup">
1097  <xsl:choose>
1098    <xsl:when test="parent::figure">
1099      <artwork>
1100        <xsl:copy-of select="@anchor|@type"/>
1101        <xsl:apply-templates mode="cleanup"/>
1102      </artwork>
1103    </xsl:when>
1104    <xsl:otherwise>
1105      <figure>
1106        <artwork>
1107          <xsl:copy-of select="@anchor|@type"/>
1108          <xsl:apply-templates mode="cleanup"/>
1109        </artwork>
1110      </figure>
1111    </xsl:otherwise>
1112  </xsl:choose>
1113</xsl:template>
1114
1115<!-- date formats -->
1116<xsl:template match="/rfc/front/date/@month" mode="cleanup">
1117  <xsl:attribute name="month">
1118    <xsl:choose>
1119      <xsl:when test="string(number(.))!='NaN' and number(.)&gt;0 and number(.)&lt;13">
1120        <xsl:call-template name="get-month-as-name">
1121          <xsl:with-param name="month" select="."/>
1122        </xsl:call-template>
1123      </xsl:when>
1124      <xsl:otherwise>
1125        <xsl:value-of select="."/>
1126      </xsl:otherwise>
1127    </xsl:choose>
1128  </xsl:attribute>
1129</xsl:template>
1130
1131<!-- x:include -->
1132<xsl:template match="/rfc/back/references/xi:include" mode="cleanup">
1133  <xsl:copy-of select="document(@href)"/>
1134</xsl:template>
1135
1136<!-- Display names for references -->
1137<xsl:template match="displayreference" mode="cleanup"/>
1138<xsl:template match="reference/@anchor[.=/rfc/back/displayreference/@target]" mode="cleanup">
1139  <xsl:attribute name="anchor">
1140    <xsl:call-template name="generate-ref-name"/>
1141  </xsl:attribute>
1142</xsl:template>
1143<xsl:template match="xref/@target[.=/rfc/back/displayreference/@target]" mode="cleanup">
1144  <xsl:attribute name="target">
1145    <xsl:call-template name="generate-ref-name"/>
1146  </xsl:attribute>
1147</xsl:template>
1148
1149<xsl:template name="generate-ref-name">
1150  <xsl:variable name="tnewname">
1151    <xsl:value-of select="/rfc/back/displayreference[@target=current()]/@to"/>
1152  </xsl:variable>
1153  <xsl:choose>
1154    <xsl:when test="translate(substring($tnewname,1,1),$digits,'')=''">
1155      <xsl:value-of select="concat('_',$tnewname)"/>
1156      <xsl:call-template name="warning">
1157        <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>
1158      </xsl:call-template>
1159    </xsl:when>
1160    <xsl:otherwise>
1161      <xsl:value-of select="$tnewname"/>
1162    </xsl:otherwise>
1163  </xsl:choose>
1164</xsl:template>
1165
1166</xsl:transform>
Note: See TracBrowser for help on using the repository browser.