Changeset 2761


Ignore:
Timestamp:
13/06/21 03:13:24 (12 months ago)
Author:
julian.reschke@…
Message:

update XSLTs

Location:
rfc2629xslt
Files:
64 edited

Legend:

Unmodified
Added
Removed
  • rfc2629xslt/check-references.xslt

    r2750 r2761  
    208208  <xsl:variable name="base" select="substring($name,1,string-length($name)-3)"/>
    209209  <xsl:variable name="number" select="substring($name,string-length($name)-1)"/>
    210   <xsl:variable name="stat" select="document(concat('http://tools.ietf.org/draft/',$base,'/state.xml'))" />
     210  <xsl:variable name="stat" select="document(concat('https://tools.ietf.org/draft/',$base,'/state.xml'))" />
    211211 
    212212  <!--stat: <xsl:value-of select="$stat/ietfdoc/info/rev"/>
  • rfc2629xslt/clean-for-DTD.xslt

    r2750 r2761  
    11<!--
    2     Strip rfc2629.xslt extensions, generating XML input for MTR's xml2rfc
    3 
    4     Copyright (c) 2006-2016, Julian Reschke (julian.reschke@greenbytes.de)
     2    Strip rfc2629.xslt extensions, generating XML input for "official" xml2rfc
     3
     4    Copyright (c) 2006-2021, Julian Reschke (julian.reschke@greenbytes.de)
    55    All rights reserved.
    66
     
    3232<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    3333                version="1.0"
     34                xmlns:exslt="http://exslt.org/common"
    3435                xmlns:ed="http://greenbytes.de/2002/rfcedit"
    3536                xmlns:grddl="http://www.w3.org/2003/g/data-view#"
     
    3940                xmlns:xi="http://www.w3.org/2001/XInclude"
    4041                xmlns:xhtml="http://www.w3.org/1999/xhtml"
    41                 exclude-result-prefixes="ed grddl rdf svg x xi xhtml"
     42                exclude-result-prefixes="ed exslt grddl rdf svg x xi xhtml"
    4243>
    4344
    4445<!-- re-use some of the default RFC2629.xslt rules -->
    45 <xsl:import href="rfc2629.xslt"/>
     46<xsl:import href="rfc2629-no-doctype.xslt"/>
    4647
    4748<!-- undo strip-space decls -->
    4849<xsl:preserve-space elements="*"/>
    4950
    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" />
     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" />
    5253
    5354<!-- Workaround for http://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/297 -->
    5455<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>
    5573
    5674<!-- kick into cleanup mode -->
     
    5977  <xsl:comment>
    6078    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.
     79    extensions to RFC 7749 from documents for processing with xml2rfc.
    6280</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>
    6385  <xsl:apply-templates select="/" mode="cleanup"/>
    6486</xsl:template>
     
    80102
    81103<xsl:template match="*" mode="cleanup">
    82   <xsl:element name="{local-name()}">
     104  <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
    83105        <xsl:apply-templates select="node()|@*" mode="cleanup" />
    84106  </xsl:element>
     
    91113<xsl:template match="processing-instruction('BEGININC')" mode="cleanup"/>
    92114<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
    93140
    94141<!-- add issues appendix -->
     
    115162
    116163
    117 
     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>
    118219
    119220<!-- extensions -->
     
    123224    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
    124225      <xsl:call-template name="error">
     226        <xsl:with-param name="inline">no</xsl:with-param>
    125227        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
    126228      </xsl:call-template>
     
    138240
    139241<xsl:template match="x:bcp14|bcp14" mode="cleanup">
    140   <xsl:apply-templates/>
     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>
    141252</xsl:template>
    142253
     
    145256<xsl:template match="x:source" mode="cleanup"/>
    146257<xsl:template match="x:feedback" mode="cleanup"/>
     258<xsl:template match="date/@x:include-day" mode="cleanup"/>
    147259
    148260<xsl:template match="x:parse-xml" mode="cleanup">
     
    163275</xsl:template>
    164276
     277<xsl:template match="t/@keepWithNext|t/@keepWithPrevious" mode="cleanup"/>
     278
    165279<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}"/>
     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>
    176299    </xsl:otherwise>
    177300  </xsl:choose>
     
    179302
    180303<xsl:template match="postalLine" mode="cleanup">
    181   <xsl:comment>converted from v3 &lt;postalLine&gt;</xsl:comment>
    182   <street><xsl:value-of select="."/></street>
     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>
    183315</xsl:template>
    184316
     
    212344      </xsl:for-each>
    213345    </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>
    214376    <xsl:otherwise>
    215377      <xsl:call-template name="warning">
     
    222384
    223385<xsl:template match="x:blockquote|blockquote" mode="cleanup">
    224   <t><list>
    225     <xsl:apply-templates mode="cleanup" />
    226   </list></t>
     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>
    227447</xsl:template>
    228448
    229449<xsl:template match="x:h" mode="cleanup">
    230   <xsl:apply-templates 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>
    231460</xsl:template>
    232461
     
    248477
    249478<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">
    250492  <t>
    251493    <xsl:apply-templates select="@anchor" mode="cleanup"/>
     
    268510    <xsl:processing-instruction name="rfc">needLines="4"</xsl:processing-instruction>
    269511  </xsl:if>-->
    270   <xsl:apply-templates mode="cleanup"/>
     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>
    271523</xsl:template>
    272524
    273525<xsl:template match="x:sup|sup" mode="cleanup">
    274   <xsl:text>^</xsl:text>
    275   <xsl:apply-templates 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>
    276538</xsl:template>
    277539
    278540<xsl:template match="sub" mode="cleanup">
    279   <xsl:text>_</xsl:text>
    280   <xsl:apply-templates 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>
    281553</xsl:template>
    282554
     
    285557</xsl:template>
    286558<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>
    287599
    288600<xsl:template match="author/@anchor" mode="cleanup"/>
     
    296608</xsl:template>
    297609
    298 <xsl:template match="xref[(@x:fmt or @x:sec or @x:rel or @section or @sectionFormat or @relative) and not(node())]" mode="cleanup">
     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">
    299715  <xsl:call-template name="insert-iref-for-xref"/>
     716  <xsl:variable name="is-xref" select="self::xref"/>
    300717  <xsl:variable name="node" select="$src//*[@anchor=current()/@target]" />
     718  <xsl:variable name="rel" select="@x:rel|@relative"/>
    301719
    302720  <xsl:variable name="ssec">
     
    304722  </xsl:variable>
    305723
    306   <xsl:variable name="sec">
     724  <xsl:variable name="tsec">
    307725    <xsl:choose>
    308       <xsl:when test="starts-with(@x:rel,'#') and $ssec='' and $node/x:source/@href">
     726      <xsl:when test="starts-with($rel,'#') and $ssec='' and $node/x:source/@href">
    309727        <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>
     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>
    313758      </xsl:when>
    314759      <xsl:otherwise>
     
    317762    </xsl:choose>
    318763  </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>
    319771
    320772  <xsl:variable name="secterm">
    321773    <xsl:choose>
    322       <!-- starts with letter? -->
    323       <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">Appendix</xsl:when>
     774      <!-- starts with letter or unnumbered? -->
     775      <xsl:when test="translate(substring($sec,1,1),$ucase,'')='' or starts-with($tsec,'A@')">Appendix</xsl:when>
    324776      <xsl:otherwise>Section</xsl:otherwise>
    325777    </xsl:choose>
     
    330782      <xsl:with-param name="default">
    331783        <xsl:choose>
    332           <xsl:when test="ancestor::artwork">comma</xsl:when>
     784          <xsl:when test="ancestor::artwork or ancestor::sourcecode">comma</xsl:when>
    333785          <xsl:otherwise>of</xsl:otherwise>
    334786        </xsl:choose>
     
    337789  </xsl:variable>
    338790 
    339   <xsl:choose>
     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>
    340814    <xsl:when test="$sfmt='comma'">
    341815      <xref>
     
    352826      <xsl:value-of select="$sec"/>
    353827    </xsl:when>
    354     <xsl:when test="$sfmt='number-only'">
     828    <xsl:when test="$sfmt='bare'">
    355829      <xsl:value-of select="$sec"/>
    356830    </xsl:when>
     
    382856</xsl:template>
    383857
    384 <xsl:template match="xref[(@x:fmt or @x:sec or @x:rel) and node()]" mode="cleanup">
     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">
    385862  <xsl:call-template name="insert-iref-for-xref"/>
    386863  <xsl:choose>
     864    <xsl:when test="self::relref">
     865      <xsl:apply-templates mode="cleanup"/>
     866    </xsl:when>
    387867    <xsl:when test="@x:fmt='none'">
    388868      <xsl:apply-templates mode="cleanup"/>
     
    400880</xsl:template>
    401881
    402 <xsl:template match="xref[node() and (@target=//preamble/@anchor or @target=//spanx/@anchor)]" mode="cleanup">
     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">
    403883  <!-- remove the link -->
    404884  <xsl:apply-templates select="node()" mode="cleanup"/>
    405885</xsl:template>
    406886
    407 <xsl:template match="xref[node() and @format='none' and @target=//artwork//@anchor]" mode="cleanup">
    408   <!-- remove the link -->
     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> -->
    409889  <xsl:apply-templates select="node()" mode="cleanup"/>
    410890</xsl:template>
    411891
    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>
     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>
    415908</xsl:template>
    416909
     
    419912  <xref>
    420913    <xsl:apply-templates select="@target|@format" mode="cleanup"/>
    421     <xsl:apply-templates 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>
    422926  </xref>
    423927</xsl:template>
     
    440944  </xsl:if>
    441945</xsl:template>
     946
     947
     948<!-- workaround for https://tools.ietf.org/tools/ietfdb/ticket/2900 -->
     949<xsl:template match="iref/comment()" mode="cleanup"/>
    442950
    443951<!-- drop index gen extension -->
     
    6451153<!-- markup inside artwork element -->
    6461154
    647 <xsl:template match="figure[.//artwork//iref | .//artwork//xref]" mode="cleanup">
     1155<xsl:template match="figure" mode="cleanup">
    6481156  <!-- move up iref elements -->
    6491157  <xsl:for-each select=".//artwork//xref">
     
    6531161  </xsl:for-each>
    6541162  <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"/>
     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>
    9121168    <xsl:variable name="title">
    9131169      <xsl:choose>
     
    9261182      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
    9271183    </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">
     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">
    9381801      <xsl:choose>
    9391802        <xsl:when test="name">
     
    9471810        </xsl:otherwise>
    9481811      </xsl:choose>
    949       <xsl:if test="@removeInRFC='yes'"> (to be removed in RFC before publication)</xsl:if>
    950     </xsl:attribute>
     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>
    9511922    <xsl:apply-templates mode="cleanup"/>
    9521923  </section>
    953   <xsl:if test="@numbered='no'">
     1924  <xsl:if test="(@numbered='no' or @numbered='false') and $xml2rfc-ext-xml2rfc-backend &lt; 201610">
    9541925    <xsl:call-template name="warning">
    9551926      <xsl:with-param name="msg">unnumbered sections not supported</xsl:with-param>
     
    9621933<xsl:template match="dl" mode="cleanup">
    9631934  <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>
    9641948    <xsl:when test="parent::dd">
    9651949      <xsl:call-template name="process-dl"/>
     
    9741958
    9751959<xsl:template name="process-dl">
    976   <xsl:variable name="hang" select="@hanging"/>
     1960  <xsl:copy-of select="@anchor"/>
     1961  <xsl:variable name="newl" select="@newline"/>
    9771962  <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>
     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>
    9841972  <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>
    9851977    <xsl:for-each select="dt">
    9861978      <xsl:variable name="txt">
     
    9891981      <!-- TODO: check for more block-level elements -->
    9901982      <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"/>
     1983      <xsl:variable name="block-level-children" select="$desc/artwork | $desc/dl | $desc/figure | $desc/ol | $desc/sourcecode | $desc/t | $desc/table | $desc/ul"/>
    9921984      <t hangText="{normalize-space($txt)}">
    993         <xsl:copy-of select="@anchor"/>
    994         <xsl:if test="$hang='false'">
     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'">
    9951994          <xsl:choose>
    9961995            <xsl:when test="$block-level-children">
     
    10312030</xsl:template>
    10322031
     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
    10332046<!-- List items -->
    10342047<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">
    10352061  <t>
    10362062    <xsl:copy-of select="@anchor"/>
     
    10382064  </t>
    10392065</xsl:template>
     2066
    10402067<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">
    10412081  <xsl:apply-templates mode="cleanup"/>
    10422082  <xsl:if test="position()!=last()">
     
    10442084  </xsl:if>
    10452085</xsl:template>
     2086
    10462087<xsl:template match="li/ul" mode="cleanup">
    1047   <list style="symbols">
     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}">
    10482108    <xsl:apply-templates mode="cleanup"/>
    10492109  </list>
     
    10522112  </xsl:if>
    10532113</xsl:template>
    1054 <xsl:template match="li/ol" mode="cleanup">
    1055   <list style="numbers">
     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>
    10562176    <xsl:apply-templates mode="cleanup"/>
    10572177  </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>
    10752178</xsl:template>
    10762179
    10772180<!-- Unordered Lists -->
    10782181<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>
     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>
    10932278</xsl:template>
    10942279
     
    10962281<xsl:template match="sourcecode" mode="cleanup">
    10972282  <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>
    10982290    <xsl:when test="parent::figure">
    1099       <artwork>
    1100         <xsl:copy-of select="@anchor|@type"/>
     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}">
    11012364        <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>
     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>
    11132401</xsl:template>
    11142402
     
    11292417</xsl:template>
    11302418
     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
    11312448<!-- x:include -->
    1132 <xsl:template match="/rfc/back/references/xi:include" mode="cleanup">
    1133   <xsl:copy-of select="document(@href)"/>
     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"/>
    11342451</xsl:template>
    11352452
    11362453<!-- Display names for references -->
    1137 <xsl:template match="displayreference" mode="cleanup"/>
     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
    11382462<xsl:template match="reference/@anchor[.=/rfc/back/displayreference/@target]" mode="cleanup">
    11392463  <xsl:attribute name="anchor">
    1140     <xsl:call-template name="generate-ref-name"/>
     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>
    11412472  </xsl:attribute>
    11422473</xsl:template>
    11432474<xsl:template match="xref/@target[.=/rfc/back/displayreference/@target]" mode="cleanup">
    11442475  <xsl:attribute name="target">
    1145     <xsl:call-template name="generate-ref-name"/>
     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>
    11462484  </xsl:attribute>
    11472485</xsl:template>
     
    11522490  </xsl:variable>
    11532491  <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>
    11542498    <xsl:when test="translate(substring($tnewname,1,1),$digits,'')=''">
    11552499      <xsl:value-of select="concat('_',$tnewname)"/>
     
    11642508</xsl:template>
    11652509
     2510<!-- removal of xml2rfc preptool artefacts -->
     2511<xsl:template match="/rfc/@prepTime" mode="cleanup"/>
     2512<xsl:template match="/rfc/front/toc" mode="cleanup"/>
     2513
    11662514</xsl:transform>
  • rfc2629xslt/extract-artwork.xslt

    r741 r2761  
    11<!--
    2     Extract named artwork elements.
     2    Extract named artwork or sourcecode elements.
    33
    4     Copyright (c) 2006-2009, Julian Reschke (julian.reschke@greenbytes.de)
     4    Copyright (c) 2006-2018, Julian Reschke (julian.reschke@greenbytes.de)
    55    All rights reserved.
    66
     
    4747  <xsl:choose>
    4848    <xsl:when test="$name!=''">
    49       <xsl:variable name="artwork" select="//artwork[@name=$name]"/>
     49      <xsl:variable name="artwork" select="//artwork[@name=$name]|//sourcecode[@name=$name]"/>
    5050     
    5151      <xsl:choose>
     
    6262    </xsl:when>
    6363    <xsl:when test="$type!=''">
    64       <xsl:variable name="artwork" select="//artwork[@type=$type]"/>
     64      <xsl:variable name="artwork" select="//artwork[@type=$type]|//sourcecode[@type=$type]"/>
    6565     
    6666      <xsl:choose>
  • rfc2629xslt/gen-reference-graph.xslt

    r2218 r2761  
    44    "tr.rdf", available from <http://www.w3.org/2002/01/tr-automation/tr.rdf>)
    55
    6     Copyright (c) 2006-2013, Julian Reschke (julian.reschke@greenbytes.de)
     6    Copyright (c) 2006-2017, Julian Reschke (julian.reschke@greenbytes.de)
    77    All rights reserved.
    88
     
    144144      </xsl:when>
    145145      <xsl:when test="$node/rfced:current-status='INFORMATIONAL'">
    146         <xsl:text>[style = filled, fillcolor = blue]</xsl:text>
     146        <xsl:text>[style = filled, fillcolor = lightblue]</xsl:text>
    147147      </xsl:when>
    148148      <xsl:when test="$node/rfced:current-status='EXPERIMENTAL'">
    149         <xsl:text>[style = filled, fillcolor = cyan]</xsl:text>
     149        <xsl:text>[style = filled, fillcolor = lightcyan]</xsl:text>
    150150      </xsl:when>
    151151      <xsl:when test="$node/rfced:current-status='PROPOSED STANDARD'">
    152         <xsl:text>[style = "filled,rounded", fillcolor = yellow, shape=box]</xsl:text>
     152        <xsl:text>[style = "filled,rounded", fillcolor = lightyellow, shape=box]</xsl:text>
    153153      </xsl:when>
    154154      <xsl:when test="$node/rfced:current-status='DRAFT STANDARD'">
    155155        <xsl:text>[style = "filled,rounded", fillcolor = orange, shape=box]</xsl:text>
    156156      </xsl:when>
    157       <xsl:when test="$node/rfced:current-status='STANDARD'">
    158         <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
     157      <xsl:when test="$node/rfced:current-status='STANDARD' or $node/rfced:current-status='INTERNET STANDARD'">
     158        <xsl:text>[style = "filled,rounded", fillcolor = palegreen1, shape=box]</xsl:text>
    159159      </xsl:when>
    160160      <xsl:otherwise></xsl:otherwise>
  • rfc2629xslt/rfc2629-ext.rnc

    r2754 r2761  
    2121include "rfc2629.rnc" {
    2222 
     23  # Redefine <address> to allow multiple email addresses
     24  address =
     25    element address {
     26      attlist.address,
     27      postal?,
     28      phone?,
     29      facsimile?,
     30      email*,
     31      uri?
     32  }
     33
    2334  # Redefine <annotation> to allow more markup
    2435  annotation =
     
    3950    element artwork {
    4051      attlist.artwork,
     52      attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    4153      ( v3_svg |
    4254        (TEXT
     
    92104      (TEXT
    93105        | eref
    94         | xref)*
     106        | xref
     107        | x_ref)*
     108    }
     109
     110  # Redefine <date> to allow text content (see Section 11.26)
     111  date =
     112    element date {
     113      attlist.date,
     114      TEXT?
    95115    }
    96116
     
    98118  figure =
    99119    element figure {
    100       attlist.cref,
     120      attlist.figure,
     121      attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     122      v3_name?,
    101123      iref*,
    102124      preamble?,
    103       ( artwork | v3_sourcecode),
     125      (artwork
     126        | v3_sourcecode
     127        | v3_artset
     128      ),
    104129      postamble?
    105130    }
     
    110135      attlist.front,
    111136      title,
     137      seriesInfo*,
    112138      author+,
    113       date,
     139      date?,
    114140      area*,
    115141      workgroup*,
    116142      keyword*,
    117143      abstract?,
    118       v3_boilerplate?,
    119       note*
     144      note*,
     145      v3_boilerplate?
    120146    }
    121147 
     
    127153    }   
    128154   
     155  # Redefine <note> to allow <name> and not require title attribute
     156  note =
     157    element note {
     158      attlist.x_note,
     159      v3_name?,
     160      (v3_dl
     161        | v3_ol
     162        | t
     163        | v3_ul)+     
     164    }
     165
    129166  # Redefine <preamble> to allow our extension elements
    130167  preamble =
     
    144181  }
    145182
    146   # Redefine <postal> to allow <postalLine>
     183  # Redefine <postal> to allow <postalLine> and new detail elements
    147184  postal =
    148185    element postal {
     
    151188          | code
    152189          | country
     190          | v3_cityarea
     191          | v3_extaddr
     192          | v3_pobox
     193          | v3_sortingcode
    153194          | region
    154195          | street)*
     
    176217    element reference {
    177218      attlist.reference,
    178       front,
    179       seriesInfo*,
    180       x_prose?,
    181       v3_refcontent?,
    182       format*,
    183       annotation*,
    184       x_source?
    185     }
    186 
    187   # Redefine <references> to allow our <name>
     219      (
     220        (
     221          front,
     222          v3_refcontent?,
     223          seriesInfo*,
     224          x_prose?,
     225          v3_refcontent?,
     226          format*,
     227          annotation*,
     228          x_source?
     229        ) | (
     230          v3_refcontent?,
     231          seriesInfo*,
     232          x_prose?,
     233          v3_refcontent?,
     234          format*,
     235          annotation*,
     236          x_source
     237        )
     238      )
     239    }
     240
     241  # Redefine <references> to allow extension elements and attributes
    188242  references =
    189243    element references {
    190244      attribute title { text }?,
     245      attribute anchor { xsd:ID }?,
     246      attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    191247      v3_name?,
    192       (reference
    193        | xi_include)+
     248      (references+ # (see [V3IMPNOTES], Section 3.1.16)
     249       |
     250        (reference
     251         | v3_referencegroup
     252         | xi_include)+
     253       )
    194254    }
    195255
     
    197257  rfc =
    198258    element rfc {
    199       attlist.rfc,
     259      attribute xml:lang { text }?,
     260      attribute grddl:transformation { ATEXT }?,
     261      attribute x:maturity-level { "proposed" | "draft" | "internet" }?,
     262      attribute category { "std" | "bcp" | "info" | "exp" | "historic" }?,
     263      attribute consensus { "false" | "true" | "no" | "yes" }?,
     264      attribute docName { text }?,
     265      attribute indexInclude { "true" | "false" }?, # (see [RFC7991bis], Section 2.48.4)
     266      attribute ipr {
     267        "full2026"
     268        | "noDerivativeWorks2026"
     269        | "none"
     270        | "full3667"
     271        | "noModification3667"
     272        | "noDerivatives3667"
     273        | "full3978"
     274        | "noModification3978"
     275        | "noDerivatives3978"
     276        | "trust200811"
     277        | "noModificationTrust200811"
     278        | "noDerivativesTrust200811"
     279        | "trust200902"
     280        | "noModificationTrust200902"
     281        | "noDerivativesTrust200902"
     282        | "pre5378Trust200902"
     283      }?,
     284      attribute iprExtract { xsd:IDREF }?,
     285      attribute number { text }?,
     286      attribute obsoletes { text }?,
     287      attribute tocDepth { text }?, # (see [RFC7991bis], Section 2.48.14)
     288      attribute tocInclude { "true" | "false" }?, # (see [RFC7991bis], Section 2.48.15)
     289      attribute scripts { text }?, # (see [RFC7991bis], Appendix B.3)
     290      attribute seriesNo { text }?,
     291      attribute sortRefs { "true" | "false" }?, # (see [RFC7991bis], Section 2.48.11)
     292      attribute submissionType { "IETF" | "IAB" | "IRTF" | "independent" }?,
     293      attribute symRefs { "true" | "false" }?, # (see [RFC7991bis], Section 2.48.13)
     294      attribute updates { text }?,
     295      attribute version { text }?, # (see [RFC7991bis], Section 2.48.13)
     296      v3_link*,
    200297      x_link*,
    201298      x_feedback?,
     
    206303    }
    207304
    208   # Redefine <section> to allow our extension elements
     305  # Redefine <section> to allow new elements
    209306  section =
    210307    element section {
    211308      attlist.x_section,
    212309      (t
     310       | artwork
    213311       | figure
    214312       | texttable
    215313       | iref
    216314       | section
     315       | v3_artset
    217316       | v3_aside
    218317       | v3_blockquote
     318       | v3_contact
    219319       | v3_dl
    220320       | v3_name
    221321       | v3_ol
    222322       | v3_sourcecode
     323       | v3_table
    223324       | v3_ul
    224325       | x_anchor-alias
    225326       | x_blockquote
     327       | x_contributor
    226328       | x_include-author
    227329       | x_note
     330       | x_u-map
    228331       | rdf_Description)*
    229332    }
     
    253356       | vspace
    254357       | v3_bcp14
     358       | v3_br
     359       | v3_contact
    255360       | v3_em
     361       | v3_relref
    256362       | v3_strong
    257363       | v3_sub
    258364       | v3_sup
    259365       | v3_tt
     366       | v3_u
    260367       | x_abnf-char-sequence
    261368       | x_anchor-alias
     
    268375       | x_sup)*
    269376    }
     377
     378  # Redefine <title> to allow <br>
     379  title =
     380    element title {
     381      attlist.title,
     382      (TEXT
     383        | v3_br)*
     384    }
     385
     386  # Redefine <xref> to allow some markup
     387  xref =
     388    element xref {
     389      attlist.xref,
     390      (TEXT
     391        | v3_em
     392        | v3_strong
     393        | v3_sub
     394        | v3_sup
     395        | v3_tt)*
     396    }
    270397}
    271398
    272 # Allow extension attributes on <artwork> (Section 11.22)
     399# Extend attribute set for <abstract>
     400attlist.abstract &=
     401  attribute anchor { xsd:ID }?, # (see [RFC7991bis], Section 2.1.1)
     402  attribute pn { text }? # (see [RFC7991bis], Appendix B.2)
     403
     404# Allow extension attributes on <artwork> (Section 11.25)
    273405attlist.artwork &=
     406  attribute anchor { xsd:ID }?,
     407  attribute originalSrc { text }?, # (see [RFC7991bis], Appendix B.3)
    274408  attribute x:indent-with { ATEXT }?,
    275409  attribute x:lang { "" }?,
     
    278412# Allow anchor and x:annotation attributes on <author>
    279413attlist.author &=
     414  attribute asciiFullname { ATEXT }?,
     415  attribute asciiInitials { ATEXT }?,
     416  attribute asciiSurname { ATEXT }?,
    280417  attribute anchor { xsd:ID }?,
    281418  attribute x:annotation { ATEXT }?
    282419 
    283 # Extend attribute set for <c> (see Section 11.23)
     420# Extend attribute set for <c>
    284421attlist.c &=
    285422  attribute anchor { xsd:ID }?
    286423
    287 # Extend attribute set for <iref> (see Section 11.23)
     424# Extend attribute set for <city>
     425attlist.city &=
     426  attribute ascii { ATEXT }?
     427
     428# Extend attribute set for <code>
     429attlist.code &=
     430  attribute ascii { ATEXT }?
     431
     432# Extend attribute set for <country>
     433attlist.country &=
     434  attribute ascii { ATEXT }?
     435
     436# Extend attribute set for <cref> (see Section 2.17.2 of [RFC7991bis])
     437attlist.cref &=
     438  attribute display { "false" | "true" }?
     439
     440# Extend attribute set for <date> (see Section 11.26)
     441attlist.date &=
     442  attribute x:include-day { "false" | "true" }?
     443
     444# Extend attribute set for <eref> (see Section 11.27)
     445attlist.eref &=
     446  attribute brackets { "none" | "angle" }?
     447
     448# Extend attribute set for <iref> (see Section 11.28)
    288449attlist.iref &=
    289450  attribute x:for-anchor { ATEXT }?
    290451
    291 # Extend attribute set for <list> (see Section 11.24)
     452# Extend attribute set for <list> (see Section 11.29)
    292453attlist.list &=
    293454  attribute x:indent { ATEXT }?
     455
     456# Extend/Relax attribute set for <note>
     457attlist.x_note &=
     458  attribute anchor { xsd:ID }?,
     459  attribute title { ATEXT }?,
     460  attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     461  attribute removeInRFC { "false" | "true" }? # see Section 12.25.2
    294462
    295463# Extend attribute set for <preamble>
     
    297465  attribute anchor { xsd:ID }?
    298466
     467# Extend attribute set for <organization>
     468attlist.organization &=
     469  attribute ascii { ATEXT }?,
     470  attribute showOnFrontPage { "false" | "true" }?
     471
    299472# Extend attribute set for <reference>
    300473attlist.reference &=
    301   attribute quoteTitle { "false" | "true" }? # see Section 12.16.1
    302 
    303 # Extend attribute set for <rfc>
    304 attlist.rfc &=
    305   attribute grddl:transformation { ATEXT }?,
    306   attribute x:maturity-level { "proposed" | "draft" | "internet" }?
    307 
    308 # Extend/Relax attribute set for <section> (see Section 11.26)
     474  attribute quoteTitle { "false" | "true" }?, # (see Section 12.22.1)
     475  attribute xml:base { text }? # (see [RFC7991bis], Section 2)
     476
     477# Extend attribute set for <references>
     478attlist.references &=
     479  attribute pn { text }? # (see [RFC7991bis], Appendix B.2)
     480
     481# Extend attribute set for <region>
     482attlist.region &=
     483  attribute ascii { ATEXT }?
     484
     485# Extend/Relax attribute set for <section> (see Section 11.31)
    309486attlist.x_section &=
    310487  attribute anchor { xsd:ID }?,
    311488  attribute title { ATEXT }?,
    312489  attribute toc { "include" | "exclude" | "default" }?,
    313   attribute numbered { "false" | "true" }?, # see Section 12.17.1
    314   attribute removeInRFC { "false" | "true" }?, # see Section 12.17.2
     490  attribute numbered { "false" | "true" }?, # see Section 12.25.1
     491  attribute removeInRFC { "false" | "true" }?, # see Section 12.25.2
     492  attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    315493  attribute x:fixed-section-number { ATEXT }?
    316494
     
    319497  attribute anchor { xsd:ID }?
    320498
    321 # Allow x:quotes attribute on <title>
     499# Extend attribute set for <street>
     500attlist.street &=
     501  attribute ascii { ATEXT }?
     502
     503# Extend attribute set for <c> (see Section 11.28)
     504attlist.t &=
     505  attribute indent { text }?,
     506  attribute keepWithNext { text }?,
     507  attribute keepWithPrevious { text }?,
     508  attribute pn { text }? # (see [RFC7991bis], Appendix B.2)
     509
     510# Extend attribute set for <texttable>
     511attlist.texttable &=
     512  attribute x:caption-side { ATEXT }?
     513
     514# Extend attribute set for <title>
    322515attlist.title &=
    323   attribute x:quotes { "true" | "false" }?
     516  attribute ascii { ATEXT }?,
     517  attribute x:quotes { "true" | "false" }? # (deprecated, see Section 12.22.1)
    324518
    325519# Allow annotation attribute on <uri>
     
    327521  attribute x:annotation { ATEXT }?
    328522
    329 # Extend attribute set for <xref> (see Section 11.27)
     523# Extend attribute set for <xref> (see Section 11.32)
    330524attlist.xref &=
     525  attribute derivedContent { text }?, # (see [RFC7991bis], Appendix B.3)
    331526  attribute x:fmt  { "()" | "," | "of" | "number" | "sec" |
    332527                     "none" }?,
    333528  attribute x:rel  { ATEXT }?,
    334   attribute x:sec  { ATEXT }?
    335 
    336 # Side Note (see Section 12.1)
     529  attribute x:sec  { ATEXT }?,
     530  attribute relative  { ATEXT }?,
     531  attribute section  { ATEXT }?,
     532  attribute sectionFormat  { "bare" | "comma" | "of" | "parens" }?
     533 
     534
     535# Set of artwork (see Section 12.1)
     536v3_artset =
     537  element artset {
     538    attribute anchor { xsd:ID }?,
     539    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     540    artwork+
     541  }
     542
     543# Side Note (see Section 12.2)
    337544v3_aside =
    338545  element aside {
    339546    attribute anchor { xsd:ID }?,
    340     t+
    341   }
    342 
    343 # BCP14/RFC2119 keywords (see Section 12.2)
     547    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     548    (artwork
     549      | figure
     550      | iref
     551      | t
     552      | v3_blockquote
     553      | v3_dl
     554      | v3_ol
     555      | v3_table
     556      | v3_ul)*
     557  }
     558
     559# BCP14/RFC2119 keywords (see Section 12.3)
    344560v3_bcp14 =
    345561  element bcp14 {
    346     "MAY"
    347     | "MUST"
    348     | "MUST NOT"
    349     | "NOT RECOMMENDED"
    350     | "OPTIONAL"
    351     | "RECOMMENDED"
    352     | "REQUIRED"
    353     | "SHALL"
    354     | "SHALL NOT"
    355     | "SHOULD"
    356     | "SHOULD NOT"
    357   }
    358 
    359 # Blockquote (see Section 12.3)
     562    TEXT
     563  }
     564
     565# Blockquote (see Section 12.4)
    360566v3_blockquote =
    361567  element blockquote {
    362568    attribute anchor { xsd:ID }?,
    363569    attribute cite { URI }?,
    364     t+
    365   }
    366 
    367 # Boilerplate (see Section 12.3)
     570    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     571    attribute quotedFrom { ATEXT }?,
     572    (
     573      (artwork
     574        | v3_dl
     575        | figure
     576        | v3_ol
     577        | v3_sourcecode
     578        | t
     579        | v3_ul)+
     580    |
     581      (TEXT
     582        | v3_bcp14
     583        | cref
     584        | v3_em
     585        | eref
     586        | iref
     587        | v3_strong
     588        | v3_sub
     589        | v3_sup
     590        | v3_tt
     591        | xref)+
     592    )
     593  }
     594
     595# Boilerplate (see Section 12.4)
    368596v3_boilerplate =
    369597  element boilerplate {
     598    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    370599    section+
    371600  }
    372601
    373 # Mapping of reference names to display names (see Section 12.5)
     602# Forced Line Break (see Section 12.6)
     603v3_br =
     604  element br {
     605    empty
     606  }
     607
     608# (see Section 12.7)
     609v3_cityarea =
     610  element cityarea {
     611    attribute ascii { ATEXT }?,
     612    TEXT
     613  }
     614
     615# (see Section 12.8)
     616v3_contact =
     617  element contact {
     618    attribute initials { text }?,
     619    attribute asciiInitials { text }?,
     620    attribute surname { text }?,
     621    attribute asciiSurname { text }?,
     622    attribute fullname { text }?,
     623    attribute asciiFullname { text }?,
     624    organization?,
     625    address?
     626  }
     627
     628# Mapping of reference names to display names (see Section 12.9)
    374629v3_displayreference =
    375630  element displayreference {
     
    378633  }
    379634
    380 # Definition List Description Element (see Section 12.6)
     635# Definition List Description Element (see Section 12.10)
    381636v3_dd =
    382637  element dd {
    383     (t
    384       | v3_dl)+ |
     638    attribute anchor { xsd:ID }?,
     639    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     640    ((v3_artset
     641      | artwork
     642      | figure
     643      | t
     644      | v3_aside
     645      | v3_dl
     646      | v3_ol
     647      | v3_table
     648      | v3_sourcecode
     649      | v3_ul)+ |
     650    (TEXT
     651      | cref
     652      | eref
     653      | iref
     654      | xref
     655      | v3_bcp14
     656      | v3_br
     657      | v3_em
     658      | v3_sub
     659      | v3_sup
     660      | v3_tt
     661      | v3_strong
     662      | v3_u
     663      | x_ref)*
     664    )
     665  }
     666
     667# Definition List (see Section 12.11)
     668v3_dl =
     669  element dl {
     670    attribute anchor { xsd:ID }?, # (see [RFC7991bis], Section 2.21.1)
     671    attribute indent { text }?,
     672    attribute newline { "false" | "true" }?,
     673    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     674    attribute spacing { "normal" | "compact" }?,
     675    (v3_dt, v3_dd)+
     676  }
     677
     678# Definition List Description Term (see Section 12.12)
     679v3_dt =
     680  element dt {
     681    attribute anchor { xsd:ID }?,
     682    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    385683    (TEXT
    386684      | cref
     
    393691  }
    394692
    395 # Definition List (see Section 12.7)
    396 v3_dl =
    397   element dl {
    398        attribute spacing { "normal" | "compact" }?,
    399        attribute hanging { "false" | "true" }?,
    400        (v3_dt, v3_dd)+
    401   }
    402 
    403 # Definition List Description Term (see Section 12.8)
    404 v3_dt =
    405   element dt {
    406     attribute anchor { xsd:ID }?,
     693# Emphasized Text (see Section 12.13)
     694v3_em =
     695  element em {
     696    attribute anchor { xsd:ID }?,
     697    (TEXT
     698      | eref
     699      | iref
     700      | xref
     701      | v3_strong
     702      | x_ref)*
     703  }
     704
     705# Extended Postal Address (see Section 12.14)
     706v3_extaddr =
     707  element extaddr {
     708    attribute ascii { ATEXT }?,
     709    TEXT
     710  }
     711
     712# Definition List (see Section 12.15)
     713v3_li =
     714  element li {
     715    attribute anchor { xsd:ID }?,
     716    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     717    ((v3_artset
     718      | artwork
     719      | figure
     720      | v3_blockquote
     721      | v3_dl
     722      | v3_ol
     723      | t
     724      | v3_table
     725      | v3_sourcecode
     726      | v3_ul
     727    )+
     728      |
    407729    (TEXT
    408730      | cref
     
    410732      | iref
    411733      | xref
    412       | v3_em
    413       | v3_tt
    414       | v3_strong)*
    415   }
    416 
    417 # Emphasized Text (see Section 12.9)
    418 v3_em =
    419   element em {
    420     (TEXT
    421       | xref
    422       | v3_strong
    423       | x_ref)*
    424   }
    425 
    426 # Definition List (see Section 12.10)
    427 v3_li =
    428   element li {
    429     attribute anchor { xsd:ID }?,
    430     ((v3_dl | v3_ol  | t | v3_ul )+
    431       |
    432     (TEXT
    433       | cref
    434       | eref
    435       | iref
    436       | xref
     734      | v3_bcp14
    437735      | v3_em
    438736      | v3_strong
     
    440738      | v3_sup
    441739      | v3_tt
     740      | v3_u
     741      | x_dfn
    442742      | x_ref)*
    443743    )
    444744  }
    445745
    446 # Section/Figure/Table Name (see Section 12.11)
     746# Container for additional links (see Section 12.16)
     747v3_link =
     748  element link {
     749    attribute href { text },
     750    attribute rel { text }?
     751  }
     752
     753# Section/Figure/Table Name (see Section 12.17)
    447754v3_name =
    448755  element name {
    449     (TEXT
     756    attribute slugifiedName { text }?, # (see [RFC7991bis], Appendix B.2)
     757    (TEXT
     758      | cref
     759      | v3_br
     760      | v3_em
     761      | v3_sup
    450762      | v3_tt
    451763      | xref)*
    452764  }
    453765
    454 # Ordered List (see Section 12.12)
     766# Ordered List (see Section 12.18)
    455767v3_ol =
    456768  element ol {
    457769    attribute anchor { xsd:ID }?,
     770    attribute indent { text }?,
     771    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    458772    attribute start { TEXT }?,
     773    attribute group { TEXT }?,
     774    attribute type { TEXT }?,
    459775    v3_li+
    460776  }
    461777
    462 # Line in postal address (see Section 12.13)
     778# Extended Postal Address (see Section 12.19)
     779v3_pobox =
     780  element pobox {
     781    attribute ascii { ATEXT }?,
     782    TEXT
     783  }
     784
     785# Line in postal address (see Section 12.20)
    463786v3_postalLine =
    464787  element postalLine {
    465     TEXT
    466   }
    467 
    468 # additional content for references (see Section 12.14)
     788    attribute ascii { TEXT }?,
     789    TEXT
     790  }
     791
     792# EXPERIMENTAL DO NOT USE YET (see Section 12.24)
     793v3_relref =
     794  element relref {
     795    attribute derivedLink { text }?, # (see [RFC7991bis], Appendix B.3)
     796    attribute displayFormat { "of" | "comma" | "parens" | "bare" }?,
     797    attribute relative { text }?,
     798    attribute section { text },
     799    attribute target { xsd:IDREF },
     800    TEXT
     801  }
     802
     803# additional content for references (see Section 12.21)
    469804v3_refcontent =
    470805  element refcontent {
     
    473808  }
    474809
    475 # Source Code (see Section 12.15)
     810# reference group (see Section 12.23)
     811v3_referencegroup =
     812  element referencegroup {
     813    attribute anchor { xsd:ID },
     814    attribute target { URI }?,
     815    (reference
     816      | xi_include)+
     817  }
     818
     819# (see Section 12.26)
     820v3_sortingcode =
     821  element sortingcode {
     822    attribute ascii { ATEXT }?,
     823    TEXT
     824  }
     825
     826# Source Code (see Section 12.27)
    476827v3_sourcecode =
    477828  element sourcecode {
    478829    attribute anchor { xsd:ID }?,
     830    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     831    attribute markers { text }?, #(see [V3IMPNOTES], Section 3.1.22)
     832    attribute name { text }?,
     833    attribute type { text }?,
    479834    attribute x:lang { "" }?,
    480     TEXT
    481   }
    482 
    483 # Emphasized Text (see Section 12.18)
     835    (TEXT
     836      | iref
     837      | xref
     838      | x_ref)*
     839  }
     840
     841# Emphasized Text (see Section 12.28)
    484842v3_strong =
    485843  element strong {
     844    attribute anchor { xsd:ID }?,
    486845    (TEXT
    487846      | xref
     
    490849  }
    491850
    492 # Subscript (see Section 12.19)
     851# Subscript (see Section 12.29)
    493852v3_sub =
    494853  element sub {
    495     (TEXT)*
    496   }
    497 
    498 # Superscript (see Section 12.20)
     854    (TEXT
     855      | v3_sup)*
     856  }
     857
     858# Superscript (see Section 12.30)
    499859v3_sup =
    500860  element sup {
    501     (TEXT)*
    502   }
    503 
    504 # Monospaced Text (see Section 12.22)
     861    (TEXT
     862      | v3_sub)*
     863  }
     864
     865# Table (see Section 12.32)
     866v3_table =
     867  element table {
     868    attribute anchor { xsd:ID }?,
     869    attribute align { "left" | "center" | "right" }?,
     870    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     871    v3_name?,
     872    iref*,
     873    v3_thead?,
     874    v3_tbody+,
     875    v3_tfoot?
     876  }
     877
     878# Table Body (see Section 12.33)
     879v3_tbody =
     880  element tbody {
     881    attribute anchor { xsd:ID }?,
     882    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     883    v3_tr+
     884  }
     885
     886# Table Contents Cell (see Section 12.34)
     887v3_td =
     888  element td {
     889    attribute anchor { xsd:ID }?,
     890    attribute align { "left" | "center" | "right" }?,
     891    attribute colspan { text }?,
     892    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     893    attribute rowspan { text }?,
     894    ( (t
     895       | v3_dl
     896       | v3_ol
     897       | v3_sourcecode
     898       | v3_ul
     899      )+
     900      | (TEXT
     901         | v3_bcp14
     902         | v3_br
     903         | cref
     904         | v3_em
     905         | eref
     906         | v3_strong
     907         | v3_sub
     908         | v3_sup
     909         | v3_tt
     910         | xref)*
     911    )
     912  }
     913
     914# Table Footer (see Section 12.35)
     915v3_tfoot =
     916  element tfoot {
     917    attribute anchor { xsd:ID }?,
     918    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     919    v3_tr
     920  }
     921
     922# Table Header Cell (see Section 12.36)
     923v3_th =
     924  element th {
     925    attribute anchor { xsd:ID }?,
     926    attribute align { "left" | "center" | "right" }?,
     927    attribute colspan { text }?,
     928    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     929    attribute rowspan { text }?,
     930    ( (t
     931       | v3_dl
     932       | v3_ol
     933       | v3_sourcecode
     934       | v3_ul
     935      )+
     936      | (TEXT
     937         | v3_bcp14
     938         | cref
     939         | v3_em
     940         | eref
     941         | v3_strong
     942         | v3_sub
     943         | v3_sup
     944         | v3_tt
     945         | xref)*
     946    )
     947  }
     948
     949# Table Head (see Section 12.37)
     950v3_thead =
     951  element thead {
     952    attribute anchor { xsd:ID }?,
     953    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     954    v3_tr+
     955  }
     956
     957# Table Row (see Section 12.38)
     958v3_tr =
     959  element tr {
     960    attribute anchor { xsd:ID }?,
     961    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
     962    (
     963      v3_td
     964      | v3_th
     965    )+
     966  }
     967
     968# Monospaced Text (see Section 12.39)
    505969v3_tt =
    506970  element tt {
     
    511975  }
    512976
    513 # Unordered List (see Section 12.23)
     977# Non-ASCII characters (see Section 12.40)
     978v3_u =
     979  element u {
     980    attribute ascii { text }?,
     981    attribute format { text }?,
     982    TEXT
     983  }
     984
     985# Unordered List (see Section 12.41)
    514986v3_ul =
    515987  element ul {
    516988    attribute anchor { xsd:ID }?,
    517     attribute empty { TEXT }?,
     989    attribute bare { "false" | "true" }?, # but see <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/547>
     990    attribute indent { text }?,
     991    attribute empty { "false" | "true" }?,
     992    attribute pn { text }?, # (see [RFC7991bis], Appendix B.2)
    518993    v3_li+
    519994  }
    520995
    521 # SVG (see Section 12.21)
     996# SVG (see Section 12.31)
    522997v3_svg =
    523998  element svg:svg {
     
    5471022  }
    5481023
    549 # Supply feedback links (see Section 11.9)
     1024# Contributor information (see Section 11.9)
     1025# (experimental)
     1026x_contributor =
     1027  element x:contributor {
     1028    attlist.author,
     1029    organization?,
     1030    address?
     1031  }
     1032
     1033# Supply feedback links (see Section 11.11)
    5501034x_feedback =
    5511035  element x:feedback {
     
    5701054  }
    5711055
    572 # Bottom line of box drawing (see Section 11.4)
     1056# Bottom line of box drawing (see Section 11.3)
    5731057x_bb =
    5741058  element x:bb {
     
    5821066  }
    5831067
    584 # Center line of box drawing (see Section 11.5)
     1068# Center line of box drawing (see Section 11.4)
    5851069x_bc =
    5861070  element x:bc {
     
    5951079  }
    5961080
    597 # BCP14/RFC2119 keywords (see Section 11.3)
     1081# BCP14/RFC2119 keywords (see Section 11.5)
    5981082x_bcp14 =
    5991083  element x:bcp14 {
    600     "MAY"
    601     | "MUST"
    602     | "MUST NOT"
    603     | "NOT RECOMMENDED"
    604     | "OPTIONAL"
    605     | "RECOMMENDED"
    606     | "REQUIRED"
    607     | "SHALL"
    608     | "SHALL NOT"
    609     | "SHOULD"
    610     | "SHOULD NOT"
     1084    TEXT
    6111085  }
    6121086 
     
    6311105  }
    6321106
    633 # Definition (see Section 11.8)
     1107# Unicode character map entry (see Section 11.8)
     1108x_c =
     1109  element x:c {
     1110    attribute c { TEXT },
     1111    attribute d { TEXT }?,
     1112    attribute n { TEXT }
     1113  }
     1114
     1115# declaration of definition in external reference
     1116x_defines =
     1117  element x:defines {
     1118    TEXT
     1119  }
     1120
     1121# Definition (see Section 11.10)
    6341122x_dfn =
    6351123  element x:dfn {
     
    6391127  }
    6401128 
    641 # Heading (see Section 11.10)
     1129# Heading (see Section 11.12)
    6421130x_h =
    6431131  element x:h {
     
    6451133  }
    6461134
    647 # Heading (see Section 11.11)
     1135# declaration of anchor in external reference
     1136x_has =
     1137  element x:has {
     1138    attribute anchor { xsd:ID }?
     1139  }
     1140
     1141# Heading (see Section 11.13)
    6481142x_highlight =
    6491143  element x:highlight {
     
    6511145  }
    6521146
    653 # Length Measurement (see Section 11.12)
     1147# Length Measurement (see Section 11.14)
    6541148x_length-of =
    6551149  element x:length-of {
     
    6591153  }
    6601154
    661 # Link (see Section 11.13)
     1155# Link (see Section 11.15)
    6621156x_link =
    6631157  element x:link {
     
    6691163  }
    6701164 
    671 # Extended list item (see Section 11.14)
     1165# Extended list item (see Section 11.16)
    6721166x_lt =
    6731167  element x:lt {
     
    6771171  }
    6781172
    679 # Note (see Section 11.15)
     1173# Note (see Section 11.17)
    6801174x_note =
    6811175  element x:note {
     
    6841178  }
    6851179
    686 # Signal XML content (see Section 11.16)
     1180# Signal XML content (see Section 11.18)
    6871181x_parse-xml =
    6881182  element x:parse-xml {
     
    6911185  }
    6921186
    693 # Inline prose in a reference (see Section 11.17)
     1187# Inline prose in a reference (see Section 11.19)
    6941188x_prose =
    6951189  element x:prose {
     
    6971191  }
    6981192
    699 # Inline quote (see Section 11.18)
     1193# Inline quote (see Section 11.20)
    7001194x_q =
    7011195  element x:q {
     
    7031197  }
    7041198
    705 # Anchor reference (see Section 11.19
     1199# Anchor reference (see Section 11.21
    7061200x_ref =
    7071201  element x:ref {
     
    7101204  }
    7111205
    712 # source information (see Section 11.20
     1206# source information (see Section 11.22
    7131207x_source =
    7141208  element x:source {
    7151209    attribute basename { ATEXT }?,
    7161210    attribute href { URI },
    717     empty
    718   }
    719 
    720 # superscript (see Section 11.21)
     1211    x_defines*,
     1212    x_has*
     1213  }
     1214
     1215# superscript (see Section 11.23)
    7211216x_sup =
    7221217  element x:sup {
     
    7311226    (TEXT
    7321227      | x_parse-xml)*
     1228  }
     1229
     1230# Unicode character map (see Section 11.24)
     1231x_u-map =
     1232  element x:u-map {
     1233    x_c*
    7331234  }
    7341235
     
    7391240  }
    7401241
    741 # XInclude
     1242# XInclude (see Section 12.43)
    7421243xi_include =
    7431244  element xi:include {
  • rfc2629xslt/rfc2629-xhtml.ent

    r6 r2761  
    163163<!ENTITY rang   "&#9002;"><!-- U+232A RIGHT-POINTING ANGLE BRACKET               (">")                -->
    164164
     165<!-- Typographic help characters -->
     166<!ENTITY zwsp   "&#8203;"><!-- U+232A RIGHT-POINTING ANGLE BRACKET        -->
     167<!ENTITY br     "&#8232;"><!-- U+2028 LINE SEPARATOR                      -->
     168<!ENTITY wj     "&#8288;"><!-- U+2060 WORD JOINER                         -->
    165169<!-- EOF -->
  • rfc2629xslt/rfc2629.xslt

    r2754 r2761  
    22    XSLT transformation from RFC2629 XML format to HTML
    33
    4     Copyright (c) 2006-2016, Julian Reschke (julian.reschke@greenbytes.de)
     4    Copyright (c) 2006-2021, Julian Reschke (julian.reschke@greenbytes.de)
    55    All rights reserved.
    66
     
    3636                xmlns:ed="http://greenbytes.de/2002/rfcedit"
    3737                xmlns:exslt="http://exslt.org/common"
     38                xmlns:fo="http://www.w3.org/1999/XSL/Format"
    3839                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    39                 xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rcf2629.xslt"
     40                xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rfc2629.xslt"
    4041                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    4142                xmlns:saxon="http://saxon.sf.net/"
     
    4647                xmlns:xhtml="http://www.w3.org/1999/xhtml"
    4748
    48                 exclude-result-prefixes="date ed exslt msxsl myns rdf saxon saxon-old svg x xi xhtml"
     49                exclude-result-prefixes="date ed exslt fo msxsl myns rdf saxon saxon-old svg x xi xhtml"
    4950                >
    5051
    51 <xsl:strip-space elements="abstract author back figure front list middle note postal reference references rfc section texttable"/>
     52<xsl:strip-space elements="abstract address artset aside author back boilerplate dl figure front list middle note ol postal reference references rfc section table tbody thead tr texttable ul svg:svg"/>
    5253
    5354<xsl:output method="html" encoding="utf-8" doctype-system="about:legacy-compat" indent="no"/>
    5455
    55 <!-- rfc comments PI -->
    56 
    57 <xsl:param name="xml2rfc-comments">
     56<!-- PIs outside the root element, or inside the root element but before <front> -->
     57<xsl:variable name="global-std-pis" select="/processing-instruction('rfc') | /*/processing-instruction('rfc')[following-sibling::front]"/>
     58
     59<!-- rfc authorship PI -->
     60
     61<xsl:param name="xml2rfc-authorship">
    5862  <xsl:call-template name="parse-pis">
    59     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
    60     <xsl:with-param name="attr" select="'comments'"/>
    61     <xsl:with-param name="default" select="'no'"/>
     63    <xsl:with-param name="nodes" select="$global-std-pis"/>
     64    <xsl:with-param name="attr" select="'authorship'"/>
     65    <xsl:with-param name="default" select="'yes'"/>
    6266  </xsl:call-template>
    6367</xsl:param>
    6468
     69<!-- rfc comments PI -->
     70
     71<xsl:param name="xml2rfc-comments">
     72  <xsl:variable name="default">
     73    <xsl:choose>
     74      <xsl:when test="/rfc/@version >= 3">yes</xsl:when>
     75      <xsl:otherwise>no</xsl:otherwise>
     76    </xsl:choose>
     77  </xsl:variable>
     78  <xsl:call-template name="parse-pis">
     79    <xsl:with-param name="nodes" select="$global-std-pis"/>
     80    <xsl:with-param name="attr" select="'comments'"/>
     81    <xsl:with-param name="default" select="$default"/>
     82  </xsl:call-template>
     83</xsl:param>
     84
    6585<!-- rfc compact PI -->
    6686
    6787<xsl:param name="xml2rfc-compact">
    6888  <xsl:call-template name="parse-pis">
    69     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     89    <xsl:with-param name="nodes" select="$global-std-pis"/>
    7090    <xsl:with-param name="attr" select="'compact'"/>
    7191    <xsl:with-param name="default" select="$xml2rfc-rfcedstyle"/>
     
    7797<xsl:param name="xml2rfc-footer">
    7898  <xsl:call-template name="parse-pis">
    79     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     99    <xsl:with-param name="nodes" select="$global-std-pis"/>
    80100    <xsl:with-param name="attr" select="'footer'"/>
    81101  </xsl:call-template>
     
    86106<xsl:param name="xml2rfc-header">
    87107  <xsl:call-template name="parse-pis">
    88     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     108    <xsl:with-param name="nodes" select="$global-std-pis"/>
    89109    <xsl:with-param name="attr" select="'header'"/>
    90110  </xsl:call-template>
     
    94114
    95115<xsl:param name="xml2rfc-inline">
     116  <xsl:variable name="default">
     117    <xsl:choose>
     118      <xsl:when test="/rfc/@version >= 3">yes</xsl:when>
     119      <xsl:otherwise>no</xsl:otherwise>
     120    </xsl:choose>
     121  </xsl:variable>
    96122  <xsl:call-template name="parse-pis">
    97     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     123    <xsl:with-param name="nodes" select="$global-std-pis"/>
    98124    <xsl:with-param name="attr" select="'inline'"/>
    99     <xsl:with-param name="default" select="'no'"/>
     125    <xsl:with-param name="default" select="$default"/>
    100126  </xsl:call-template>
    101127</xsl:param>
     
    105131
    106132<xsl:param name="xml2rfc-toc">
    107   <xsl:call-template name="parse-pis">
    108     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
    109     <xsl:with-param name="attr" select="'toc'"/>
    110     <xsl:with-param name="default" select="'no'"/>
    111   </xsl:call-template>
     133  <xsl:variable name="default">
     134    <xsl:choose>
     135      <xsl:when test="/rfc/@version >= 3">yes</xsl:when>
     136      <xsl:otherwise>no</xsl:otherwise>
     137    </xsl:choose>
     138  </xsl:variable>
     139  <xsl:choose>
     140    <xsl:when test="/rfc/@tocInclude='false'">no</xsl:when>
     141    <xsl:when test="/rfc/@tocInclude='true'">yes</xsl:when>
     142    <xsl:otherwise>
     143      <xsl:call-template name="parse-pis">
     144        <xsl:with-param name="nodes" select="$global-std-pis"/>
     145        <xsl:with-param name="attr" select="'toc'"/>
     146        <xsl:with-param name="default" select="$default"/>
     147      </xsl:call-template>
     148    </xsl:otherwise>
     149  </xsl:choose>
    112150</xsl:param>
    113151
     
    115153
    116154<xsl:param name="xml2rfc-tocdepth">
    117   <xsl:call-template name="parse-pis">
    118     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
    119     <xsl:with-param name="attr" select="'tocdepth'"/>
    120     <xsl:with-param name="default" select="'3'"/>
    121   </xsl:call-template>
     155  <xsl:choose>
     156    <xsl:when test="/rfc/@tocDepth">
     157      <xsl:value-of select="/rfc/@tocDepth"/>
     158    </xsl:when>
     159    <xsl:otherwise>
     160      <xsl:call-template name="parse-pis">
     161        <xsl:with-param name="nodes" select="$global-std-pis"/>
     162        <xsl:with-param name="attr" select="'tocdepth'"/>
     163        <xsl:with-param name="default" select="'3'"/>
     164      </xsl:call-template>
     165    </xsl:otherwise>
     166  </xsl:choose>
    122167</xsl:param>
    123168
     
    138183<xsl:param name="xml2rfc-topblock">
    139184  <xsl:call-template name="parse-pis">
    140     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     185    <xsl:with-param name="nodes" select="$global-std-pis"/>
    141186    <xsl:with-param name="attr" select="'topblock'"/>
    142187    <xsl:with-param name="default" select="'yes'"/>
     
    148193<xsl:param name="xml2rfc-rfcedstyle">
    149194  <xsl:call-template name="parse-pis">
    150     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     195    <xsl:with-param name="nodes" select="$global-std-pis"/>
    151196    <xsl:with-param name="attr" select="'rfcedstyle'"/>
    152197    <xsl:with-param name="default" select="'no'"/>
     
    158203<xsl:param name="xml2rfc-refparent">
    159204  <xsl:call-template name="parse-pis">
    160     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     205    <xsl:with-param name="nodes" select="$global-std-pis"/>
    161206    <xsl:with-param name="attr" select="'refparent'"/>
    162207    <xsl:with-param name="default" select="'References'"/>
     
    168213
    169214<xsl:param name="xml2rfc-symrefs">
    170   <xsl:call-template name="parse-pis">
    171     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
    172     <xsl:with-param name="attr" select="'symrefs'"/>
    173     <xsl:with-param name="default" select="'yes'"/>
    174   </xsl:call-template>
     215  <xsl:choose>
     216    <xsl:when test="/rfc/@symRefs='false'">no</xsl:when>
     217    <xsl:when test="/rfc/@symRefs='true'">yes</xsl:when>
     218    <xsl:otherwise>
     219      <xsl:call-template name="parse-pis">
     220        <xsl:with-param name="nodes" select="$global-std-pis"/>
     221        <xsl:with-param name="attr" select="'symrefs'"/>
     222        <xsl:with-param name="default" select="'yes'"/>
     223      </xsl:call-template>
     224    </xsl:otherwise>
     225  </xsl:choose>
    175226</xsl:param>
    176227
     
    179230
    180231<xsl:param name="xml2rfc-sortrefs">
    181   <xsl:call-template name="parse-pis">
    182     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
    183     <xsl:with-param name="attr" select="'sortrefs'"/>
    184     <xsl:with-param name="default" select="'no'"/>
    185   </xsl:call-template>
     232  <xsl:choose>
     233    <xsl:when test="/rfc/@sortRefs='true'">yes</xsl:when>
     234    <xsl:when test="/rfc/@sortRefs='false'">no</xsl:when>
     235    <xsl:otherwise>
     236      <xsl:call-template name="parse-pis">
     237        <xsl:with-param name="nodes" select="$global-std-pis"/>
     238        <xsl:with-param name="attr" select="'sortrefs'"/>
     239        <xsl:with-param name="default" select="'no'"/>
     240      </xsl:call-template>
     241    </xsl:otherwise>
     242  </xsl:choose>
    186243</xsl:param>
    187244
     
    191248<xsl:param name="xml2rfc-editing">
    192249  <xsl:call-template name="parse-pis">
    193     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     250    <xsl:with-param name="nodes" select="$global-std-pis"/>
    194251    <xsl:with-param name="attr" select="'editing'"/>
    195252    <xsl:with-param name="default" select="'no'"/>
     
    201258<xsl:param name="xml2rfc-private">
    202259  <xsl:call-template name="parse-pis">
    203     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     260    <xsl:with-param name="nodes" select="$global-std-pis"/>
    204261    <xsl:with-param name="attr" select="'private'"/>
    205262  </xsl:call-template>
     
    210267<xsl:param name="xml2rfc-background">
    211268  <xsl:call-template name="parse-pis">
    212     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     269    <xsl:with-param name="nodes" select="$global-std-pis"/>
    213270    <xsl:with-param name="attr" select="'background'"/>
     271  </xsl:call-template>
     272</xsl:param>
     273
     274<!-- override CSS? -->
     275
     276<xsl:param name="xml2rfc-ext-css-resource">
     277  <xsl:call-template name="parse-pis">
     278    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     279    <xsl:with-param name="attr" select="'css-resource'"/>
     280  </xsl:call-template>
     281</xsl:param>
     282
     283<xsl:param name="xml2rfc-ext-css-contents">
     284  <xsl:call-template name="parse-pis">
     285    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     286    <xsl:with-param name="attr" select="'css-contents'"/>
    214287  </xsl:call-template>
    215288</xsl:param>
     
    239312</xsl:variable>
    240313
     314<!-- CSS styles -->
     315
     316<xsl:param name="xml2rfc-ext-styles">fft-sans-serif ffb-serif ff-cleartype</xsl:param>
     317
     318<xsl:variable name="styles" select="concat(' ',normalize-space($xml2rfc-ext-styles),' ')"/>
     319
     320<xsl:param name="xml2rfc-ext-ff-body">
     321  <xsl:variable name="t">
     322    <xsl:if test="contains($styles,' ff-noto ')">
     323      <xsl:if test="contains($styles,' ffb-serif ')">
     324        'Noto Serif',
     325      </xsl:if>
     326      <xsl:if test="contains($styles,' ffb-sans-serif ')">
     327        'Noto Sans',
     328      </xsl:if>
     329    </xsl:if>
     330    <xsl:if test="contains($styles,' ff-cleartype ')">
     331      <xsl:if test="contains($styles,' ffb-serif ')">
     332        cambria, georgia,
     333      </xsl:if>
     334      <xsl:if test="contains($styles,' ffb-sans-serif ')">
     335        candara, calibri,
     336      </xsl:if>
     337    </xsl:if>
     338    <xsl:if test="contains($styles,' ffb-sans-serif ')">
     339      segoe, optima, arial, sans-serif,
     340    </xsl:if>
     341    serif
     342  </xsl:variable>
     343  <xsl:call-template name="ff-list">
     344    <xsl:with-param name="s" select="normalize-space($t)"/>
     345  </xsl:call-template>
     346</xsl:param>
     347
     348<xsl:param name="xml2rfc-ext-ff-title">
     349  <xsl:variable name="t">
     350    <xsl:if test="contains($styles,' ff-noto ')">
     351      <xsl:if test="contains($styles,' fft-serif ')">
     352        'Noto Serif',
     353      </xsl:if>
     354      <xsl:if test="contains($styles,' fft-sans-serif ')">
     355        'Noto Sans',
     356      </xsl:if>
     357    </xsl:if>
     358    <xsl:if test="contains($styles,' ff-cleartype ')">
     359      <xsl:if test="contains($styles,' fft-serif ')">
     360        cambria, georgia,
     361      </xsl:if>
     362      <xsl:if test="contains($styles,' fft-sans-serif ')">
     363        candara, calibri,
     364      </xsl:if>
     365    </xsl:if>
     366    <xsl:if test="contains($styles,' fft-serif ')">
     367      serif,
     368    </xsl:if>
     369    <xsl:if test="contains($styles,' fft-sans-serif ')">
     370      segoe, optima, arial,
     371    </xsl:if>
     372    sans-serif
     373  </xsl:variable>
     374  <xsl:call-template name="ff-list">
     375    <xsl:with-param name="s" select="normalize-space($t)"/>
     376  </xsl:call-template>
     377</xsl:param>
     378
     379<xsl:param name="xml2rfc-ext-ff-pre">
     380  <xsl:variable name="t">
     381    <xsl:if test="contains($styles,' ff-noto ')">
     382      'Roboto Mono',
     383    </xsl:if>
     384    <xsl:if test="contains($styles,' ff-cleartype ')">
     385      consolas, monaco,
     386    </xsl:if>
     387    monospace
     388  </xsl:variable>
     389  <xsl:call-template name="ff-list">
     390    <xsl:with-param name="s" select="normalize-space($t)"/>
     391  </xsl:call-template>
     392</xsl:param>
     393
     394<xsl:param name="xml2rfc-ext-webfonts">
     395  <xsl:if test="contains($styles,' ff-noto ')">
     396    <xsl:if test="contains($styles,' ffb-sans-serif ') or contains($styles,' fft-sans-serif ')">
     397      <xsl:text>@import url('https://fonts.googleapis.com/css?family=Noto+Sans:r,b,i,bi');&#10;</xsl:text>
     398    </xsl:if>
     399    <xsl:if test="contains($styles,' ffb-serif ') or contains($styles,' fft-serif ')">
     400      <xsl:text>@import url('https://fonts.googleapis.com/css?family=Noto+Serif:r,b,i,bi');&#10;</xsl:text>
     401    </xsl:if>
     402    <xsl:text>@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:r,b,i,bi');&#10;</xsl:text>
     403  </xsl:if>
     404</xsl:param>
     405
     406<xsl:param name="xml2rfc-ext-dark-mode">
     407  <xsl:call-template name="parse-pis">
     408    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     409    <xsl:with-param name="attr" select="'dark-mode'"/>
     410    <xsl:with-param name="default" select="'no'"/>
     411  </xsl:call-template>
     412</xsl:param>
     413
     414<xsl:template name="ff-list">
     415  <xsl:param name="s"/>
     416  <xsl:choose>
     417    <xsl:when test="not(contains($s,','))">
     418      <xsl:value-of select="normalize-space($s)"/>
     419    </xsl:when>
     420    <xsl:otherwise>
     421      <xsl:value-of select="normalize-space(substring-before($s,','))"/>
     422      <xsl:text>, </xsl:text>
     423      <xsl:call-template name="ff-list">
     424        <xsl:with-param name="s" select="substring-after($s,',')"/>
     425      </xsl:call-template>
     426    </xsl:otherwise>
     427  </xsl:choose>
     428</xsl:template>
     429
    241430<!-- include PI -->
     431
     432<xsl:template name="obtain-reference-for-include-PI">
     433  <xsl:param name="uri"/>
     434 
     435  <xsl:variable name="tbase" select="substring-before($uri, '?')"/>
     436  <xsl:variable name="base"><xsl:choose><xsl:when test="$tbase!=''"><xsl:value-of select="$tbase"/></xsl:when><xsl:otherwise><xsl:value-of select="$uri"/></xsl:otherwise></xsl:choose></xsl:variable>
     437  <xsl:variable name="tquery" select="substring-after($uri, '?')"/>
     438  <xsl:variable name="query"><xsl:if test="$tquery!=''">?</xsl:if><xsl:value-of select="$tquery"/></xsl:variable>
     439  <xsl:variable name="ends-with-xml" select="substring($base, string-length($base)-3)='.xml'"/>
     440  <xsl:variable name="for-draft" select="contains($base,'reference.I-D')"/>
     441  <xsl:variable name="uri2" select="concat($base,'.xml',$query)"/>
     442  <xsl:variable name="uri3r" select="concat($xml2rfc-ext-rfc-reference-base-uri,$base,$query)"/>
     443  <xsl:variable name="uri4r" select="concat($xml2rfc-ext-rfc-reference-base-uri,$base,'.xml',$query)"/>
     444  <xsl:variable name="uri3i" select="concat($xml2rfc-ext-internet-draft-reference-base-uri,$base,$query)"/>
     445  <xsl:variable name="uri4i" select="concat($xml2rfc-ext-internet-draft-reference-base-uri,$base,'.xml',$query)"/>
     446  <xsl:choose>
     447    <xsl:when test="function-available('doc-available')">
     448      <xsl:choose>
     449        <xsl:when test="not($ends-with-xml) and doc-available($uri2) and document($uri2)/reference">
     450          <xsl:call-template name="include-uri-warning">
     451            <xsl:with-param name="specified" select="$uri"/>
     452            <xsl:with-param name="success" select="$uri2"/>
     453          </xsl:call-template>
     454          <myns:include from="{$uri2}" in="{generate-id(..)}">
     455            <xsl:copy-of select="document($uri2)"/>
     456          </myns:include>
     457        </xsl:when>
     458        <xsl:when test="doc-available($uri) and document($uri)/reference">
     459          <myns:include from="{$uri}" in="{generate-id(..)}">
     460            <xsl:copy-of select="document($uri)"/>
     461          </myns:include>
     462        </xsl:when>
     463        <xsl:when test="not($ends-with-xml) and $for-draft and not(contains($uri,':')) and doc-available($uri4i) and document($uri4i)/reference">
     464          <xsl:call-template name="include-uri-warning">
     465            <xsl:with-param name="specified" select="$uri"/>
     466            <xsl:with-param name="success" select="$uri4i"/>
     467          </xsl:call-template>
     468          <myns:include from="{$uri4i}" in="{generate-id(..)}">
     469            <xsl:copy-of select="document($uri4i)"/>
     470          </myns:include>
     471        </xsl:when>
     472        <xsl:when test="not(contains($uri,':')) and $for-draft and doc-available($uri3i) and document($uri3i)/reference">
     473          <xsl:call-template name="include-uri-warning">
     474            <xsl:with-param name="specified" select="$uri"/>
     475            <xsl:with-param name="success" select="$uri3i"/>
     476          </xsl:call-template>
     477          <myns:include from="{$uri3i}" in="{generate-id(..)}">
     478            <xsl:copy-of select="document($uri3i)"/>
     479          </myns:include>
     480        </xsl:when>
     481        <xsl:when test="not($ends-with-xml) and not(contains($uri,':')) and doc-available($uri4r) and document($uri4r)/reference">
     482          <xsl:call-template name="include-uri-warning">
     483            <xsl:with-param name="specified" select="$uri"/>
     484            <xsl:with-param name="success" select="$uri4r"/>
     485          </xsl:call-template>
     486          <myns:include from="{$uri4r}" in="{generate-id(..)}">
     487            <xsl:copy-of select="document($uri4r)"/>
     488          </myns:include>
     489        </xsl:when>
     490        <xsl:when test="not(contains($uri,':')) and doc-available($uri3r) and document($uri3r)/reference">
     491          <xsl:call-template name="include-uri-warning">
     492            <xsl:with-param name="specified" select="$uri"/>
     493            <xsl:with-param name="success" select="$uri3r"/>
     494          </xsl:call-template>
     495          <myns:include from="{$uri3r}" in="{generate-id(..)}">
     496            <xsl:copy-of select="document($uri3r)"/>
     497          </myns:include>
     498        </xsl:when>
     499        <xsl:otherwise/>
     500      </xsl:choose>
     501    </xsl:when>
     502    <xsl:otherwise>
     503      <xsl:choose>
     504        <xsl:when test="not($ends-with-xml) and document($uri2)/reference">
     505          <xsl:call-template name="include-uri-warning">
     506            <xsl:with-param name="specified" select="$uri"/>
     507            <xsl:with-param name="success" select="$uri2"/>
     508          </xsl:call-template>
     509          <myns:include from="{$uri2}" in="{generate-id(..)}">
     510            <xsl:copy-of select="document($uri2)"/>
     511          </myns:include>
     512        </xsl:when>
     513        <xsl:when test="document($uri)/reference">
     514          <myns:include from="{$uri}" in="{generate-id(..)}">
     515            <xsl:copy-of select="document($uri)"/>
     516          </myns:include>
     517        </xsl:when>
     518        <xsl:when test="not($ends-with-xml) and $for-draft and not(contains($uri,':')) and document($uri4i)/reference">
     519          <xsl:call-template name="include-uri-warning">
     520            <xsl:with-param name="specified" select="$uri"/>
     521            <xsl:with-param name="success" select="$uri4i"/>
     522          </xsl:call-template>
     523          <myns:include from="{$uri4i}" in="{generate-id(..)}">
     524            <xsl:copy-of select="document($uri4i)"/>
     525          </myns:include>
     526        </xsl:when>
     527        <xsl:when test="not(contains($uri,':')) and $for-draft and document($uri3i)/reference">
     528          <xsl:call-template name="include-uri-warning">
     529            <xsl:with-param name="specified" select="$uri"/>
     530            <xsl:with-param name="success" select="$uri3i"/>
     531          </xsl:call-template>
     532          <myns:include from="{$uri3i}" in="{generate-id(..)}">
     533            <xsl:copy-of select="document($uri3i)"/>
     534          </myns:include>
     535        </xsl:when>
     536        <xsl:when test="not($ends-with-xml) and not(contains($uri,':')) and document($uri4r)/reference">
     537          <xsl:call-template name="include-uri-warning">
     538            <xsl:with-param name="specified" select="$uri"/>
     539            <xsl:with-param name="success" select="$uri4r"/>
     540          </xsl:call-template>
     541          <myns:include from="{$uri4r}" in="{generate-id(..)}">
     542            <xsl:copy-of select="document($uri4r)"/>
     543          </myns:include>
     544        </xsl:when>
     545        <xsl:when test="not(contains($uri,':')) and document($uri3r)/reference">
     546          <xsl:call-template name="include-uri-warning">
     547            <xsl:with-param name="specified" select="$uri"/>
     548            <xsl:with-param name="success" select="$uri3r"/>
     549          </xsl:call-template>
     550          <myns:include from="{$uri3r}" in="{generate-id(..)}">
     551            <xsl:copy-of select="document($uri3r)"/>
     552          </myns:include>
     553        </xsl:when>
     554        <xsl:otherwise/>
     555      </xsl:choose>
     556    </xsl:otherwise>
     557  </xsl:choose>     
     558</xsl:template>
    242559
    243560<xsl:template name="getIncludes">
    244561  <xsl:param name="nodes"/>
    245562  <xsl:for-each select="$nodes">
    246     <xsl:variable name="include">
     563    <xsl:variable name="uri1">
    247564      <xsl:call-template name="parse-pis">
    248565        <xsl:with-param name="nodes" select="."/>
     
    250567      </xsl:call-template>
    251568    </xsl:variable>
    252     <xsl:variable name="doc">
    253       <xsl:choose>
    254         <xsl:when test="$include=''"/>
    255         <xsl:when test="substring($include, string-length($include) - 3) != '.xml'">
    256           <xsl:copy-of select="document(concat($include,'.xml'))"/>
    257         </xsl:when>
    258         <xsl:otherwise>
    259           <xsl:copy-of select="document($include)"/>
    260         </xsl:otherwise>
    261       </xsl:choose>
    262     </xsl:variable>
    263     <xsl:if test="count(exslt:node-set($doc)) = 1">
    264       <myns:include from="{$include}" in="{generate-id(..)}">
    265         <xsl:copy-of select="$doc"/>
    266       </myns:include>
     569    <xsl:if test="$uri1!=''">
     570      <xsl:call-template name="obtain-reference-for-include-PI">
     571        <xsl:with-param name="uri" select="$uri1"/>
     572      </xsl:call-template>
    267573    </xsl:if>
    268574  </xsl:for-each>
     575</xsl:template>
     576
     577<xsl:template name="include-uri-warning">
     578  <xsl:param name="specified"/>
     579  <xsl:param name="success"/>
     580  <xsl:call-template name="warning">
     581    <xsl:with-param name="msg">include succeeded for best-guess URI <xsl:value-of select="$success"/> while <xsl:value-of select="$specified"/> was specified - you may want to adjust the include directive in order to avoid future warnings</xsl:with-param>
     582  </xsl:call-template>
    269583</xsl:template>
    270584
     
    279593      </xsl:when>
    280594      <xsl:otherwise>
     595        <xsl:variable name="uri">
     596          <!--<xsl:choose>
     597            <xsl:when test="starts-with(@href,'https://xml2rfc.ietf.org/public/rfc/')">
     598              <xsl:call-template name="warning">
     599                <xsl:with-param name="msg">rewriting URI to /xml2rfc.tools.ietf.org for <xsl:value-of select="@href"/> - see in order to avoid broken server's 403 response (see https://mailarchive.ietf.org/arch/msg/xml2rfc/56sDqFVKF0baqdgEjHQtxOUMf4o).</xsl:with-param>
     600              </xsl:call-template>
     601              <xsl:value-of select="concat('https://xml2rfc.tools.ietf.org/public/rfc/',substring-after(@href,'https://xml2rfc.ietf.org/public/rfc/'))"/>
     602            </xsl:when>
     603            <xsl:otherwise>-->
     604              <xsl:value-of select="@href"/>
     605            <!--</xsl:otherwise>
     606          </xsl:choose>-->
     607        </xsl:variable>
    281608        <xsl:variable name="doc">
    282           <xsl:copy-of select="document(@href)"/>
     609          <xsl:copy-of select="document($uri)"/>
    283610        </xsl:variable>
    284         <xsl:if test="count(exslt:node-set($doc)) = 1">
     611        <xsl:if test="count($doc) = 1">
    285612          <myns:include from="{@href}" in="{generate-id(..)}">
    286613            <xsl:copy-of select="$doc"/>
    287614          </myns:include>
    288615        </xsl:if>
     616        <xsl:if test="$doc//xi:include">
     617          <xsl:call-template name="error">
     618            <xsl:with-param name="msg" select="'Nested x:include elements are not supported'"/>
     619            <xsl:with-param name="node" select="exslt:node-set($doc)//xi:include"/>
     620          </xsl:call-template>
     621        </xsl:if>
    289622      </xsl:otherwise>
    290623    </xsl:choose>
     
    294627<xsl:variable name="includeDirectives">
    295628  <xsl:call-template name="getIncludes">
    296     <xsl:with-param name="nodes" select="/rfc/back/references/processing-instruction('rfc')"/>
     629    <xsl:with-param name="nodes" select="/rfc/back//references/processing-instruction('rfc')|/rfc/back//references/referencegroup/processing-instruction('rfc')"/>
    297630  </xsl:call-template>
    298631  <xsl:call-template name="getXIncludes">
    299     <xsl:with-param name="nodes" select="/rfc/back/references/xi:include"/>
     632    <xsl:with-param name="nodes" select="/rfc/back//references/xi:include|/rfc/back//references/referencegroup/xi:include"/>
    300633  </xsl:call-template>
    301634</xsl:variable>
     635
     636<xsl:variable name="sourcedReferences">
     637  <xsl:for-each select="//reference[x:source/@href and not(seriesInfo)]">
     638    <xsl:copy>
     639      <xsl:variable name="f" select="document(x:source/@href)"/>
     640      <xsl:if test="$f/rfc/@number" myns:namespaceless-elements="xml2rfc">
     641        <seriesInfo name="RFC" value="{$f/rfc/@number}"/>
     642      </xsl:if>
     643      <xsl:if test="$f/rfc/@docName" myns:namespaceless-elements="xml2rfc">
     644        <seriesInfo name="Internet-Draft" value="{$f/@docName}"/>
     645      </xsl:if>
     646    </xsl:copy>
     647  </xsl:for-each>
     648</xsl:variable>
     649
     650<!-- logging -->
     651
     652<xsl:param name="xml2rfc-ext-log-level">
     653  <xsl:call-template name="parse-pis">
     654    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     655    <xsl:with-param name="attr" select="'log-level'"/>
     656    <xsl:with-param name="default" select="'WARNING'"/>
     657  </xsl:call-template>
     658</xsl:param>
     659
     660<xsl:variable name="log-level">
     661  <xsl:call-template name="parse-log-level">
     662    <xsl:with-param name="level" select="$xml2rfc-ext-log-level"/>
     663  </xsl:call-template>
     664</xsl:variable>
     665
     666<xsl:param name="xml2rfc-ext-abort-on">
     667  <xsl:call-template name="parse-pis">
     668    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     669    <xsl:with-param name="attr" select="'abort-on'"/>
     670    <xsl:with-param name="default" select="'OFF'"/>
     671  </xsl:call-template>
     672</xsl:param>
     673
     674<xsl:variable name="abort-log-level">
     675  <xsl:call-template name="parse-log-level">
     676    <xsl:with-param name="level" select="$xml2rfc-ext-abort-on"/>
     677  </xsl:call-template>
     678</xsl:variable>
     679
     680<xsl:template name="parse-log-level">
     681  <xsl:param name="level"/>
     682  <xsl:choose>
     683    <xsl:when test="$level='OFF'">6</xsl:when>
     684    <xsl:when test="$level='FATAL'">5</xsl:when>
     685    <xsl:when test="$level='ERROR'">4</xsl:when>
     686    <xsl:when test="$level='WARNING'">3</xsl:when>
     687    <xsl:when test="$level='INFO'">2</xsl:when>
     688    <xsl:when test="$level='DEBUG'">1</xsl:when>
     689    <xsl:when test="$level='TRACE'">0</xsl:when>
     690    <xsl:otherwise>
     691      <xsl:message>Unsupported LOG level '<xsl:value-of select="$level"/>', defaulting to 'WARNING'</xsl:message>
     692      <xsl:value-of select="'3'"/>
     693    </xsl:otherwise>
     694  </xsl:choose>
     695</xsl:template>
    302696
    303697<!-- prettyprinting -->
     
    321715  </xsl:if>
    322716</xsl:variable>
     717
     718<!-- Unicode database -->
     719<xsl:param name="xml2rfc-ext-ucd-file">
     720  <xsl:call-template name="parse-pis">
     721    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     722    <xsl:with-param name="attr" select="'ucd-file'"/>
     723  </xsl:call-template>
     724</xsl:param>
     725
     726<!-- external resource containing errata, as generated by parse-errata.xslt -->
     727<xsl:param name="xml2rfc-ext-errata"/>
     728<xsl:variable name="errata-parsed" select="document($xml2rfc-ext-errata)//erratum[@status!='Rejected']"/>
     729
     730<!-- "remove in RFC phrases" -->
     731<xsl:variable name="note-removeInRFC">This note is to be removed before publishing as an RFC.</xsl:variable>
     732<xsl:variable name="section-removeInRFC">This section is to be removed before publishing as an RFC.</xsl:variable>
     733
     734<!-- constant string for unnumbered parts -->
     735<xsl:variable name="unnumbered">unnumbered-</xsl:variable>
    323736
    324737<!-- CSS class name remapping -->
     
    341754
    342755<!-- WORK IN PROGRESS; ONLY A FEW CLASSES SUPPORTED FOR NOW -->
     756<xsl:variable name="css-artwork"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'artwork'"/></xsl:call-template></xsl:variable>
     757<xsl:variable name="css-art-svg"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'art-svg'"/></xsl:call-template></xsl:variable>
    343758<xsl:variable name="css-docstatus"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'docstatus'"/></xsl:call-template></xsl:variable>
     759<xsl:variable name="css-center"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'center'"/></xsl:call-template></xsl:variable>
     760<xsl:variable name="css-erratum"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'erratum'"/></xsl:call-template></xsl:variable>
    344761<xsl:variable name="css-error"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'error'"/></xsl:call-template></xsl:variable>
    345762<xsl:variable name="css-fbbutton"><xsl:call-template name="generate-css-class"><xsl:with-param name="name" select="'fbbutton'"/></xsl:call-template></xsl:variable>
     
    428845
    429846<xsl:param name="xml2rfc-ext-include-index">
    430   <xsl:call-template name="parse-pis">
    431     <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
    432     <xsl:with-param name="attr" select="'include-index'"/>
    433     <xsl:with-param name="default" select="'yes'"/>
    434   </xsl:call-template>
     847  <xsl:choose>
     848    <xsl:when test="/rfc/@indexInclude='false'">no</xsl:when>
     849    <xsl:when test="/rfc/@indexInclude='true'">yes</xsl:when>
     850    <xsl:otherwise>
     851      <xsl:call-template name="parse-pis">
     852        <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     853        <xsl:with-param name="attr" select="'include-index'"/>
     854        <xsl:with-param name="default" select="'yes'"/>
     855      </xsl:call-template>
     856    </xsl:otherwise>
     857  </xsl:choose>
    435858</xsl:param>
    436859
     
    455878</xsl:param>
    456879
     880<!-- extension for excluding generator information -->
     881
     882<xsl:param name="xml2rfc-ext-include-generator">
     883  <xsl:call-template name="parse-pis">
     884    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     885    <xsl:with-param name="attr" select="'include-generator'"/>
     886    <xsl:with-param name="default" select="'yes'"/>
     887  </xsl:call-template>
     888</xsl:param>
     889
    457890<!-- extension for specifying the value for <vspace> after which it's taken as a page break -->
    458891
     
    485918</xsl:param>
    486919
     920<!-- extension for switching the behaviour for xrefs with text content -->
     921<!-- 'text': as in text output, 'nothing': just the link -->
     922
     923<xsl:param name="xml2rfc-ext-xref-with-text-generate">
     924  <xsl:call-template name="parse-pis">
     925    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     926    <xsl:with-param name="attr" select="'xref-with-text-generate-text'"/>
     927    <xsl:with-param name="default" select="'text'"/>
     928  </xsl:call-template>
     929</xsl:param>
     930
    487931<!-- position of author's section -->
    488932
     
    538982<xsl:param name="xml2rfc-linkmailto">
    539983  <xsl:call-template name="parse-pis">
    540     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     984    <xsl:with-param name="nodes" select="$global-std-pis"/>
    541985    <xsl:with-param name="attr" select="'linkmailto'"/>
    542986    <xsl:with-param name="default" select="'yes'"/>
     
    548992<xsl:param name="xml2rfc-iprnotified">
    549993  <xsl:call-template name="parse-pis">
    550     <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
     994    <xsl:with-param name="nodes" select="$global-std-pis"/>
    551995    <xsl:with-param name="attr" select="'iprnotified'"/>
    552996    <xsl:with-param name="default" select="'no'"/>
     
    5561000<!-- URL templates for RFCs and Internet Drafts. -->
    5571001
    558 <!-- Reference the authoritative ASCII versions
    559 <xsl:param name="rfcUrlPrefix" select="'http://www.ietf.org/rfc/rfc'" />
    560 <xsl:param name="rfcUrlPostfix" select="'.txt'" />
    561 -->
    5621002<!-- Reference the marked up versions over on https://tools.ietf.org/html. -->
    563 <xsl:param name="rfcUrlPrefix" select="'https://tools.ietf.org/html/rfc'" />
    564 <xsl:param name="rfcUrlPostfix" select="''" />
    5651003<xsl:param name="rfcUrlFragSection" select="'section-'" />
    5661004<xsl:param name="rfcUrlFragAppendix" select="'appendix-'" />
    567 <xsl:param name="internetDraftUrlPrefix" select="'https://tools.ietf.org/html/'" />
    568 <xsl:param name="internetDraftUrlPostfix" select="''" />
    5691005<xsl:param name="internetDraftUrlFragSection" select="'section-'" />
    5701006<xsl:param name="internetDraftUrlFragAppendix" select="'appendix-'" />
     1007
     1008<!-- base URI for include directive when relative reference does not resolve for RFCs -->
     1009<xsl:param name="xml2rfc-ext-rfc-reference-base-uri">
     1010  <xsl:call-template name="parse-pis">
     1011    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1012    <xsl:with-param name="attr" select="'rfc-reference-base-uri'"/>
     1013    <!-- previously 'https://xml2rfc.tools.ietf.org/public/rfc/bibxml/' -->
     1014    <xsl:with-param name="default">https://www.rfc-editor.org/refs/bibxml/</xsl:with-param>
     1015  </xsl:call-template>
     1016</xsl:param>
     1017
     1018<!-- base URI for include directive when relative reference does not resolve for Intetnet Drafts -->
     1019<xsl:param name="xml2rfc-ext-internet-draft-reference-base-uri">
     1020  <xsl:call-template name="parse-pis">
     1021    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1022    <xsl:with-param name="attr" select="'internet-draft-reference-base-uri'"/>
     1023    <xsl:with-param name="default">https://xml2rfc.tools.ietf.org/public/rfc/bibxml-ids/</xsl:with-param>
     1024  </xsl:call-template>
     1025</xsl:param>
     1026
     1027<!--templates for URI calculation -->
     1028
     1029<xsl:param name="xml2rfc-ext-isbn-uri">
     1030  <xsl:call-template name="parse-pis">
     1031    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1032    <xsl:with-param name="attr" select="'isbn-uri'"/>
     1033    <xsl:with-param name="default">https://www.worldcat.org/search?q=isbn:{isbn}</xsl:with-param>
     1034  </xsl:call-template>
     1035</xsl:param>
     1036
     1037<xsl:template name="compute-isbn-uri">
     1038  <xsl:param name="isbn"/>
     1039  <xsl:call-template name="replace-substring">
     1040    <xsl:with-param name="string" select="$xml2rfc-ext-isbn-uri"/>
     1041    <xsl:with-param name="replace" select="'{isbn}'"/>
     1042    <xsl:with-param name="by" select="translate($isbn,'-','')"/>
     1043  </xsl:call-template>
     1044</xsl:template>
     1045
     1046<xsl:param name="xml2rfc-ext-rfc-uri">
     1047  <xsl:call-template name="parse-pis">
     1048    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1049    <xsl:with-param name="attr" select="'rfc-uri'"/>
     1050    <!-- previously 'https://tools.ietf.org/html/rfc{rfc}' -->
     1051    <xsl:with-param name="default">https://www.rfc-editor.org/rfc/rfc{rfc}.html</xsl:with-param>
     1052  </xsl:call-template>
     1053</xsl:param>
     1054
     1055<xsl:template name="compute-rfc-uri">
     1056  <xsl:param name="rfc"/>
     1057  <xsl:call-template name="replace-substring">
     1058    <xsl:with-param name="string" select="$xml2rfc-ext-rfc-uri"/>
     1059    <xsl:with-param name="replace" select="'{rfc}'"/>
     1060    <xsl:with-param name="by" select="$rfc"/>
     1061  </xsl:call-template>
     1062</xsl:template>
     1063
     1064<xsl:param name="xml2rfc-ext-internet-draft-uri">
     1065  <xsl:call-template name="parse-pis">
     1066    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1067    <xsl:with-param name="attr" select="'internet-draft-uri'"/>
     1068    <xsl:with-param name="default">https://tools.ietf.org/html/{internet-draft}</xsl:with-param>
     1069  </xsl:call-template>
     1070</xsl:param>
     1071
     1072<xsl:template name="compute-internet-draft-uri">
     1073  <xsl:param name="internet-draft"/>
     1074  <xsl:param name="ref" select="."/>
     1075  <xsl:variable name="local-link-template">
     1076    <xsl:call-template name="parse-pis">
     1077      <xsl:with-param name="nodes" select="$ref/processing-instruction('rfc-ext')"/>
     1078      <xsl:with-param name="attr" select="'internet-draft-uri'"/>
     1079    </xsl:call-template>
     1080  </xsl:variable>
     1081  <xsl:choose>
     1082    <xsl:when test="$local-link-template!=''">
     1083      <xsl:call-template name="replace-substring">
     1084        <xsl:with-param name="string" select="$local-link-template"/>
     1085        <xsl:with-param name="replace" select="'{internet-draft}'"/>
     1086        <xsl:with-param name="by" select="$internet-draft"/>
     1087      </xsl:call-template>
     1088    </xsl:when>
     1089    <xsl:otherwise>
     1090      <xsl:call-template name="replace-substring">
     1091        <xsl:with-param name="string" select="$xml2rfc-ext-internet-draft-uri"/>
     1092        <xsl:with-param name="replace" select="'{internet-draft}'"/>
     1093        <xsl:with-param name="by" select="$internet-draft"/>
     1094      </xsl:call-template>
     1095    </xsl:otherwise>
     1096  </xsl:choose>
     1097</xsl:template>
     1098
     1099<xsl:param name="xml2rfc-ext-diff-uri">
     1100  <xsl:call-template name="parse-pis">
     1101    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1102    <xsl:with-param name="attr" select="'diff-uri'"/>
     1103    <xsl:with-param name="default">https://tools.ietf.org/rfcdiff?url2={internet-draft}</xsl:with-param>
     1104  </xsl:call-template>
     1105</xsl:param>
     1106
     1107<xsl:template name="compute-diff-uri">
     1108  <xsl:param name="name"/>
     1109  <xsl:call-template name="replace-substring">
     1110    <xsl:with-param name="string" select="$xml2rfc-ext-diff-uri"/>
     1111    <xsl:with-param name="replace" select="'{internet-draft}'"/>
     1112    <xsl:with-param name="by" select="$name"/>
     1113  </xsl:call-template>
     1114</xsl:template>
     1115
     1116<xsl:param name="xml2rfc-ext-latest-diff-uri">
     1117  <xsl:call-template name="parse-pis">
     1118    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1119    <xsl:with-param name="attr" select="'latest-diff-uri'"/>
     1120  </xsl:call-template>
     1121</xsl:param>
     1122
     1123<xsl:template name="compute-latest-diff-uri">
     1124  <xsl:param name="name"/>
     1125  <xsl:call-template name="replace-substring">
     1126    <xsl:with-param name="string" select="$xml2rfc-ext-latest-diff-uri"/>
     1127    <xsl:with-param name="replace" select="'{internet-draft}'"/>
     1128    <xsl:with-param name="by" select="$name"/>
     1129  </xsl:call-template>
     1130</xsl:template>
     1131
     1132<xsl:param name="xml2rfc-ext-doi-uri">
     1133  <xsl:call-template name="parse-pis">
     1134    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1135    <xsl:with-param name="attr" select="'doi-uri'"/>
     1136    <xsl:with-param name="default">https://dx.doi.org/{doi}</xsl:with-param>
     1137  </xsl:call-template>
     1138</xsl:param>
     1139
     1140<xsl:template name="compute-doi-uri">
     1141  <xsl:param name="doi"/>
     1142  <xsl:call-template name="replace-substring">
     1143    <xsl:with-param name="string" select="$xml2rfc-ext-doi-uri"/>
     1144    <xsl:with-param name="replace" select="'{doi}'"/>
     1145    <xsl:with-param name="by" select="$doi"/>
     1146  </xsl:call-template>
     1147</xsl:template>
     1148
     1149<xsl:param name="xml2rfc-ext-rfc-info-uri">
     1150  <xsl:call-template name="parse-pis">
     1151    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1152    <xsl:with-param name="attr" select="'rfc-info-uri'"/>
     1153    <xsl:with-param name="default">
     1154      <xsl:choose>
     1155        <xsl:when test="$pub-yearmonth &lt; 201708">http://www.rfc-editor.org/info/{type}{no}</xsl:when>
     1156        <xsl:otherwise>https://www.rfc-editor.org/info/{type}{no}</xsl:otherwise>
     1157      </xsl:choose>   
     1158    </xsl:with-param>
     1159  </xsl:call-template>
     1160</xsl:param>
     1161
     1162<xsl:template name="compute-rfc-info-uri">
     1163  <xsl:param name="type"/>
     1164  <xsl:param name="no"/>
     1165  <xsl:variable name="t">
     1166    <xsl:call-template name="replace-substring">
     1167      <xsl:with-param name="string" select="$xml2rfc-ext-rfc-info-uri"/>
     1168      <xsl:with-param name="replace" select="'{type}'"/>
     1169      <xsl:with-param name="by" select="$type"/>
     1170    </xsl:call-template>
     1171  </xsl:variable>
     1172  <xsl:call-template name="replace-substring">
     1173    <xsl:with-param name="string" select="$t"/>
     1174    <xsl:with-param name="replace" select="'{no}'"/>
     1175    <xsl:with-param name="by" select="$no"/>
     1176  </xsl:call-template>
     1177</xsl:template>
     1178
     1179<xsl:param name="xml2rfc-ext-rfc-erratum-uri">
     1180  <xsl:call-template name="parse-pis">
     1181    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1182    <xsl:with-param name="attr" select="'rfc-erratum-uri'"/>
     1183    <xsl:with-param name="default">https://www.rfc-editor.org/errata/eid{eid}</xsl:with-param>
     1184  </xsl:call-template>
     1185</xsl:param>
     1186
     1187<xsl:template name="compute-rfc-erratum-uri">
     1188  <xsl:param name="eid"/>
     1189  <xsl:call-template name="replace-substring">
     1190    <xsl:with-param name="string" select="$xml2rfc-ext-rfc-erratum-uri"/>
     1191    <xsl:with-param name="replace" select="'{eid}'"/>
     1192    <xsl:with-param name="by" select="$eid"/>
     1193  </xsl:call-template>
     1194</xsl:template>
     1195
     1196<xsl:param name="xml2rfc-ext-rfc-errata-uri">
     1197  <xsl:call-template name="parse-pis">
     1198    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1199    <xsl:with-param name="attr" select="'rfc-errata-uri'"/>
     1200    <xsl:with-param name="default">https://www.rfc-editor.org/errata/rfc{rfc}</xsl:with-param>
     1201  </xsl:call-template>
     1202</xsl:param>
     1203
     1204<xsl:param name="xml2rfc-ext-draft-status-uri">
     1205  <xsl:call-template name="parse-pis">
     1206    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1207    <xsl:with-param name="attr" select="'draft-status-uri'"/>
     1208    <xsl:with-param name="default">https://datatracker.ietf.org/doc/{draftname}</xsl:with-param>
     1209  </xsl:call-template>
     1210</xsl:param>
     1211
     1212<xsl:template name="compute-draft-status-uri">
     1213  <xsl:param name="draftname"/>
     1214  <xsl:call-template name="replace-substring">
     1215    <xsl:with-param name="string" select="$xml2rfc-ext-draft-status-uri"/>
     1216    <xsl:with-param name="replace" select="'{draftname}'"/>
     1217    <xsl:with-param name="by" select="$draftname"/>
     1218  </xsl:call-template>
     1219</xsl:template>
    5711220
    5721221<!-- the format we're producing -->
     
    6001249</xsl:param>
    6011250
     1251<!-- for testing: switch to disable code that gets the system time -->
     1252<xsl:param name="xml2rfc-ext-use-system-time">
     1253  <xsl:call-template name="parse-pis">
     1254    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
     1255    <xsl:with-param name="attr" select="'use-system-time'"/>
     1256    <xsl:with-param name="default" select="'yes'"/>
     1257  </xsl:call-template>
     1258</xsl:param>
     1259
    6021260<!-- warning re: absent node-set ext. function -->
    6031261<xsl:variable name="node-set-warning">
     
    6171275<xsl:key name="index-first-letter"
    6181276  match="iref|reference"
    619     use="translate(substring(concat(@anchor,@item),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
     1277    use="translate(substring(concat(/rfc/back/displayreference[@target=current()/@anchor]/@to,@anchor,@item),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
    6201278
    6211279<xsl:key name="index-item"
     
    6281286
    6291287<xsl:key name="index-xref-by-sec"
    630   match="xref[@x:sec|@section]"
     1288  match="xref[@x:sec]|relref[@section]"
    6311289    use="concat(@target,'..',@x:sec,@section)" />
    6321290
    6331291<xsl:key name="index-xref-by-anchor"
    634   match="xref[@x:rel|@relative]"
     1292  match="xref[@x:rel]|relref[@relative]"
    6351293    use="concat(@target,'..',@x:rel,@relative)" />
    6361294
     
    6401298
    6411299<xsl:key name="xref-item"
    642   match="//xref"
     1300  match="//xref|//relref"
    6431301    use="@target"/>
    6441302
     
    6521310<!-- IPR version switch -->
    6531311<xsl:variable name="ipr-rfc3667" select="(
    654   /rfc/@number &gt; 3708) or
     1312  number($rfcno) &gt; 3708) or
    6551313  not(
    6561314    (/rfc/@ipr = 'full2026') or
     
    6621320  )" />
    6631321
    664 <xsl:variable name="rfcno" select="/rfc/@number"/>
     1322<xsl:variable name="draft-fullname" select="/rfc/@docName"/>
     1323
     1324<xsl:variable name="draft-seq">
     1325  <xsl:call-template name="draft-sequence-number">
     1326    <xsl:with-param name="name" select="$draft-fullname"/>
     1327  </xsl:call-template>
     1328</xsl:variable>
     1329
     1330<xsl:variable name="draft-basename">
     1331  <xsl:call-template name="draft-base-name">
     1332    <xsl:with-param name="name" select="$draft-fullname"/>
     1333  </xsl:call-template>
     1334</xsl:variable>
     1335
     1336<xsl:variable name="is-submitted-draft" select="number($draft-seq)=$draft-seq"/>
     1337
     1338<xsl:variable name="is-rfc" select="$src/rfc/@number"/>
     1339
     1340<xsl:variable name="rfcno">
     1341  <xsl:value-of select="$src/rfc/@number"/>
     1342  <xsl:if test="$is-rfc">
     1343    <xsl:for-each select="$src/rfc/front/seriesInfo[@name='RFC']">
     1344      <xsl:if test="number(@value) != number($src/rfc/@number)">
     1345        <xsl:call-template name="error">
     1346          <xsl:with-param name="msg">RFC number given in /rfc/front/seriesInfo (<xsl:value-of select="@value"/>) inconsistent with rfc element (<xsl:value-of select="$src/rfc/@number"/>)</xsl:with-param>
     1347        </xsl:call-template>
     1348      </xsl:if>
     1349    </xsl:for-each>
     1350  </xsl:if>
     1351</xsl:variable>
    6651352
    6661353<xsl:variable name="submissionType">
     
    7211408</xsl:variable>
    7221409
     1410<!-- use https in boilerplate links? -->
     1411<xsl:variable name="rfc-boilerplate-use-https" select="($pub-yearmonth >= 201709 and number($rfcno)!=8230 and number($rfcno)!=8325 and number($rfcno)!=8236) or number($rfcno)=8214 or number($rfcno)=8223"/>
     1412
     1413<xsl:variable name="rfc-info-link">
     1414  <xsl:variable name="scheme">
     1415    <xsl:choose>
     1416      <xsl:when test="$rfc-boilerplate-use-https">https</xsl:when>
     1417      <xsl:otherwise>http</xsl:otherwise>
     1418    </xsl:choose>
     1419  </xsl:variable>
     1420  <xsl:value-of select="concat($scheme,'://www.rfc-editor.org/info/rfc',$rfcno)"/>
     1421</xsl:variable>
     1422
     1423<xsl:variable name="trust-license-info-link">
     1424  <xsl:variable name="scheme">
     1425    <xsl:choose>
     1426      <xsl:when test="$rfc-boilerplate-use-https">https</xsl:when>
     1427      <xsl:otherwise>http</xsl:otherwise>
     1428    </xsl:choose>
     1429  </xsl:variable>
     1430  <xsl:value-of select="concat($scheme,'://trustee.ietf.org/license-info')"/>
     1431</xsl:variable>
     1432
     1433<!-- the reference to the latest and greatest headers-and-boilerplates document -->
     1434<xsl:variable name="hab-reference" myns:namespaceless-elements="xml2rfc">
     1435  <eref>
     1436    <xsl:choose>
     1437      <xsl:when test="$pub-yearmonth >= 201606 or ($rfcno=7846 or $rfcno=7865 or $rfcno=7866 or $rfcno=7873 or $rfcno=7879 or $rfcno=7892)"><xsl:attribute name="target">https://tools.ietf.org/html/rfc7841#section-2</xsl:attribute>Section 2 of RFC 7841</xsl:when>
     1438      <xsl:otherwise><xsl:attribute name="target">https://tools.ietf.org/html/rfc5741#section-2</xsl:attribute>Section 2 of RFC 5741</xsl:otherwise>
     1439    </xsl:choose>
     1440  </eref>
     1441</xsl:variable>
     1442
    7231443<xsl:variable name="id-boilerplate">
    7241444  <xsl:choose>
     
    7321452<xsl:variable name="ipr-rfc4748" select="(
    7331453  $ipr-rfc3667 and
    734     ( $rfcno &gt;= 4715 and ( $rfcno != 4718 and $rfcno != 4735 and $rfcno != 4749 ))
     1454    ( number($rfcno) &gt;= 4715 and ( number($rfcno)!=4718 and number($rfcno)!=4735 and number($rfcno)!= 4749 ))
    7351455    or
    736     ( $rfcno=4578 or $rfcno=4582 or $rfcno=4583 or $rfcno=4628 or $rfcno=4629 or $rfcno=4639 or $rfcno=4651 or $rfcno=4682 or $rfcno=4684 or $rfcno=4695 or $rfcno=4696 )
     1456    ( number($rfcno)=4578 or number($rfcno)=4582 or number($rfcno)=4583 or number($rfcno)=4628 or number($rfcno)=4629 or number($rfcno)=4639 or number($rfcno)=4651 or number($rfcno)=4682 or number($rfcno)=4684 or number($rfcno)=4695 or number($rfcno)=4696 )
    7371457    or
    738     ( not(/rfc/@number) and $pub-yearmonth >= 200611)
     1458    ( not($is-rfc) and $pub-yearmonth >= 200611)
    7391459  )" />
    7401460
     
    7421462  $ipr-rfc4748 and
    7431463    (
    744       ($rfcno &gt; 5000
    745         and $rfcno != 5020
    746         and $rfcno != 5021
    747         and $rfcno != 5034
    748         and $rfcno != 5052
    749         and $rfcno != 5065
    750         and $rfcno != 5094) or
     1464      (number($rfcno) &gt; 5000
     1465        and number($rfcno) != 5020
     1466        and number($rfcno) != 5021
     1467        and number($rfcno) != 5034
     1468        and number($rfcno) != 5052
     1469        and number($rfcno) != 5065
     1470        and number($rfcno) != 5094) or
    7511471      ($xml2rfc-ext-pub-year >= 2008) or
    752       (not(/rfc/@number) and $pub-yearmonth >= 200709)
     1472      (not($is-rfc) and $pub-yearmonth >= 200709)
    7531473    )
    7541474  )" />
    7551475
    7561476<xsl:variable name="ipr-2008-11" select="(
    757     /rfc/@number and $pub-yearmonth >= 200811
     1477    $is-rfc and $pub-yearmonth >= 200811
    7581478  )
    7591479  or
     
    7751495     for IDs, and around 2009-09 for RFCs-->
    7761496<xsl:variable name="ipr-2009-09" select="(
    777     ( not(/rfc/@number) and $pub-yearmonth >= 200911 )
     1497    ( not($is-rfc) and $pub-yearmonth >= 200911 )
    7781498    or
    7791499    (
    780       /rfc/@number and $pub-yearmonth >= 200909 and
     1500      $is-rfc and $pub-yearmonth >= 200909 and
    7811501      $rfcno!=5582 and $rfcno!=5621 and $rfcno!=5632 and $rfcno!=5645 and $rfcno!=5646 and $rfcno!=5681
    7821502    )
     
    7861506     for IDs, and around 2010-01 for RFCs-->
    7871507<xsl:variable name="ipr-2010-01" select="(
    788     ( not(/rfc/@number) and $pub-yearmonth >= 201004 )
     1508    ( not($is-rfc) and $pub-yearmonth >= 201004 )
    7891509    or
    7901510    (
    791       /rfc/@number and ($pub-yearmonth >= 201001 or
     1511      $is-rfc and ($pub-yearmonth >= 201001 or
    7921512      $rfcno=5741 or $rfcno=5742 or $rfcno=5743)
    7931513    )
     
    7971517<!-- for IDs, implement the change as 2009-11 -->
    7981518<xsl:variable name="abstract-first" select="(
    799     (/rfc/@number and $pub-yearmonth >= 200907)
     1519    ($is-rfc and $pub-yearmonth >= 200907)
    8001520    or
    801     (not(/rfc/@number) and $pub-yearmonth >= 200911)
     1521    (not($is-rfc) and $pub-yearmonth >= 200911)
    8021522  )" />
    8031523
    8041524<!-- RFC 7322 changed the placement of notes -->
    8051525<xsl:variable name="notes-follow-abstract" select="(
    806     (/rfc/@number and /rfc/@number >= 7200)
     1526    ($is-rfc and $rfcno >= 7200)
    8071527    or
    8081528    ($pub-yearmonth >= 201409)
     
    8121532<xsl:variable name="funding0" select="(
    8131533  $rfcno &gt; 2499) or
    814   (not(/rfc/@number) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 1999
     1534  (not($is-rfc) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 1999
    8151535  )" />
    8161536
    8171537<xsl:variable name="funding1" select="(
    8181538  $rfcno &gt; 4320) or
    819   (not(/rfc/@number) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 2006
     1539  (not($is-rfc) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 2006
    8201540  )" />
    8211541
    8221542<xsl:variable name="no-funding" select="$ipr-2007-08"/>
    8231543
    824 <xsl:variable name="no-copylong" select="$ipr-2008-11"/>
     1544<xsl:variable name="no-copylong" select="$ipr-2008-11 or /rfc/@ipr='none'"/>
    8251545
    8261546<!-- will document have an index -->
     
    8341554
    8351555
    836 <xsl:template match="text()[not(ancestor::artwork) and not(ancestor::sourcecode)]">
     1556<xsl:template match="text()[not(ancestor::artwork or ancestor::sourcecode)]">
    8371557  <xsl:variable name="ws" select="'&#9;&#10;&#13;&#32;'"/>
    8381558  <xsl:variable name="starts-with-ws" select="'' = translate(substring(.,1,1),$ws,'')"/>
     
    8421562  <xsl:message>Start: "<xsl:value-of select="$starts-with-ws"/>"</xsl:message>
    8431563  <xsl:message>  End: "<xsl:value-of select="$ends-with-ws"/>"</xsl:message> -->
    844   <xsl:if test="$starts-with-ws and (preceding-sibling::node() | parent::ed:ins | parent::ed:del)">
    845     <xsl:text> </xsl:text>
     1564  <xsl:if test="$starts-with-ws">
     1565    <xsl:variable name="t">
     1566      <xsl:for-each select="preceding-sibling::node()">
     1567        <xsl:choose>
     1568          <xsl:when test="self::text()">
     1569            <xsl:value-of select="."/>
     1570          </xsl:when>
     1571          <xsl:when test="self::*">
     1572            <xsl:apply-templates select="."/>
     1573          </xsl:when>
     1574          <xsl:otherwise/>
     1575        </xsl:choose>
     1576      </xsl:for-each>
     1577    </xsl:variable>
     1578    <xsl:variable name="text-before" select="normalize-space($t)"/>
     1579    <xsl:if test="$text-before!=''">
     1580      <xsl:text> </xsl:text>
     1581    </xsl:if>
    8461582  </xsl:if>
    8471583  <xsl:value-of select="$normalized"/>
    848   <xsl:if test="$ends-with-ws and $normalized!='' and (following-sibling::node() | parent::ed:ins | parent::ed:del)">
    849     <xsl:text> </xsl:text>
     1584  <xsl:if test="$ends-with-ws and $normalized!=''">
     1585    <xsl:variable name="t">
     1586      <xsl:for-each select="following-sibling::node()">
     1587        <xsl:choose>
     1588          <xsl:when test="self::text()">
     1589            <xsl:value-of select="."/>
     1590          </xsl:when>
     1591          <xsl:when test="self::*">
     1592            <xsl:apply-templates select="."/>
     1593          </xsl:when>
     1594          <xsl:otherwise/>
     1595        </xsl:choose>
     1596      </xsl:for-each>
     1597    </xsl:variable>
     1598    <xsl:variable name="text-after" select="normalize-space($t)"/>
     1599    <xsl:if test="$text-after!='' and substring($t,1,1)!=' '">
     1600      <xsl:text> </xsl:text>
     1601    </xsl:if>
    8501602  </xsl:if>
    8511603</xsl:template>
     
    8541606<xsl:template match="abstract">
    8551607  <xsl:call-template name="check-no-text-content"/>
    856   <section id="{$anchor-pref}abstract">
    857     <h2><a href="#{$anchor-pref}abstract">Abstract</a></h2>
     1608  <section>
     1609    <xsl:call-template name="copy-anchor"/>
     1610    <h2 id="{$anchor-pref}abstract"><a href="#{$anchor-pref}abstract">Abstract</a></h2>
     1611    <xsl:call-template name="insert-errata">
     1612      <xsl:with-param name="section" select="'abstract'"/>
     1613    </xsl:call-template>
    8581614    <xsl:apply-templates />
    8591615  </section>
     
    8811637  <xsl:variable name="v">
    8821638    <xsl:choose>
    883       <xsl:when test="@type='abnf' or @type='abnf2045' or @type='abnf2616' or @type='abnf7230' or @type='application/xml-dtd' or @type='inline' or @type='application/relax-ng-compact-syntax'">inline</xsl:when>
     1639      <xsl:when test="@type='abnf' or @type='abnf2045' or @type='abnf2616' or @type='abnf7230' or @type='application/xml-dtd' or @type='inline' or @type='application/relax-ng-compact-syntax' or @type='hex-dump'">inline</xsl:when>
    8841640      <xsl:when test="starts-with(@type,'message/http') and contains(@type,'msgtype=&quot;request&quot;')">text2</xsl:when>
    8851641      <xsl:when test="starts-with(@type,'message/http')">text</xsl:when>
    886       <xsl:when test="starts-with(@type,'drawing')">drawing</xsl:when>
    887       <xsl:when test="starts-with(@type,'text/plain') or @type='example' or @type='code' or @type='application/xml-dtd' or @type='application/json'">text</xsl:when>
     1642      <xsl:when test="@type='drawing' or @type='pdu' or type='ascii-art' or type='call-flow'">drawing</xsl:when>
     1643      <xsl:when test="self::sourcecode or @type='text/plain' or @type='example' or @type='http-message' or @type='code' or @type='xml' or @type='application/xml-dtd' or @type='application/json'">text</xsl:when>
    8881644      <xsl:otherwise/>
    8891645    </xsl:choose>
    890     <xsl:if test="@x:lang and $prettyprint-class!=''"><xsl:value-of select="concat(' ',$prettyprint-class)"/></xsl:if>
     1646    <xsl:if test="@x:lang and $prettyprint-class!=''">
     1647      <xsl:value-of select="concat(' ',$prettyprint-class)"/>
     1648      <xsl:if test="@x:lang!=''">
     1649        <xsl:value-of select="concat(' lang-',@x:lang)"/>
     1650      </xsl:if>
     1651    </xsl:if>
     1652    <xsl:if test="contains(@type,'abnf') and $prettyprint-class!=''">
     1653      <xsl:value-of select="concat(' ',$prettyprint-class,' lang-ietf_abnf')"/>
     1654    </xsl:if>
    8911655  </xsl:variable>
    8921656  <xsl:if test="normalize-space($v)!=''">
     
    8961660
    8971661<xsl:template name="insert-begin-code">
    898   <xsl:if test="@x:is-code-component='yes'">
    899     <pre class="ccmarker cct"><span>&lt;CODE BEGINS></span></pre>
     1662  <xsl:if test="(self::artwork and @x:is-code-component='yes') or (self::sourcecode and @markers='true')">
     1663    <pre class="ccmarker cct">
     1664      <xsl:text>&lt;CODE BEGINS></xsl:text>
     1665      <xsl:if test="self::sourcecode and @name">
     1666        <xsl:variable name="offending" select="translate(@name,concat($alnum,'-+.,;_~#'),'')"/>
     1667        <xsl:choose>
     1668          <xsl:when test="$offending!=''">
     1669            <xsl:call-template name="error">
     1670              <xsl:with-param name="msg">illegal characters in @name attribute '<xsl:value-of select="@name"/>': '<xsl:value-of select="$offending"/>'</xsl:with-param>
     1671            </xsl:call-template>
     1672          </xsl:when>
     1673          <xsl:otherwise>
     1674            <xsl:text> file "</xsl:text>
     1675            <xsl:value-of select="@name"/>
     1676            <xsl:text>"</xsl:text>
     1677          </xsl:otherwise>
     1678        </xsl:choose>
     1679      </xsl:if>
     1680    </pre>
    9001681  </xsl:if>
    9011682</xsl:template>
    9021683
    9031684<xsl:template name="insert-end-code">
    904   <xsl:if test="@x:is-code-component='yes'">
    905     <pre class="ccmarker ccb"><span>&lt;CODE ENDS></span></pre>
     1685  <xsl:if test="(self::artwork and @x:is-code-component='yes') or (self::sourcecode and @markers='true')">
     1686    <pre class="ccmarker ccb">&lt;CODE ENDS></pre>
    9061687  </xsl:if>
    9071688</xsl:template>
    9081689
    909 <xsl:template match="artwork[svg:svg]">
    910   <xsl:copy-of select="svg:svg"/>
     1690<xsl:template match="artset">
     1691  <xsl:call-template name="check-no-text-content"/>
     1692  <!-- see https://tools.ietf.org/html/draft-levkowetz-xml2rfc-v3-implementation-notes-08#section-3.1.1 -->
     1693  <xsl:choose>
     1694    <xsl:when test="artwork[svg:svg or normalize-space(.)='' or @src!='']">
     1695      <xsl:apply-templates select="artwork[svg:svg or normalize-space(.)='' or @src!=''][1]"/>
     1696    </xsl:when>
     1697    <xsl:when test="artwork">
     1698      <xsl:apply-templates select="artwork[1]"/>
     1699    </xsl:when>
     1700    <xsl:otherwise>
     1701      <xsl:call-template name="error">
     1702        <xsl:with-param name="msg">artset needs to contain at least one artwork child element</xsl:with-param>
     1703      </xsl:call-template>
     1704      <p>
     1705        <xsl:call-template name="attach-paragraph-number-as-id"/>
     1706        <xsl:if test="@anchor">
     1707          <span id="{@anchor}"/>
     1708        </xsl:if>
     1709      </p>
     1710    </xsl:otherwise>
     1711  </xsl:choose>
    9111712</xsl:template>
    9121713
     
    9411742  <xsl:if test="contains(.,'&#9;')">
    9421743    <xsl:call-template name="error">
    943       <xsl:with-param name="msg" select="'artwork contains HTAB character'"/>
     1744      <xsl:with-param name="msg" select="'artwork or sourcecode contains HTAB character'"/>
    9441745      <xsl:with-param name="inline" select="'no'"/>
    9451746    </xsl:call-template>
     
    9511752      </xsl:when>
    9521753      <xsl:otherwise>
    953         <xsl:value-of select="."/>
     1754        <xsl:call-template name="text-in-artwork"/>
    9541755      </xsl:otherwise>
    9551756    </xsl:choose>
    9561757  </xsl:variable>
    957   <xsl:choose>
    958     <xsl:when test="@align='right'">
    959       <div style="display:table; margin-left: auto; margin-right: 0em;">
    960         <xsl:call-template name="insert-begin-code"/>
    961         <pre style="margin-left: 0em;">
    962           <xsl:call-template name="add-artwork-class"/>
    963           <xsl:call-template name="insertInsDelClass"/>
    964           <xsl:copy-of select="$display"/>
    965         </pre>
    966         <xsl:call-template name="insert-end-code"/>
    967       </div>
    968     </xsl:when>
    969     <xsl:when test="@align='center'">
    970       <div style="display:table; margin-left: auto; margin-right: auto;">
    971         <xsl:call-template name="insert-begin-code"/>
    972         <pre style="margin-left: 0em;">
    973           <xsl:call-template name="add-artwork-class"/>
    974           <xsl:call-template name="insertInsDelClass"/>
    975           <xsl:copy-of select="$display"/>
    976         </pre>
    977         <xsl:call-template name="insert-end-code"/>
    978       </div>
    979     </xsl:when>
    980     <xsl:otherwise>
    981       <xsl:call-template name="insert-begin-code"/>
    982       <pre>
    983         <xsl:call-template name="add-artwork-class"/>
    984         <xsl:call-template name="insertInsDelClass"/>
    985         <xsl:copy-of select="$display"/>
    986       </pre>
    987       <xsl:call-template name="insert-end-code"/>
    988     </xsl:otherwise>
    989   </xsl:choose>
     1758  <xsl:variable name="divstyle">
     1759    <xsl:choose>
     1760      <xsl:when test="self::artwork and @align='right'">display:table; margin-left: auto; margin-right: 0em;</xsl:when>
     1761      <xsl:when test="self::artwork and @align='center'">display:table; margin-left: auto; margin-right: auto;</xsl:when>
     1762      <xsl:otherwise/>
     1763    </xsl:choose>
     1764  </xsl:variable>
     1765  <xsl:variable name="prestyle">
     1766    <xsl:choose>
     1767      <xsl:when test="self::artwork and (@align='right' or @align='center')">margin-left: 0em;</xsl:when>
     1768      <xsl:otherwise/>
     1769    </xsl:choose>
     1770  </xsl:variable>
     1771  <xsl:variable name="anch-container">
     1772    <xsl:choose>
     1773      <xsl:when test="ancestor::t">span</xsl:when>
     1774      <xsl:otherwise>div</xsl:otherwise>
     1775    </xsl:choose>
     1776  </xsl:variable>
     1777  <xsl:element name="{$anch-container}">
     1778    <xsl:choose>
     1779      <xsl:when test="parent::artset">
     1780        <xsl:for-each select="..">
     1781          <xsl:call-template name="attach-paragraph-number-as-id"/>
     1782        </xsl:for-each>
     1783      </xsl:when>
     1784      <xsl:otherwise>
     1785        <xsl:call-template name="attach-paragraph-number-as-id"/>
     1786      </xsl:otherwise>
     1787    </xsl:choose>
     1788    <xsl:if test="$divstyle!=''">
     1789      <xsl:attribute name="style"><xsl:value-of select="$divstyle"/></xsl:attribute>
     1790    </xsl:if>
     1791    <xsl:call-template name="insert-begin-code"/>
     1792    <pre>
     1793      <xsl:call-template name="copy-anchor"/>
     1794      <xsl:if test="$prestyle!=''">
     1795        <xsl:attribute name="style"><xsl:value-of select="$prestyle"/></xsl:attribute>
     1796      </xsl:if>
     1797      <xsl:call-template name="add-artwork-class"/>
     1798      <xsl:call-template name="insertInsDelClass"/>
     1799      <xsl:copy-of select="$display"/>
     1800    </pre>
     1801    <xsl:call-template name="insert-end-code"/>
     1802  </xsl:element>
    9901803  <xsl:call-template name="check-artwork-width">
    9911804    <xsl:with-param name="content"><xsl:apply-templates/></xsl:with-param>
     
    9941807</xsl:template>
    9951808
    996 <!-- special case for first text node in artwork -->
    997 <xsl:template match="artwork/text()[1]">
     1809<xsl:template name="text-in-artwork">
     1810  <xsl:param name="content" select="."/>
     1811  <xsl:choose>
     1812    <xsl:when test="contains($content,'&#9;')">
     1813      <xsl:call-template name="text-in-artwork">
     1814        <xsl:with-param name="content" select="substring-before($content,'&#9;')"/>
     1815      </xsl:call-template>
     1816      <span class="error" title="HTAB character">&#x2409;</span>
     1817      <xsl:call-template name="text-in-artwork">
     1818        <xsl:with-param name="content" select="substring-after($content,'&#9;')"/>
     1819      </xsl:call-template>
     1820    </xsl:when>
     1821    <xsl:otherwise>
     1822      <xsl:value-of select="$content"/>
     1823    </xsl:otherwise>
     1824  </xsl:choose>
     1825</xsl:template>
     1826
     1827<!-- special case for first text node in artwork or sourcecode -->
     1828<xsl:template match="artwork/text()[1]|sourcecode/text()[1]" priority="9">
    9981829  <xsl:choose>
    9991830    <xsl:when test="starts-with(.,'&#10;')">
    10001831      <!-- reduce leading whitespace -->
    1001       <xsl:value-of select="substring(.,2)"/>
     1832      <xsl:call-template name="text-in-artwork">
     1833        <xsl:with-param name="content" select="substring(.,2)"/>
     1834      </xsl:call-template>
    10021835    </xsl:when>
    10031836    <xsl:otherwise>
    1004       <xsl:value-of select="."/>
     1837      <xsl:call-template name="text-in-artwork"/>
    10051838    </xsl:otherwise>
    10061839  </xsl:choose>
    10071840</xsl:template>
    10081841
     1842<!-- other text nodes in artwork or sourcecode -->
     1843<xsl:template match="artwork//text()|sourcecode//text()">
     1844  <xsl:call-template name="text-in-artwork"/>
     1845</xsl:template>
    10091846
    10101847<xsl:template name="check-artwork-width">
     
    10431880</xsl:template>
    10441881
    1045 <xsl:template match="artwork[@src and starts-with(@type,'image/')]">
    1046   <p>
     1882<xsl:template match="artwork[xi:include]" priority="9">
     1883  <xsl:variable name="resolved" xmlns="">
     1884    <xsl:element name="artwork" namespace="">
     1885      <xsl:copy-of select="@*"/>
     1886      <xsl:for-each select="node()">
     1887        <xsl:choose>
     1888          <xsl:when test="self::xi:include">
     1889            <xsl:if test="(@parse and @parse!='xml') or @xpointer">
     1890              <xsl:call-template name="error">
     1891                <xsl:with-param name="msg" select="'Unsupported attributes on x:include element'"/>
     1892              </xsl:call-template>
     1893            </xsl:if>
     1894            <xsl:copy-of select="document(@href)"/>
     1895          </xsl:when>
     1896          <xsl:otherwise>
     1897            <xsl:copy-of select="."/>
     1898          </xsl:otherwise>
     1899        </xsl:choose>
     1900      </xsl:for-each>
     1901    </xsl:element>
     1902  </xsl:variable>
     1903  <xsl:apply-templates select="exslt:node-set($resolved)/*"/>
     1904</xsl:template>
     1905
     1906<xsl:template match="artwork[@src and starts-with(@type,'image/') or @type='svg']|artwork[svg:svg]">
     1907  <xsl:variable name="class">
     1908    <xsl:value-of select="$css-artwork"/>
     1909    <xsl:text> </xsl:text>
     1910    <xsl:if test="svg:svg">
     1911      <xsl:value-of select="$css-art-svg"/>
     1912    </xsl:if>
    10471913    <xsl:choose>
    1048       <xsl:when test="@align='center'">
    1049         <xsl:attribute name="style">text-align: center</xsl:attribute>
    1050       </xsl:when>
    1051       <xsl:when test="@align='right'">
    1052         <xsl:attribute name="style">text-align: right</xsl:attribute>
    1053       </xsl:when>
     1914      <xsl:when test="@align='center'"><xsl:text> </xsl:text><xsl:value-of select="$css-center"/></xsl:when>
     1915      <xsl:when test="@align='right'"><xsl:text> </xsl:text><xsl:value-of select="$css-right"/></xsl:when>
    10541916      <xsl:otherwise/>
    10551917    </xsl:choose>
     1918  </xsl:variable>
     1919  <div class="{normalize-space($class)}">
    10561920    <xsl:choose>
    1057       <xsl:when test="@type='image/svg+xml'">
    1058         <object data="{@src}" type="image/svg+xml">
    1059           <xsl:choose>
    1060             <xsl:when test="@width!='' or @height!=''">
    1061               <xsl:copy-of select="@width|@height"/>
    1062             </xsl:when>
    1063             <xsl:otherwise xmlns:svg="http://www.w3.org/2000/svg">
    1064               <!-- try to find width and height from SVG -->
    1065               <xsl:variable name="svg" select="document(@src)"/>
    1066               <xsl:for-each select="$svg/svg:svg/@width|$svg/svg:svg/@height">
    1067                 <!-- strip out the units, cross the fingers pixels are meant -->
    1068                 <xsl:attribute name="{local-name()}">
    1069                   <xsl:value-of select="translate(.,concat($ucase,$lcase),'')"/>
    1070                 </xsl:attribute>
    1071               </xsl:for-each>
    1072             </xsl:otherwise>
    1073           </xsl:choose>
    1074           <xsl:apply-templates/>
    1075         </object>
     1921      <xsl:when test="parent::artset">
     1922        <xsl:for-each select="..">
     1923          <xsl:call-template name="attach-paragraph-number-as-id"/>
     1924        </xsl:for-each>
     1925      </xsl:when>
     1926      <xsl:otherwise>
     1927        <xsl:call-template name="attach-paragraph-number-as-id"/>
     1928      </xsl:otherwise>
     1929    </xsl:choose>
     1930    <xsl:choose>
     1931      <xsl:when test="svg:svg">
     1932        <xsl:choose>
     1933          <xsl:when test="parent::artset and ../@anchor">
     1934            <div id="{../@anchor}">
     1935              <xsl:apply-templates select="svg:svg" mode="embed-svg"/>
     1936            </div>
     1937          </xsl:when>
     1938          <xsl:when test="parent::artset and ../artwork/@anchor">
     1939            <div id="{../artwork[@anchor][1]/@anchor}">
     1940              <xsl:apply-templates select="svg:svg" mode="embed-svg"/>
     1941            </div>
     1942          </xsl:when>
     1943          <xsl:when test="@anchor">
     1944            <div id="{@anchor}">
     1945              <xsl:apply-templates select="svg:svg" mode="embed-svg"/>
     1946            </div>
     1947          </xsl:when>
     1948          <xsl:otherwise>
     1949            <xsl:apply-templates select="svg:svg" mode="embed-svg"/>
     1950          </xsl:otherwise>
     1951        </xsl:choose>
    10761952      </xsl:when>
    10771953      <xsl:otherwise>
     
    10991975      </xsl:otherwise>
    11001976    </xsl:choose>
    1101   </p>
    1102 </xsl:template>
    1103 
    1104 <xsl:template match="author">
     1977  </div>
     1978</xsl:template>
     1979
     1980<!-- copy SVG content without inserted line no information -->
     1981<xsl:template match="node()|@*" mode="embed-svg">
     1982  <xsl:copy><xsl:apply-templates select="node()|@*" mode="embed-svg"/></xsl:copy>
     1983</xsl:template>
     1984<xsl:template match="processing-instruction('rfc-ext')[contains(.,'line-no=')]" mode="embed-svg"/>
     1985
     1986<xsl:template match="/" mode="embed-svg">
     1987        <xsl:copy><xsl:apply-templates select="node()"  mode="embed-svg"/></xsl:copy>
     1988</xsl:template>
     1989
     1990<xsl:template match="contact[ancestor::t]">
     1991  <xsl:if test="*">
     1992    <xsl:call-template name="info">
     1993      <xsl:with-param name="msg">Ignoring child elements of &lt;contact> when used inside &lt;t>.</xsl:with-param>
     1994    </xsl:call-template>
     1995  </xsl:if>
     1996  <xsl:value-of select="@fullname"/>
     1997  <xsl:if test="@asciiFullname">
     1998    <xsl:text> (</xsl:text>
     1999    <xsl:value-of select="@asciiFullname"/>
     2000    <xsl:text>)</xsl:text>
     2001  </xsl:if>
     2002</xsl:template>
     2003
     2004<xsl:template match="author|contact|x:contributor">
    11052005  <xsl:call-template name="check-no-text-content"/>
    11062006
    1107   <p>
    1108     <b><xsl:value-of select="@fullname" /></b>
    1109     <xsl:if test="@role">
    1110       (<xsl:value-of select="@role" />)
     2007  <address>
     2008    <xsl:call-template name="emit-author"/>
     2009
     2010    <xsl:if test="@asciiFullname!='' or organization/@ascii!='' or address/postal/*/@ascii">
     2011      <br/><br/>
     2012      <em>Additional contact information:</em>
     2013      <br/>
     2014      <xsl:call-template name="emit-author">
     2015        <xsl:with-param name="ascii" select="false()"/>
     2016      </xsl:call-template>
    11112017    </xsl:if>
    1112     <!-- annotation support for Martin "uuml" Duerst -->
    1113     <xsl:if test="@x:annotation">
     2018  </address>
     2019</xsl:template>
     2020
     2021<xsl:template name="emit-postal-line">
     2022  <xsl:param name="prefix"/>
     2023  <xsl:param name="value"/>
     2024  <xsl:param name="values"/>
     2025  <xsl:param name="link"/>
     2026  <xsl:param name="annotation"/>
     2027
     2028  <xsl:if test="normalize-space($value)!='' or $values">
     2029    <br/>
     2030    <xsl:if test="$prefix!=''"><xsl:value-of select="$prefix"/>: </xsl:if>
     2031    <xsl:choose>
     2032      <xsl:when test="$values">
     2033        <xsl:for-each select="exslt:node-set($values)/*">
     2034          <xsl:choose>
     2035            <xsl:when test="@href">
     2036              <a href="{@href}"><xsl:value-of select="normalize-space(.)"/></a>
     2037            </xsl:when>
     2038            <xsl:otherwise>
     2039              <xsl:value-of select="normalize-space(.)"/>
     2040            </xsl:otherwise>
     2041          </xsl:choose>
     2042          <xsl:if test="position()!=last()">, </xsl:if>
     2043        </xsl:for-each>
     2044      </xsl:when>
     2045      <xsl:when test="$link!=''">
     2046        <a href="{$link}"><xsl:value-of select="normalize-space($value)"/></a>
     2047      </xsl:when>
     2048      <xsl:otherwise>
     2049        <xsl:value-of select="normalize-space($value)"/>
     2050      </xsl:otherwise>
     2051    </xsl:choose>
     2052    <xsl:if test="$annotation!=''">
    11142053      <xsl:text> </xsl:text>
    1115       <i><xsl:value-of select="@x:annotation"/></i>
     2054      <i><xsl:value-of select="$annotation"/></i>
    11162055    </xsl:if>
    1117 
    1118     <xsl:if test="normalize-space(organization) != ''">
    1119       <br/>
    1120       <xsl:value-of select="organization" />
     2056  </xsl:if>
     2057</xsl:template>
     2058
     2059<xsl:template name="emit-author-details">
     2060  <xsl:param name="ascii"/>
     2061  <xsl:for-each select="address">
     2062    <xsl:choose>
     2063      <xsl:when test="position() != 1">
     2064        <xsl:call-template name="error">
     2065          <xsl:with-param name="msg">Multiple &lt;address> elements inside &lt;author>, all but the first ignored.</xsl:with-param>
     2066        </xsl:call-template>
     2067      </xsl:when>
     2068      <xsl:otherwise>
     2069        <xsl:call-template name="emit-author-details2">
     2070          <xsl:with-param name="ascii" select="$ascii"/>
     2071        </xsl:call-template>
     2072      </xsl:otherwise>
     2073    </xsl:choose>
     2074  </xsl:for-each>
     2075</xsl:template>
     2076
     2077<xsl:template name="emit-postal-city">
     2078  <xsl:param name="ascii"/>
     2079  <xsl:call-template name="emit-postal-line">
     2080    <xsl:with-param name="value">
     2081      <xsl:if test="city">
     2082        <xsl:call-template name="extract-normalized">
     2083          <xsl:with-param name="node" select="city"/>
     2084          <xsl:with-param name="ascii" select="$ascii"/>
     2085        </xsl:call-template>
     2086      </xsl:if>
     2087    </xsl:with-param>
     2088  </xsl:call-template>
     2089</xsl:template>
     2090
     2091<xsl:template name="emit-postal-city-code">
     2092  <xsl:param name="ascii"/>
     2093  <xsl:param name="prefix"/>
     2094  <xsl:variable name="city">
     2095    <xsl:if test="city">
     2096      <xsl:call-template name="extract-normalized">
     2097        <xsl:with-param name="node" select="city"/>
     2098        <xsl:with-param name="ascii" select="$ascii"/>
     2099      </xsl:call-template>
    11212100    </xsl:if>
    1122 
    1123     <xsl:if test="address/postal">
    1124       <xsl:for-each select="address/postal/street">
    1125         <xsl:variable name="street">
    1126           <xsl:call-template name="extract-normalized">
    1127             <xsl:with-param name="name" select="'street'"/>
     2101  </xsl:variable>
     2102  <xsl:variable name="code">
     2103    <xsl:if test="code">
     2104      <xsl:call-template name="extract-normalized">
     2105        <xsl:with-param name="node" select="code"/>
     2106        <xsl:with-param name="ascii" select="$ascii"/>
     2107      </xsl:call-template>
     2108    </xsl:if>
     2109  </xsl:variable>
     2110  <xsl:call-template name="emit-postal-line">
     2111    <xsl:with-param name="value">
     2112      <xsl:value-of select="$city"/>
     2113      <xsl:text> </xsl:text>
     2114      <xsl:if test="$code!=''">
     2115        <xsl:choose>
     2116          <xsl:when test="$prefix!='' and starts-with($code,$prefix)">
     2117            <xsl:call-template name="warning">
     2118              <xsl:with-param name="msg">Prefix '<xsl:value-of select="$prefix"/>' on &lt;code> '<xsl:value-of select="$code"/>' will be inserted automatically.</xsl:with-param>
     2119            </xsl:call-template>
     2120          </xsl:when>
     2121          <xsl:otherwise>
     2122            <xsl:value-of select="$prefix"/>
     2123          </xsl:otherwise>
     2124        </xsl:choose>
     2125        <xsl:value-of select="$code"/>
     2126      </xsl:if>
     2127    </xsl:with-param>
     2128  </xsl:call-template>
     2129</xsl:template>
     2130
     2131<xsl:template name="emit-postal-city-region-code">
     2132  <xsl:param name="ascii"/>
     2133  <xsl:variable name="city">
     2134    <xsl:if test="city">
     2135      <xsl:call-template name="extract-normalized">
     2136        <xsl:with-param name="node" select="city"/>
     2137        <xsl:with-param name="ascii" select="$ascii"/>
     2138      </xsl:call-template>
     2139    </xsl:if>
     2140  </xsl:variable>
     2141  <xsl:variable name="region">
     2142    <xsl:if test="region">
     2143      <xsl:call-template name="extract-normalized">
     2144        <xsl:with-param name="node" select="region"/>
     2145        <xsl:with-param name="ascii" select="$ascii"/>
     2146      </xsl:call-template>
     2147    </xsl:if>
     2148  </xsl:variable>
     2149  <xsl:variable name="code">
     2150    <xsl:if test="code">
     2151      <xsl:call-template name="extract-normalized">
     2152        <xsl:with-param name="node" select="code"/>
     2153        <xsl:with-param name="ascii" select="$ascii"/>
     2154      </xsl:call-template>
     2155    </xsl:if>
     2156  </xsl:variable>
     2157  <xsl:call-template name="emit-postal-line">
     2158    <xsl:with-param name="value" select="concat($city,' ',$region,' ',$code)"/>
     2159  </xsl:call-template>
     2160</xsl:template>
     2161
     2162<xsl:template name="emit-postal-code-city-region">
     2163  <xsl:param name="ascii"/>
     2164  <xsl:param name="cr-delim" select="' '"/>
     2165  <xsl:variable name="city">
     2166    <xsl:if test="city">
     2167      <xsl:call-template name="extract-normalized">
     2168        <xsl:with-param name="node" select="city"/>
     2169        <xsl:with-param name="ascii" select="$ascii"/>
     2170      </xsl:call-template>
     2171    </xsl:if>
     2172  </xsl:variable>
     2173  <xsl:variable name="region">
     2174    <xsl:if test="region">
     2175      <xsl:call-template name="extract-normalized">
     2176        <xsl:with-param name="node" select="region"/>
     2177        <xsl:with-param name="ascii" select="$ascii"/>
     2178      </xsl:call-template>
     2179    </xsl:if>
     2180  </xsl:variable>
     2181  <xsl:variable name="code">
     2182    <xsl:if test="code">
     2183      <xsl:call-template name="extract-normalized">
     2184        <xsl:with-param name="node" select="code"/>
     2185        <xsl:with-param name="ascii" select="$ascii"/>
     2186      </xsl:call-template>
     2187    </xsl:if>
     2188  </xsl:variable>
     2189  <xsl:call-template name="emit-postal-line">
     2190    <xsl:with-param name="value" select="concat($code,' ',$city,$cr-delim,$region)"/>
     2191  </xsl:call-template>
     2192</xsl:template>
     2193
     2194<xsl:template name="emit-postal-city-comma-region-code">
     2195  <xsl:param name="ascii"/>
     2196  <xsl:variable name="city">
     2197    <xsl:if test="city">
     2198      <xsl:call-template name="extract-normalized">
     2199        <xsl:with-param name="node" select="city"/>
     2200        <xsl:with-param name="ascii" select="$ascii"/>
     2201      </xsl:call-template>
     2202    </xsl:if>
     2203  </xsl:variable>
     2204  <xsl:variable name="region">
     2205    <xsl:if test="region">
     2206      <xsl:call-template name="extract-normalized">
     2207        <xsl:with-param name="node" select="region"/>
     2208        <xsl:with-param name="ascii" select="$ascii"/>
     2209      </xsl:call-template>
     2210    </xsl:if>
     2211  </xsl:variable>
     2212  <xsl:variable name="code">
     2213    <xsl:if test="code">
     2214      <xsl:call-template name="extract-normalized">
     2215        <xsl:with-param name="node" select="code"/>
     2216        <xsl:with-param name="ascii" select="$ascii"/>
     2217      </xsl:call-template>
     2218    </xsl:if>
     2219  </xsl:variable>
     2220  <xsl:call-template name="emit-postal-line">
     2221    <xsl:with-param name="value">
     2222      <xsl:value-of select="$city"/>
     2223      <xsl:variable name="region-and-code" select="concat($region,' ',$code)"/>
     2224      <xsl:if test="normalize-space($region-and-code)!=''">
     2225        <xsl:if test="$city!=''">
     2226          <xsl:text>, </xsl:text>
     2227        </xsl:if>
     2228        <xsl:value-of select="normalize-space($region-and-code)"/>
     2229      </xsl:if>
     2230    </xsl:with-param>
     2231  </xsl:call-template>
     2232</xsl:template>
     2233
     2234<xsl:template name="emit-postal-city-minus-region">
     2235  <xsl:param name="ascii"/>
     2236  <xsl:variable name="city">
     2237    <xsl:if test="city">
     2238      <xsl:call-template name="extract-normalized">
     2239        <xsl:with-param name="node" select="city"/>
     2240        <xsl:with-param name="ascii" select="$ascii"/>
     2241      </xsl:call-template>
     2242    </xsl:if>
     2243  </xsl:variable>
     2244  <xsl:variable name="region">
     2245    <xsl:if test="region">
     2246      <xsl:call-template name="extract-normalized">
     2247        <xsl:with-param name="node" select="region"/>
     2248        <xsl:with-param name="ascii" select="$ascii"/>
     2249      </xsl:call-template>
     2250    </xsl:if>
     2251  </xsl:variable>
     2252  <xsl:call-template name="emit-postal-line">
     2253    <xsl:with-param name="value">
     2254      <xsl:value-of select="$city"/>
     2255      <xsl:if test="$region!=''">
     2256        <xsl:if test="$city!=''">
     2257          <xsl:text>-</xsl:text>
     2258        </xsl:if>
     2259        <xsl:value-of select="$region"/>
     2260      </xsl:if>
     2261    </xsl:with-param>
     2262  </xsl:call-template>
     2263</xsl:template>
     2264
     2265<xsl:template name="emit-postal-cityarea">
     2266  <xsl:param name="ascii"/>
     2267  <xsl:if test="cityarea">
     2268    <xsl:call-template name="emit-postal-line">
     2269      <xsl:with-param name="value">
     2270        <xsl:call-template name="extract-normalized">
     2271          <xsl:with-param name="node" select="cityarea"/>
     2272          <xsl:with-param name="ascii" select="$ascii"/>
     2273        </xsl:call-template>
     2274      </xsl:with-param>
     2275    </xsl:call-template>
     2276  </xsl:if>
     2277</xsl:template>
     2278
     2279<xsl:template name="emit-postal-cityarea-city">
     2280  <xsl:param name="ascii"/>
     2281  <xsl:variable name="cityarea">
     2282    <xsl:if test="cityarea">
     2283      <xsl:call-template name="extract-normalized">
     2284        <xsl:with-param name="node" select="cityarea"/>
     2285        <xsl:with-param name="ascii" select="$ascii"/>
     2286      </xsl:call-template>
     2287    </xsl:if>
     2288  </xsl:variable>
     2289  <xsl:variable name="city">
     2290    <xsl:if test="city">
     2291      <xsl:call-template name="extract-normalized">
     2292        <xsl:with-param name="node" select="city"/>
     2293        <xsl:with-param name="ascii" select="$ascii"/>
     2294      </xsl:call-template>
     2295    </xsl:if>
     2296  </xsl:variable>
     2297  <xsl:call-template name="emit-postal-line">
     2298    <xsl:with-param name="value" select="concat($cityarea,' ',$city)"/>
     2299  </xsl:call-template>
     2300</xsl:template>
     2301
     2302<xsl:template name="emit-postal-code">
     2303  <xsl:param name="ascii"/>
     2304  <xsl:param name="prefix"/>
     2305  <xsl:if test="code">
     2306    <xsl:variable name="code">
     2307      <xsl:call-template name="extract-normalized">
     2308        <xsl:with-param name="node" select="code"/>
     2309        <xsl:with-param name="ascii" select="$ascii"/>
     2310      </xsl:call-template>
     2311    </xsl:variable>
     2312    <xsl:call-template name="emit-postal-line">
     2313      <xsl:with-param name="value">
     2314      <xsl:if test="$code!=''">
     2315        <xsl:choose>
     2316          <xsl:when test="$prefix!='' and starts-with($code,$prefix)">
     2317            <xsl:call-template name="warning">
     2318              <xsl:with-param name="msg">Prefix '<xsl:value-of select="$prefix"/>' on &lt;code> '<xsl:value-of select="$code"/>' will be inserted automatically.</xsl:with-param>
     2319            </xsl:call-template>
     2320          </xsl:when>
     2321          <xsl:otherwise>
     2322            <xsl:value-of select="$prefix"/>
     2323          </xsl:otherwise>
     2324        </xsl:choose>
     2325        <xsl:value-of select="$code"/>
     2326      </xsl:if>
     2327      </xsl:with-param>
     2328    </xsl:call-template>
     2329  </xsl:if>
     2330</xsl:template>
     2331
     2332<xsl:template name="emit-postal-country">
     2333  <xsl:param name="ascii"/>
     2334  <xsl:if test="country">
     2335    <xsl:call-template name="emit-postal-line">
     2336      <xsl:with-param name="value">
     2337        <xsl:call-template name="extract-normalized">
     2338          <xsl:with-param name="node" select="country"/>
     2339          <xsl:with-param name="ascii" select="$ascii"/>
     2340        </xsl:call-template>
     2341      </xsl:with-param>
     2342    </xsl:call-template>
     2343  </xsl:if>
     2344</xsl:template>
     2345
     2346<xsl:template name="emit-postal-code-city">
     2347  <xsl:param name="ascii"/>
     2348  <xsl:param name="prefix"/>
     2349  <xsl:variable name="city">
     2350    <xsl:if test="city">
     2351      <xsl:call-template name="extract-normalized">
     2352        <xsl:with-param name="node" select="city"/>
     2353        <xsl:with-param name="ascii" select="$ascii"/>
     2354      </xsl:call-template>
     2355    </xsl:if>
     2356  </xsl:variable>
     2357  <xsl:variable name="code">
     2358    <xsl:if test="code">
     2359      <xsl:call-template name="extract-normalized">
     2360        <xsl:with-param name="node" select="code"/>
     2361        <xsl:with-param name="ascii" select="$ascii"/>
     2362      </xsl:call-template>
     2363    </xsl:if>
     2364  </xsl:variable>
     2365  <xsl:call-template name="emit-postal-line">
     2366    <xsl:with-param name="value">
     2367      <xsl:if test="$code!=''">
     2368        <xsl:choose>
     2369          <xsl:when test="$prefix!='' and starts-with($code,$prefix)">
     2370            <xsl:call-template name="warning">
     2371              <xsl:with-param name="msg">Prefix '<xsl:value-of select="$prefix"/>' on &lt;code> '<xsl:value-of select="$code"/>' will be inserted automatically.</xsl:with-param>
     2372            </xsl:call-template>
     2373          </xsl:when>
     2374          <xsl:otherwise>
     2375            <xsl:value-of select="$prefix"/>
     2376          </xsl:otherwise>
     2377        </xsl:choose>
     2378        <xsl:value-of select="$code"/>
     2379      </xsl:if>
     2380      <xsl:text> </xsl:text>
     2381      <xsl:value-of select="$city"/>
     2382    </xsl:with-param>
     2383  </xsl:call-template>
     2384</xsl:template>
     2385
     2386<xsl:template name="emit-postal-region">
     2387  <xsl:param name="ascii"/>
     2388  <xsl:if test="region">
     2389    <xsl:call-template name="emit-postal-line">
     2390      <xsl:with-param name="value">
     2391        <xsl:call-template name="extract-normalized">
     2392          <xsl:with-param name="node" select="region"/>
     2393          <xsl:with-param name="ascii" select="$ascii"/>
     2394        </xsl:call-template>
     2395      </xsl:with-param>
     2396    </xsl:call-template>
     2397  </xsl:if>
     2398</xsl:template>
     2399
     2400<xsl:template name="emit-postal-region-city-cityarea">
     2401  <xsl:param name="ascii"/>
     2402  <xsl:variable name="city">
     2403    <xsl:if test="city">
     2404      <xsl:call-template name="extract-normalized">
     2405        <xsl:with-param name="node" select="city"/>
     2406        <xsl:with-param name="ascii" select="$ascii"/>
     2407      </xsl:call-template>
     2408    </xsl:if>
     2409  </xsl:variable>
     2410  <xsl:variable name="region">
     2411    <xsl:if test="region">
     2412      <xsl:call-template name="extract-normalized">
     2413        <xsl:with-param name="node" select="region"/>
     2414        <xsl:with-param name="ascii" select="$ascii"/>
     2415      </xsl:call-template>
     2416    </xsl:if>
     2417  </xsl:variable>
     2418  <xsl:variable name="cityarea">
     2419    <xsl:if test="cityarea">
     2420      <xsl:call-template name="extract-normalized">
     2421        <xsl:with-param name="node" select="cityarea"/>
     2422        <xsl:with-param name="ascii" select="$ascii"/>
     2423      </xsl:call-template>
     2424    </xsl:if>
     2425  </xsl:variable>
     2426  <xsl:call-template name="emit-postal-line">
     2427    <xsl:with-param name="value" select="concat($region,' ',$city,' ',$cityarea)"/>
     2428  </xsl:call-template>
     2429</xsl:template>
     2430
     2431<xsl:template name="emit-postal-region-code">
     2432  <xsl:param name="ascii"/>
     2433  <xsl:variable name="region">
     2434    <xsl:if test="region">
     2435      <xsl:call-template name="extract-normalized">
     2436        <xsl:with-param name="node" select="region"/>
     2437        <xsl:with-param name="ascii" select="$ascii"/>
     2438      </xsl:call-template>
     2439    </xsl:if>
     2440  </xsl:variable>
     2441  <xsl:variable name="code">
     2442    <xsl:if test="code">
     2443      <xsl:call-template name="extract-normalized">
     2444        <xsl:with-param name="node" select="code"/>
     2445        <xsl:with-param name="ascii" select="$ascii"/>
     2446      </xsl:call-template>
     2447    </xsl:if>
     2448  </xsl:variable>
     2449  <xsl:call-template name="emit-postal-line">
     2450    <xsl:with-param name="value" select="concat($region,' ',$code)"/>
     2451  </xsl:call-template>
     2452</xsl:template>
     2453
     2454<xsl:template name="emit-postal-region-comma-code">
     2455  <xsl:param name="ascii"/>
     2456  <xsl:variable name="region">
     2457    <xsl:if test="region">
     2458      <xsl:call-template name="extract-normalized">
     2459        <xsl:with-param name="node" select="region"/>
     2460        <xsl:with-param name="ascii" select="$ascii"/>
     2461      </xsl:call-template>
     2462    </xsl:if>
     2463  </xsl:variable>
     2464  <xsl:variable name="code">
     2465    <xsl:if test="code">
     2466      <xsl:call-template name="extract-normalized">
     2467        <xsl:with-param name="node" select="code"/>
     2468        <xsl:with-param name="ascii" select="$ascii"/>
     2469      </xsl:call-template>
     2470    </xsl:if>
     2471  </xsl:variable>
     2472  <xsl:call-template name="emit-postal-line">
     2473    <xsl:with-param name="value">
     2474      <xsl:value-of select="$region"/>
     2475      <xsl:if test="$region!='' and $code!=''">, </xsl:if>
     2476      <xsl:value-of select="$code"/>
     2477    </xsl:with-param>
     2478  </xsl:call-template>
     2479</xsl:template>
     2480
     2481<xsl:template name="emit-postal-street">
     2482  <xsl:param name="ascii"/>
     2483  <xsl:for-each select="extaddr">
     2484    <xsl:call-template name="emit-postal-line">
     2485      <xsl:with-param name="value">
     2486        <xsl:call-template name="extract-normalized">
     2487          <xsl:with-param name="ascii" select="$ascii"/>
     2488        </xsl:call-template>
     2489      </xsl:with-param>
     2490    </xsl:call-template>
     2491  </xsl:for-each>
     2492  <xsl:for-each select="street">
     2493    <xsl:call-template name="emit-postal-line">
     2494      <xsl:with-param name="value">
     2495        <xsl:call-template name="extract-normalized">
     2496          <xsl:with-param name="ascii" select="$ascii"/>
     2497        </xsl:call-template>
     2498      </xsl:with-param>