source: rfc2629xslt/rfc2629toXHTML.xslt @ 10

Last change on this file since 10 was 6, checked in by fielding@…, 15 years ago

XSLT stylesheet for enhanced RFC2629 xml2rfc output as HTML.
By Julian Reschke

Obtained from: wget -N http://www.greenbytes.de/tech/webdav/rfc2629xslt.zip

  • Property svn:eol-style set to native
File size: 174.9 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!--Auto-generated from rfc2629.xslt through HTMLtoXHTML.xslt-->
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ed="http://greenbytes.de/2002/rfcedit" xmlns:exslt="http://exslt.org/common" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rcf2629.xslt" xmlns:saxon="http://icl.com/saxon" xmlns:x="http://purl.org/net/xml2rfc/ext" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="ed exslt msxsl myns saxon x xhtml">
4
5<xsl:strip-space elements="back front list middle rfc section"/>                
6               
7<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" method="xml"/>
8
9<!-- process some of the processing instructions supported by Marshall T. Rose's
10     xml2rfc sofware, see <http://xml.resource.org/> -->
11
12<!-- delimiters in PIs -->
13<xsl:variable name="quote-chars">"'</xsl:variable>    
14     
15<!-- rfc comments PI -->
16
17<xsl:param name="xml2rfc-comments" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'comments=')], concat($quote-chars,' '), ''),         'comments=')"/>
18
19<!-- rfc compact PI -->
20
21<xsl:param name="xml2rfc-compact" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'compact=')], concat($quote-chars,' '), ''),         'compact=')"/>
22
23<!-- rfc footer PI -->
24
25<xsl:param name="xml2rfc-footer" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'footer=')], concat($quote-chars,' '), ''),         'footer=')"/>
26
27<!-- rfc header PI -->
28
29<xsl:param name="xml2rfc-header" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'header=')], concat($quote-chars,' '), ''),         'header=')"/>
30
31<!-- rfc inline PI -->
32
33<xsl:param name="xml2rfc-inline" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'inline=')], concat($quote-chars,' '), ''),         'inline=')"/>
34
35<!-- rfc strict PI -->
36
37<xsl:param name="xml2rfc-strict" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'strict=')], concat($quote-chars,' '), ''),         'strict=')"/>
38
39<!-- include a table of contents if a processing instruction <?rfc?>
40     exists with contents toc="yes". Can be overriden by an XSLT parameter -->
41
42<xsl:param name="xml2rfc-toc" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'toc=')], concat($quote-chars,' '), ''),         'toc=')"/>
43
44<!-- optional tocdepth-->
45
46<xsl:param name="xml2rfc-tocdepth" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'tocdepth=')], concat($quote-chars,' '), ''),         'tocdepth=')"/>
47
48<xsl:variable name="parsedTocDepth">
49  <xsl:choose>
50    <xsl:when test="$xml2rfc-tocdepth='1'">1</xsl:when>
51    <xsl:when test="$xml2rfc-tocdepth='2'">2</xsl:when>
52    <xsl:when test="$xml2rfc-tocdepth='3'">3</xsl:when>
53    <xsl:when test="$xml2rfc-tocdepth='4'">4</xsl:when>
54    <xsl:when test="$xml2rfc-tocdepth='5'">5</xsl:when>
55    <xsl:otherwise>99</xsl:otherwise>
56  </xsl:choose>
57</xsl:variable>
58
59<!-- suppress top block if a processing instruction <?rfc?>
60     exists with contents tocblock="no". Can be overriden by an XSLT parameter -->
61
62<xsl:param name="xml2rfc-topblock" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'topblock=')], concat($quote-chars,' '), ''),         'topblock=')"/>
63
64<!-- use symbolic reference names instead of numeric ones unless a processing instruction <?rfc?>
65     exists with contents symrefs="no". Can be overriden by an XSLT parameter -->
66
67<xsl:param name="xml2rfc-symrefs" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'symrefs=')], concat($quote-chars,' '), ''),         'symrefs=')"/>
68
69<!-- sort references if a processing instruction <?rfc?>
70     exists with contents sortrefs="yes". Can be overriden by an XSLT parameter -->
71
72<xsl:param name="xml2rfc-sortrefs" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'sortrefs=')], concat($quote-chars,' '), ''),         'sortrefs=')"/>
73
74<!-- insert editing marks if a processing instruction <?rfc?>
75     exists with contents editing="yes". Can be overriden by an XSLT parameter -->
76
77<xsl:param name="xml2rfc-editing" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'editing=')], concat($quote-chars,' '), ''),         'editing=')"/>
78
79<!-- make it a private paper -->
80
81<xsl:param name="xml2rfc-private" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'private=')], $quote-chars, ''),         'private=')"/>
82
83<!-- background image? -->
84
85<xsl:param name="xml2rfc-background" select="substring-after(       translate(/processing-instruction('rfc')[contains(.,'background=')], $quote-chars, ''),         'background=')"/>
86
87<!-- extension for XML parsing in artwork -->
88
89<xsl:param name="xml2rfc-ext-parse-xml-in-artwork" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'parse-xml-in-artwork=')], concat($quote-chars,' '), ''),         'parse-xml-in-artwork=')"/>
90
91<!-- extension for excluding DCMI properties in meta tag (RFC2731) -->
92
93<xsl:param name="xml2rfc-ext-support-rfc2731" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'support-rfc2731=')], concat($quote-chars,' '), ''),         'support-rfc2731=')"/>
94
95<!-- extension for allowing markup inside artwork -->
96
97<xsl:param name="xml2rfc-ext-allow-markup-in-artwork" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'allow-markup-in-artwork=')], concat($quote-chars,' '), ''),         'allow-markup-in-artwork=')"/>
98
99<!-- extension for including references into index -->
100
101<xsl:param name="xml2rfc-ext-include-references-in-index" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'include-references-in-index=')], concat($quote-chars,' '), ''),         'include-references-in-index=')"/>
102
103<!-- position of author's section -->
104
105<xsl:param name="xml2rfc-ext-authors-section" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'authors-section=')], concat($quote-chars,' '), ''),         'authors-section=')"/>
106
107<!-- justification? -->
108
109<xsl:param name="xml2rfc-ext-justification" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'justification=')], concat($quote-chars,' '), ''),         'justification=')"/>
110
111<!-- trailing dots in section numbers -->
112
113<xsl:param name="xml2rfc-ext-sec-no-trailing-dots" select="substring-after(       translate(/processing-instruction('rfc-ext')[contains(.,'sec-no-trailing-dots=')], concat($quote-chars,' '), ''),         'sec-no-trailing-dots=')"/>
114
115<!-- choose whether or not to do mailto links -->
116 
117 <xsl:param name="xml2rfc-linkmailto" select="substring-after(         translate(/processing-instruction('rfc')[contains(.,'linkmailto=')], concat($quote-chars,' '), ''),           'linkmailto=')"/>
118
119
120<!-- iprnotified switch -->
121 
122 <xsl:param name="xml2rfc-iprnotified" select="substring-after(         translate(/processing-instruction('rfc')[contains(.,'iprnotified=')], concat($quote-chars,' '), ''),           'iprnotified=')"/>
123
124
125<!-- URL templates for RFCs and Internet Drafts. -->
126
127<!-- Reference the authorative ASCII versions
128<xsl:param name="rfcUrlPrefix" select="'http://www.ietf.org/rfc/rfc'" />
129<xsl:param name="rfcUrlPostfix" select="'.txt'" />
130-->
131<!-- Reference the marked up versions over on http://tools.ietf.org/html. -->
132<xsl:param name="rfcUrlPrefix" select="'http://tools.ietf.org/html/rfc'"/>
133<xsl:param name="rfcUrlPostfix" select="''"/>
134<xsl:param name="rfcUrlFrag" select="'section-'"/>
135<xsl:param name="internetDraftUrlPrefix" select="'http://tools.ietf.org/html/'"/>
136<xsl:param name="internetDraftUrlPostfix" select="''"/>
137<xsl:param name="internetDraftUrlFrag" select="'section-'"/>
138
139<!-- warning re: absent node-set ext. function -->
140<xsl:variable name="node-set-warning">
141  This stylesheet requires either an XSLT-1.0 processor with node-set()
142  extension function, or an XSLT-2.0 processor. Therefore, parts of the
143  document couldn't be displayed.
144</xsl:variable>
145
146<!-- character translation tables -->
147<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
148<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>      
149
150<xsl:variable name="plain" select="' #/ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
151<xsl:variable name="touri" select="'___abcdefghijklmnopqrstuvwxyz'"/>
152
153<!-- build help keys for indices -->
154<xsl:key name="index-first-letter" match="iref|reference" use="translate(substring(concat(@anchor,@item),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
155
156<xsl:key name="index-item" match="iref" use="@item"/>
157
158<xsl:key name="index-item-subitem" match="iref" use="concat(@item,'..',@subitem)"/>
159
160<xsl:key name="index-xref-by-sec" match="xref[@x:sec]" use="concat(@target,'..',@x:sec)"/>
161
162<xsl:key name="index-xref-by-anchor" match="xref[@x:rel]" use="concat(@target,'..',@x:rel)"/>
163
164<!-- prefix for automatically generated anchors -->
165<xsl:variable name="anchor-prefix" select="'rfc'"/>
166
167<!-- IPR version switch -->
168<xsl:variable name="ipr-rfc3667" select="(   /rfc/@number &gt; 3708) or   not(     (/rfc/@ipr = 'full2026') or     (/rfc/@ipr = 'noDerivativeWorks2026') or     (/rfc/@ipr = 'noDerivativeWorksNow') or     (/rfc/@ipr = 'none') or     (/rfc/@ipr = '') or     not(/rfc/@ipr)   )"/>
169
170<xsl:variable name="ipr-rfc4748" select="(   $ipr-rfc3667 and     (       (/rfc/@number &gt; 4671) or       (/rfc/front/date/@year &gt; 2006) or       (/rfc/front/date/@year &gt; 2005 and (/rfc/front/date/@month='November' or /rfc/front/date/@month='December'))     )   )"/>
171
172<!-- will document have an index -->
173<xsl:variable name="has-index" select="//iref or (//xref and $xml2rfc-ext-include-references-in-index='yes')"/>
174         
175<!-- Templates for the various elements of rfc2629.dtd -->
176             
177<xsl:template match="text()[not(ancestor::artwork)]">
178  <xsl:variable name="starts-with-ws" select="translate(substring(.,1,1),'&#x9;&#xA;&#xD; ','')"/>
179  <xsl:variable name="ends-with-ws" select="translate(substring(.,string-length(.),1),'&#x9;&#xA;&#xD; ','')"/>
180  <!--<xsl:message> Orig: "<xsl:value-of select="."/>"</xsl:message>
181  <xsl:message>Start: "<xsl:value-of select="$starts-with-ws"/>"</xsl:message>
182  <xsl:message>  End: "<xsl:value-of select="$ends-with-ws"/>"</xsl:message> -->
183  <xsl:if test="$starts-with-ws='' and preceding-sibling::node()">
184    <xsl:text> </xsl:text>
185  </xsl:if>
186  <xsl:value-of select="normalize-space(.)"/>
187  <xsl:if test="$ends-with-ws='' and following-sibling::node()">
188    <xsl:text> </xsl:text>
189  </xsl:if>
190</xsl:template>
191             
192             
193<xsl:template match="abstract">
194  <h1 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.abstract"><a href="#{$anchor-prefix}.abstract">Abstract</a></h1>
195  <xsl:apply-templates/>
196</xsl:template>
197
198<msxsl:script language="JScript" implements-prefix="myns">
199  function parseXml(str) {
200    try {
201      var doc = new ActiveXObject("MSXML2.DOMDocument");
202      doc.async = false;
203      if (doc.loadXML(str)) {
204        return "";
205      }
206      else {
207        return doc.parseError.reason + "\n" + doc.parseError.srcText + " (" + doc.parseError.line + "/" + doc.parseError.linepos + ")";
208      }
209    }
210    catch(e) {
211      return "";
212    }
213  }
214</msxsl:script>
215
216<xsl:template name="add-artwork-class">
217  <xsl:choose>
218    <xsl:when test="@type='abnf' or @type='abnf2616' or @type='application/xml-dtd' or @type='inline' or @type='application/relax-ng-compact-syntax'">
219      <xsl:attribute name="class">inline</xsl:attribute>
220    </xsl:when>
221    <xsl:when test="starts-with(@type,'message/http') and contains(@type,'msgtype=&#34;request&#34;')">
222      <xsl:attribute name="class">text2</xsl:attribute>
223    </xsl:when>
224    <xsl:when test="starts-with(@type,'message/http')">
225      <xsl:attribute name="class">text</xsl:attribute>
226    </xsl:when>
227    <xsl:when test="starts-with(@type,'drawing')">
228      <xsl:attribute name="class">drawing</xsl:attribute>
229    </xsl:when>
230    <xsl:when test="starts-with(@type,'text/plain') or @type='example' or @type='code'">
231      <xsl:attribute name="class">text</xsl:attribute>
232    </xsl:when>
233    <xsl:otherwise/>
234  </xsl:choose>
235</xsl:template>
236
237<xsl:template match="artwork">
238  <xsl:if test="not(ancestor::ed:del) and $xml2rfc-ext-parse-xml-in-artwork='yes' and function-available('myns:parseXml')">
239    <xsl:if test="contains(.,'&lt;?xml')">
240      <xsl:variable name="body" select="substring-after(substring-after(.,'&lt;?xml'),'?&gt;')"/>
241      <xsl:if test="$body!='' and myns:parseXml($body)!=''">
242        <table xmlns="http://www.w3.org/1999/xhtml" style="background-color: red; border-width: thin; border-style: solid; border-color: black;">
243        <tr><td>
244        XML PARSE ERROR; parsed the body below:
245        <pre>
246        <xsl:value-of select="$body"/>
247        </pre>
248        resulting in:
249        <pre>
250        <xsl:value-of select="myns:parseXml($body)"/>
251        </pre>
252        </td></tr></table>
253      </xsl:if>
254    </xsl:if>
255    <xsl:if test="@ed:parse-xml-after">
256      <xsl:if test="myns:parseXml(string(.))!=''">
257        <table xmlns="http://www.w3.org/1999/xhtml" style="background-color: red; border-width: thin; border-style: solid; border-color: black;">
258        <tr><td>
259        XML PARSE ERROR:
260        <pre><xsl:value-of select="myns:parseXml(string(.))"/></pre>
261        </td></tr></table>
262      </xsl:if>
263    </xsl:if>
264  </xsl:if>
265  <xsl:variable name="display">
266    <xsl:choose>
267      <xsl:when test="$xml2rfc-ext-allow-markup-in-artwork='yes'">
268        <xsl:apply-templates/>
269      </xsl:when>
270      <xsl:otherwise>
271        <xsl:value-of select="."/>
272      </xsl:otherwise>
273    </xsl:choose>
274  </xsl:variable> 
275  <xsl:choose>
276    <xsl:when test="@align='right'">
277      <div xmlns="http://www.w3.org/1999/xhtml" style="display:table; margin-left: auto; margin-right: 0pt;">
278        <pre style="margin-left: 0em;">
279          <xsl:call-template name="add-artwork-class"/>
280          <xsl:call-template name="insertInsDelClass"/>
281          <xsl:copy-of select="$display"/>
282        </pre>         
283      </div>
284    </xsl:when>
285    <xsl:when test="@align='center'">
286      <div xmlns="http://www.w3.org/1999/xhtml" style="display:table; margin-left: auto; margin-right: auto;">
287        <pre style="margin-left: 0em;">
288          <xsl:call-template name="add-artwork-class"/>
289          <xsl:call-template name="insertInsDelClass"/>
290          <xsl:copy-of select="$display"/>
291        </pre>         
292      </div>
293    </xsl:when>
294    <xsl:otherwise>
295      <pre xmlns="http://www.w3.org/1999/xhtml">
296        <xsl:call-template name="add-artwork-class"/>
297        <xsl:call-template name="insertInsDelClass"/>
298        <xsl:copy-of select="$display"/>
299      </pre>
300    </xsl:otherwise>
301  </xsl:choose>
302  <xsl:call-template name="check-artwork-width">
303    <xsl:with-param name="content"><xsl:apply-templates/></xsl:with-param>
304  </xsl:call-template>
305</xsl:template>
306
307<!-- special case for first text node in artwork -->
308<xsl:template match="artwork/text()[1]">
309  <xsl:choose>
310    <xsl:when test="starts-with(.,'&#xA;')">
311      <!-- reduce leading whitespace -->
312      <xsl:value-of select="substring(.,2)"/>
313    </xsl:when>
314    <xsl:otherwise>
315      <xsl:value-of select="."/>
316    </xsl:otherwise>
317  </xsl:choose>
318</xsl:template>
319
320
321<xsl:template name="check-artwork-width">
322  <xsl:param name="content"/>
323  <xsl:choose>
324    <xsl:when test="not(contains($content,'&#xA;'))">
325      <xsl:if test="string-length($content) &gt; 69">
326        <xsl:message>artwork line too long: <xsl:value-of select="$content"/></xsl:message>
327      </xsl:if>
328    </xsl:when>
329    <xsl:otherwise>
330      <xsl:variable name="start" select="substring-before($content,'&#xA;')"/>
331      <xsl:variable name="end" select="substring-after($content,'&#xA;')"/>
332      <xsl:if test="string-length($start) &gt; 69">
333        <xsl:message>WARNING: artwork line too long: <xsl:value-of select="$start"/><xsl:call-template name="lineno"/></xsl:message>
334      </xsl:if>
335      <xsl:call-template name="check-artwork-width">
336        <xsl:with-param name="content" select="$end"/>
337      </xsl:call-template>
338    </xsl:otherwise>
339  </xsl:choose>
340</xsl:template>
341
342<xsl:template match="artwork[@src and starts-with(@type,'image/')]">
343  <p xmlns="http://www.w3.org/1999/xhtml">
344    <img src="{@src}" alt="{.}">
345      <xsl:copy-of select="@width|@height"/>
346    </img>
347  </p>
348</xsl:template>
349
350<xsl:template match="author">
351
352    <address xmlns="http://www.w3.org/1999/xhtml" class="vcard">
353      <span class="vcardline">
354        <span class="fn">
355          <xsl:value-of select="@fullname"/>
356        </span>
357        <xsl:if test="@role">
358          (<xsl:value-of select="@role"/>)
359        </xsl:if>
360        <!-- components of name (hidden from display -->
361        <span class="n hidden">
362          <span class="family-name"><xsl:value-of select="@surname"/></span>
363          <!-- given-name family-name -->
364          <xsl:if test="@surname=substring(@fullname,1 + string-length(@fullname) - string-length(@surname))">
365            <span class="given-name"><xsl:value-of select="normalize-space(substring(@fullname,1,string-length(@fullname) - string-length(@surname)))"/></span>
366          </xsl:if>
367          <!-- family-name given-name -->
368          <xsl:if test="starts-with(@fullname,@surname)">
369            <span class="given-name"><xsl:value-of select="normalize-space(substring-after(@fullname,@surname))"/></span>
370          </xsl:if>
371        </span>
372      </span>
373      <xsl:if test="normalize-space(organization) != ''">
374        <span class="org vcardline">
375          <xsl:value-of select="organization"/>
376        </span>
377      </xsl:if>
378      <xsl:if test="address/postal">
379        <span class="adr">
380          <xsl:if test="address/postal/street!=''">
381            <xsl:for-each select="address/postal/street">
382              <span class="street-address vcardline">
383                <xsl:value-of select="."/>
384              </span>
385            </xsl:for-each>
386          </xsl:if>
387          <xsl:if test="address/postal/city|address/postal/region|address/postal/code">
388            <span class="vcardline">
389              <xsl:if test="address/postal/city"><span class="locality"><xsl:value-of select="address/postal/city"/></span>, </xsl:if>
390              <xsl:if test="address/postal/region"><span class="region"><xsl:value-of select="address/postal/region"/></span> </xsl:if>
391              <xsl:if test="address/postal/code"><span class="postal-code"><xsl:value-of select="address/postal/code"/></span></xsl:if>
392            </span>
393          </xsl:if>
394          <xsl:if test="address/postal/country">
395            <span class="country-name vcardline"><xsl:value-of select="address/postal/country"/></span>
396          </xsl:if>
397        </span>
398      </xsl:if>
399      <xsl:if test="address/phone">
400        <span class="vcardline tel">
401          <xsl:text>Phone: </xsl:text>
402          <a href="tel:{translate(address/phone,' ','')}"><span class="value"><xsl:value-of select="address/phone"/></span></a>
403        </span>
404      </xsl:if>
405      <xsl:if test="address/facsimile">
406        <span class="vcardline tel">
407          <span class="type">Fax</span><xsl:text>: </xsl:text>
408          <a href="fax:{translate(address/facsimile,' ','')}"><span class="value"><xsl:value-of select="address/facsimile"/></span></a>
409        </span>
410      </xsl:if>
411      <xsl:if test="address/email">
412        <span class="vcardline">
413        <xsl:text>EMail: </xsl:text>
414        <a>
415          <xsl:if test="$xml2rfc-linkmailto!='no'">
416            <xsl:attribute name="href">mailto:<xsl:value-of select="address/email"/></xsl:attribute>
417          </xsl:if>
418          <span class="email"><xsl:value-of select="address/email"/></span>
419        </a>
420        </span>
421      </xsl:if>
422      <xsl:if test="address/uri">
423        <span class="vcardline">
424          <xsl:text>URI: </xsl:text>
425          <a href="{address/uri}" class="url"><xsl:value-of select="address/uri"/></a>
426        </span>
427      </xsl:if>
428    </address>
429
430</xsl:template>
431
432<xsl:template match="back">
433
434  <!-- add references section first, no matter where it appears in the
435    source document -->
436  <!-- as of April 2004, process from middle section
437  <xsl:apply-templates select="references" />
438  -->
439 
440  <!-- add editorial comments -->
441  <xsl:if test="//cref and $xml2rfc-comments='yes' and $xml2rfc-inline!='yes'">
442    <xsl:call-template name="insertComments"/>
443  </xsl:if>
444 
445  <!-- next, add information about the document's authors -->
446  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
447    <xsl:call-template name="insertAuthors"/>
448  </xsl:if>
449     
450  <!-- add all other top-level sections under <back> -->
451  <xsl:apply-templates select="*[not(self::references) and not(self::ed:replace and .//references)]"/>
452
453  <xsl:if test="$xml2rfc-ext-authors-section='end'">
454    <xsl:call-template name="insertAuthors"/>
455  </xsl:if>
456
457  <xsl:if test="not($xml2rfc-private)">
458    <!-- copyright statements -->
459    <xsl:variable name="copyright"><xsl:call-template name="insertCopyright"/></xsl:variable>
460 
461    <!-- emit it -->
462    <xsl:choose>
463      <xsl:when test="function-available('msxsl:node-set')">
464        <xsl:apply-templates select="msxsl:node-set($copyright)"/>
465      </xsl:when>
466      <xsl:when test="function-available('exslt:node-set')">
467        <xsl:apply-templates select="exslt:node-set($copyright)"/>
468      </xsl:when>
469      <xsl:otherwise>
470        <xsl:message><xsl:value-of select="$node-set-warning"/></xsl:message>
471        <p xmlns="http://www.w3.org/1999/xhtml" class="error"><xsl:value-of select="$node-set-warning"/></p>
472      </xsl:otherwise>
473    </xsl:choose>
474  </xsl:if>
475 
476  <!-- insert the index if index entries exist -->
477  <xsl:if test="$has-index">
478    <xsl:call-template name="insertIndex"/>
479  </xsl:if>
480
481</xsl:template>
482
483<xsl:template match="eref[node()]">
484  <a xmlns="http://www.w3.org/1999/xhtml" href="{@target}"><xsl:apply-templates/></a>
485</xsl:template>
486               
487<xsl:template match="eref[not(node())]">
488  <xsl:text>&lt;</xsl:text>
489  <a xmlns="http://www.w3.org/1999/xhtml" href="{@target}"><xsl:value-of select="@target"/></a>
490  <xsl:text>&gt;</xsl:text>
491</xsl:template>
492
493<xsl:template match="figure">
494  <xsl:if test="@anchor!=''">
495    <div xmlns="http://www.w3.org/1999/xhtml" id="{@anchor}"/>
496  </xsl:if>
497  <xsl:variable name="anch">
498    <xsl:call-template name="get-figure-anchor"/>
499  </xsl:variable>
500  <div xmlns="http://www.w3.org/1999/xhtml" id="{$anch}"/>
501  <xsl:apply-templates/>
502  <xsl:if test="@title!='' or @anchor!=''">
503    <xsl:variable name="n"><xsl:number level="any" count="figure[@title!='' or @anchor!='']"/></xsl:variable>
504    <p xmlns="http://www.w3.org/1999/xhtml" class="figure">Figure <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title"/></xsl:if></p>
505  </xsl:if>
506</xsl:template>
507
508<xsl:template match="front">
509 
510  <xsl:if test="$xml2rfc-topblock!='no'">
511    <!-- collect information for left column -->
512     
513    <xsl:variable name="leftColumn">
514      <xsl:call-template name="collectLeftHeaderColumn"/>   
515    </xsl:variable>
516 
517    <!-- collect information for right column -->
518     
519    <xsl:variable name="rightColumn">
520      <xsl:call-template name="collectRightHeaderColumn"/>   
521    </xsl:variable>
522     
523    <!-- insert the collected information -->
524    <table xmlns="http://www.w3.org/1999/xhtml" summary="header information" class="header" border="0" cellpadding="1" cellspacing="1">
525      <xsl:choose>
526        <xsl:when test="function-available('msxsl:node-set')">
527          <xsl:call-template name="emitheader">
528            <xsl:with-param name="lc" select="msxsl:node-set($leftColumn)"/>   
529            <xsl:with-param name="rc" select="msxsl:node-set($rightColumn)"/>   
530          </xsl:call-template>
531        </xsl:when>   
532        <xsl:when test="function-available('exslt:node-set')">
533          <xsl:call-template name="emitheader">
534            <xsl:with-param name="lc" select="exslt:node-set($leftColumn)"/>   
535            <xsl:with-param name="rc" select="exslt:node-set($rightColumn)"/>   
536          </xsl:call-template>
537        </xsl:when>   
538        <xsl:otherwise>
539          <xsl:message><xsl:value-of select="$node-set-warning"/></xsl:message>
540          <p class="error"><xsl:value-of select="$node-set-warning"/></p>
541        </xsl:otherwise>
542      </xsl:choose>
543    </table>
544  </xsl:if>
545   
546  <p xmlns="http://www.w3.org/1999/xhtml" class="title">
547    <!-- main title -->
548    <xsl:apply-templates select="title"/>
549    <xsl:if test="/rfc/@docName">
550      <br/>
551      <span class="filename"><xsl:value-of select="/rfc/@docName"/></span>
552     
553      <xsl:if test="contains(/rfc/@docName,'.')">
554        <xsl:call-template name="warning">
555          <xsl:with-param name="msg">The @docName attribute should contain the base name, not the filename (thus no file extension).</xsl:with-param>
556        </xsl:call-template>
557      </xsl:if>
558    </xsl:if> 
559  </p>
560 
561  <!-- insert notice about update -->
562  <xsl:variable name="published-as" select="/*/x:link[@rel='Alternate' and starts-with(@title,'RFC')]"/>
563  <xsl:if test="$published-as">
564    <p xmlns="http://www.w3.org/1999/xhtml" style="color: green; text-align: center; font-size: 14pt; background-color: yellow;">
565      <b>Note:</b> a later version of this document has been published as <a href="{$published-as/@href}"><xsl:value-of select="$published-as/@title"/></a>.
566    </p>
567  </xsl:if>
568   
569  <xsl:if test="not($xml2rfc-private)">
570    <!-- Get status info formatted as per RFC2629-->
571    <xsl:variable name="preamble"><xsl:call-template name="insertPreamble"/></xsl:variable>
572   
573    <!-- emit it -->
574    <xsl:choose>
575      <xsl:when test="function-available('msxsl:node-set')">
576        <xsl:apply-templates select="msxsl:node-set($preamble)"/>
577      </xsl:when>
578      <xsl:when test="function-available('exslt:node-set')">
579        <xsl:apply-templates select="exslt:node-set($preamble)"/>
580      </xsl:when>
581      <xsl:otherwise>
582        <xsl:message><xsl:value-of select="$node-set-warning"/></xsl:message>
583        <p xmlns="http://www.w3.org/1999/xhtml" class="error"><xsl:value-of select="$node-set-warning"/></p>
584      </xsl:otherwise>
585    </xsl:choose>
586  </xsl:if>
587           
588  <xsl:apply-templates select="abstract"/>
589  <xsl:apply-templates select="note"/>
590  <!-- show notes inside change tracking as well -->
591  <xsl:apply-templates select="ed:replace[.//note]"/>
592   
593  <xsl:if test="$xml2rfc-toc='yes'">
594    <xsl:apply-templates select="/" mode="toc"/>
595    <xsl:call-template name="insertTocAppendix"/>
596  </xsl:if>
597
598</xsl:template>
599
600
601<xsl:template match="iref">
602  <xsl:variable name="anchor"><xsl:call-template name="compute-iref-anchor"/></xsl:variable>
603  <xsl:choose>
604    <xsl:when test="ancestor::t|ancestor::figure">
605      <span xmlns="http://www.w3.org/1999/xhtml" id="{$anchor}"/>
606    </xsl:when>
607    <xsl:otherwise>
608      <div xmlns="http://www.w3.org/1999/xhtml" id="{$anchor}"/>
609    </xsl:otherwise>
610  </xsl:choose>
611</xsl:template>
612
613<xsl:template name="compute-iref-anchor">
614  <xsl:variable name="first" select="translate(substring(@item,1,1),$ucase,$lcase)"/>
615  <xsl:variable name="nkey" select="translate($first,$lcase,'')"/>
616  <xsl:choose>
617    <xsl:when test="$nkey=''">
618      <xsl:value-of select="$anchor-prefix"/>.iref.<xsl:value-of select="$first"/>.<xsl:number level="any" count="iref[starts-with(translate(@item,$ucase,$lcase),$first)]"/>
619    </xsl:when>
620    <xsl:otherwise>
621      <xsl:value-of select="$anchor-prefix"/>.iref.<xsl:number level="any" count="iref[translate(substring(@item,1,1),concat($lcase,$ucase),'')='']"/>
622    </xsl:otherwise>
623  </xsl:choose>
624</xsl:template>
625
626<!-- list templates depend on the list style -->
627
628<xsl:template match="list[@style='empty' or not(@style)]">
629  <dl xmlns="http://www.w3.org/1999/xhtml" class="empty">
630    <xsl:call-template name="insertInsDelClass"/>
631    <xsl:apply-templates/>
632  </dl>
633</xsl:template>
634
635<xsl:template match="list[starts-with(@style,'format ')]">
636  <dl xmlns="http://www.w3.org/1999/xhtml">
637    <xsl:call-template name="insertInsDelClass"/>
638    <xsl:apply-templates/>
639  </dl>
640</xsl:template>
641
642<xsl:template match="list[@style='hanging']">
643  <dl xmlns="http://www.w3.org/1999/xhtml">
644    <xsl:call-template name="insertInsDelClass"/>
645    <xsl:apply-templates/>
646  </dl>
647</xsl:template>
648
649<xsl:template match="list[@style='numbers']">
650  <ol xmlns="http://www.w3.org/1999/xhtml">
651    <xsl:call-template name="insertInsDelClass"/>
652    <xsl:apply-templates/>
653  </ol>
654</xsl:template>
655
656<!-- numbered list inside numbered list -->
657<xsl:template match="list[@style='numbers']/t/list[@style='numbers']" priority="9">
658  <ol xmlns="http://www.w3.org/1999/xhtml" style="list-style-type: lower-alpha">
659    <xsl:call-template name="insertInsDelClass"/>
660    <xsl:apply-templates/>
661  </ol>
662</xsl:template>
663
664<xsl:template match="list[@style='letters']">
665  <ol xmlns="http://www.w3.org/1999/xhtml" style="list-style-type: lower-alpha">
666    <xsl:call-template name="insertInsDelClass"/>
667    <xsl:apply-templates/>
668  </ol>
669</xsl:template>
670
671<!-- nested lettered list uses uppercase -->
672<xsl:template match="list//t//list[@style='letters']" priority="9">
673  <ol xmlns="http://www.w3.org/1999/xhtml" style="list-style-type: upper-alpha">
674    <xsl:call-template name="insertInsDelClass"/>
675    <xsl:apply-templates/>
676  </ol>
677</xsl:template>
678   
679<xsl:template match="list[@style='symbols']">
680  <ul xmlns="http://www.w3.org/1999/xhtml">
681    <xsl:call-template name="insertInsDelClass"/>
682    <xsl:apply-templates/>
683  </ul>
684</xsl:template>
685
686
687<!-- same for t(ext) elements -->
688
689<xsl:template match="list[@style='empty' or not(@style)]/t | list[@style='empty' or not(@style)]/ed:replace/ed:*/t">
690  <!-- Inherited through CSS now <dd style="margin-top: .5em">-->
691  <dd xmlns="http://www.w3.org/1999/xhtml">
692    <xsl:call-template name="insertInsDelClass"/>
693    <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
694    <xsl:apply-templates/>
695  </dd>
696</xsl:template>
697
698<xsl:template match="list[@style='numbers' or @style='symbols' or @style='letters']/x:lt">
699  <li xmlns="http://www.w3.org/1999/xhtml">
700    <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
701    <xsl:apply-templates select="t"/>
702  </li>
703</xsl:template>
704
705<xsl:template match="list[@style='numbers' or @style='symbols' or @style='letters']/t | list[@style='numbers' or @style='symbols' or @style='letters']/ed:replace/ed:*/t">
706  <li xmlns="http://www.w3.org/1999/xhtml">
707    <xsl:call-template name="insertInsDelClass"/>
708    <xsl:for-each select="../..">
709      <xsl:call-template name="insert-issue-pointer"/>
710    </xsl:for-each>
711    <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
712    <xsl:apply-templates/>
713  </li>
714</xsl:template>
715
716<xsl:template match="list[@style='hanging']/x:lt">
717  <xsl:if test="@hangText!=''">
718    <dt xmlns="http://www.w3.org/1999/xhtml">
719      <xsl:call-template name="insertInsDelClass"/>
720      <xsl:variable name="del-node" select="ancestor::ed:del"/>
721      <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
722      <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
723      <xsl:for-each select="../..">
724        <xsl:call-template name="insert-issue-pointer">
725          <xsl:with-param name="deleted-anchor" select="$deleted"/>
726        </xsl:call-template>
727      </xsl:for-each>
728      <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
729      <xsl:value-of select="@hangText"/>
730    </dt>
731  </xsl:if>
732  <dd xmlns="http://www.w3.org/1999/xhtml">
733    <xsl:call-template name="insertInsDelClass"/>
734    <!-- if hangIndent present, use 0.7 of the specified value (1em is the width of the "m" character -->
735    <xsl:if test="../@hangIndent and ../@hangIndent!='0'">
736      <xsl:attribute name="style">margin-left: <xsl:value-of select="../@hangIndent * 0.7"/>em</xsl:attribute>
737    </xsl:if>
738    <xsl:apply-templates select="t"/>
739  </dd>
740</xsl:template>
741
742<xsl:template match="list[@style='hanging']/t | list[@style='hanging']/ed:replace/ed:*/t">
743  <xsl:if test="@hangText!=''">
744    <dt xmlns="http://www.w3.org/1999/xhtml">
745      <xsl:call-template name="insertInsDelClass"/>
746      <xsl:if test="count(preceding-sibling::t)=0">
747        <xsl:variable name="del-node" select="ancestor::ed:del"/>
748        <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
749        <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
750        <xsl:for-each select="../..">
751          <xsl:call-template name="insert-issue-pointer">
752            <xsl:with-param name="deleted-anchor" select="$deleted"/>
753          </xsl:call-template>
754        </xsl:for-each>
755      </xsl:if>
756      <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
757      <xsl:value-of select="@hangText"/>
758    </dt>
759  </xsl:if>
760
761  <xsl:variable name="dd-content">
762    <xsl:apply-templates/>
763  </xsl:variable>
764
765  <xsl:if test="$dd-content!=''">
766    <dd xmlns="http://www.w3.org/1999/xhtml">
767      <xsl:call-template name="insertInsDelClass"/>
768      <!-- if hangIndent present, use 0.7 of the specified value (1em is the width of the "m" character -->
769      <xsl:if test="../@hangIndent and ../@hangIndent!='0'">
770        <xsl:attribute name="style">margin-left: <xsl:value-of select="../@hangIndent * 0.7"/>em</xsl:attribute>
771      </xsl:if>
772      <xsl:apply-templates/>
773    </dd>
774  </xsl:if>
775</xsl:template>
776
777<xsl:template match="list[starts-with(@style,'format ') and (contains(@style,'%c') or contains(@style,'%d'))]/t">
778  <xsl:variable name="list" select=".."/>
779  <xsl:variable name="format" select="substring-after(../@style,'format ')"/>
780  <xsl:variable name="pos">
781    <xsl:choose>
782      <xsl:when test="$list/@counter">
783        <xsl:number level="any" count="list[@counter=$list/@counter or (not(@counter) and @style=concat('format ',$list/@counter))]/t"/>
784      </xsl:when>
785      <xsl:otherwise>
786        <xsl:number level="any" count="list[concat('format ',@counter)=$list/@style or (not(@counter) and @style=$list/@style)]/t"/>
787      </xsl:otherwise>
788    </xsl:choose>
789  </xsl:variable>
790  <dt xmlns="http://www.w3.org/1999/xhtml">
791    <xsl:if test="@anchor"><xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute></xsl:if>
792    <xsl:choose>
793      <xsl:when test="contains($format,'%c')">
794        <xsl:value-of select="substring-before($format,'%c')"/><xsl:number value="$pos" format="a"/><xsl:value-of select="substring-after($format,'%c')"/>
795      </xsl:when>
796      <xsl:otherwise>
797        <xsl:value-of select="substring-before($format,'%d')"/><xsl:number value="$pos" format="1"/><xsl:value-of select="substring-after($format,'%d')"/>
798      </xsl:otherwise>
799    </xsl:choose>
800  </dt>
801  <dd xmlns="http://www.w3.org/1999/xhtml">
802    <xsl:apply-templates/>
803  </dd>
804</xsl:template>
805
806<xsl:template match="middle">
807  <xsl:apply-templates/>
808  <xsl:apply-templates select="../back//references"/>
809</xsl:template>
810
811<xsl:template match="note">
812  <xsl:variable name="num"><xsl:number/></xsl:variable>
813    <h1 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.note.{$num}">
814      <xsl:call-template name="insertInsDelClass"/>
815      <a href="#{$anchor-prefix}.note.{$num}">
816        <xsl:value-of select="@title"/>
817      </a>
818    </h1>
819  <xsl:apply-templates/>
820</xsl:template>
821
822<xsl:template match="postamble">
823  <xsl:if test="normalize-space(.) != ''">
824    <p xmlns="http://www.w3.org/1999/xhtml">
825      <xsl:call-template name="insertInsDelClass"/>
826      <xsl:call-template name="editingMark"/>
827      <xsl:apply-templates/>
828    </p>
829  </xsl:if>
830</xsl:template>
831
832<xsl:template match="preamble">
833  <xsl:if test="normalize-space(.) != ''">
834    <p xmlns="http://www.w3.org/1999/xhtml">
835      <xsl:if test="@anchor">
836        <xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute>
837      </xsl:if>
838      <xsl:call-template name="insertInsDelClass"/>
839      <xsl:call-template name="editingMark"/>
840      <xsl:apply-templates/>
841    </p>
842  </xsl:if>
843</xsl:template>
844
845<xsl:template name="computed-auto-target">
846  <xsl:param name="bib"/>
847  <xsl:param name="ref"/>
848
849  <xsl:choose>
850    <xsl:when test="$ref and $bib/x:source/@href and $bib/x:source/@basename and $ref/@x:rel">
851      <xsl:value-of select="concat($bib/x:source/@basename,'.html',$ref/@x:rel)"/>
852    </xsl:when>
853    <xsl:when test="$bib/seriesInfo/@name='RFC'">
854      <xsl:variable name="sec">
855        <xsl:choose>
856          <xsl:when test="$ref and starts-with($ref/@x:rel,'#') and not($ref/@x:sec)">
857            <xsl:variable name="extdoc" select="document($bib/x:source/@href)"/>
858            <xsl:for-each select="$extdoc//*[@anchor=substring-after($ref/@x:rel,'#')]">
859              <xsl:call-template name="get-section-number"/>
860            </xsl:for-each>
861          </xsl:when>
862          <xsl:when test="$ref">
863            <xsl:value-of select="$ref/@x:sec"/>
864          </xsl:when>
865          <xsl:otherwise/>
866        </xsl:choose>
867      </xsl:variable>
868      <xsl:value-of select="concat($rfcUrlPrefix,$bib/seriesInfo[@name='RFC']/@value,$rfcUrlPostfix)"/>
869      <xsl:if test="$ref and $sec!='' and $rfcUrlFrag">
870        <xsl:value-of select="concat('#',$rfcUrlFrag,$sec)"/>
871      </xsl:if>
872    </xsl:when>
873    <xsl:when test="$bib/seriesInfo/@name='Internet-Draft'">
874      <xsl:value-of select="concat($internetDraftUrlPrefix,$bib/seriesInfo[@name='Internet-Draft']/@value,$internetDraftUrlPostfix)"/>
875      <xsl:if test="$ref and $ref/@x:sec and $internetDraftUrlFrag">
876        <xsl:value-of select="concat('#',$internetDraftUrlFrag,$ref/@x:sec)"/>
877      </xsl:if>
878    </xsl:when>
879    <xsl:otherwise/>
880  </xsl:choose> 
881 
882</xsl:template>
883
884<xsl:template name="computed-target">
885  <xsl:param name="bib"/>
886  <xsl:param name="ref"/>
887
888  <xsl:choose>
889    <xsl:when test="$bib/@target">
890      <xsl:if test="$ref and $ref/@x:sec and $ref/@x:rel">
891        <xsl:value-of select="concat($bib/@target,$ref/@x:rel)"/>
892      </xsl:if>
893    </xsl:when>
894    <xsl:otherwise>
895      <xsl:call-template name="computed-auto-target">
896        <xsl:with-param name="bib" select="$bib"/>
897        <xsl:with-param name="ref" select="$ref"/>
898      </xsl:call-template>
899    </xsl:otherwise>
900  </xsl:choose> 
901 
902</xsl:template>
903
904<xsl:template match="reference">
905
906  <!-- check for reference to reference -->
907  <xsl:variable name="anchor" select="@anchor"/>
908  <xsl:if test="not(ancestor::ed:del) and not(//xref[@target=$anchor])">
909    <xsl:message>WARNING: unused reference '<xsl:value-of select="@anchor"/>'<xsl:call-template name="lineno"/></xsl:message>
910  </xsl:if>
911
912  <xsl:variable name="target">
913    <xsl:choose>
914      <xsl:when test="@target"><xsl:value-of select="@target"/></xsl:when>
915      <xsl:otherwise>
916        <xsl:call-template name="computed-auto-target">
917          <xsl:with-param name="bib" select="."/>
918        </xsl:call-template>
919      </xsl:otherwise>
920    </xsl:choose>
921  </xsl:variable>
922 
923  <tr xmlns="http://www.w3.org/1999/xhtml">
924    <td class="reference">
925      <xsl:call-template name="insertInsDelClass"/>
926      <xsl:variable name="del-node" select="ancestor::ed:del"/>
927      <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
928      <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
929      <xsl:for-each select="../..">
930        <xsl:call-template name="insert-issue-pointer">
931          <xsl:with-param name="deleted-anchor" select="$deleted"/>
932        </xsl:call-template>
933      </xsl:for-each>
934      <b id="{@anchor}">
935        <xsl:call-template name="referencename">
936          <xsl:with-param name="node" select="."/>
937        </xsl:call-template>
938      </b>
939    </td>
940   
941    <td class="top">
942      <xsl:call-template name="insertInsDelClass"/>
943      <xsl:for-each select="front/author">
944        <xsl:variable name="initials">
945          <xsl:call-template name="format-initials"/>
946        </xsl:variable>
947     
948        <xsl:choose>
949          <xsl:when test="@surname and @surname!=''">
950            <xsl:variable name="displayname">
951              <!-- surname/initials is reversed for last author except when it's the only one -->
952              <xsl:choose>
953                <xsl:when test="position()=last() and position()!=1">
954                  <xsl:value-of select="concat($initials,' ',@surname)"/>
955                </xsl:when>
956                <xsl:otherwise>
957                  <xsl:value-of select="concat(@surname,', ',$initials)"/>
958                </xsl:otherwise>
959              </xsl:choose>
960              <xsl:if test="@role='editor'">
961                <xsl:text>, Ed.</xsl:text>
962              </xsl:if>
963            </xsl:variable>
964            <xsl:choose>
965              <xsl:when test="address/email">
966                <a>
967                  <xsl:if test="$xml2rfc-linkmailto!='no'">
968                    <xsl:attribute name="href">mailto:<xsl:value-of select="address/email"/></xsl:attribute>
969                  </xsl:if>
970                  <xsl:if test="organization/text()">
971                    <xsl:attribute name="title"><xsl:value-of select="organization/text()"/></xsl:attribute>
972                  </xsl:if>
973                  <xsl:value-of select="$displayname"/>
974                </a>
975              </xsl:when>
976              <xsl:otherwise>
977                <xsl:value-of select="$displayname"/>
978              </xsl:otherwise>
979            </xsl:choose>
980           
981            <xsl:choose>
982              <xsl:when test="position()=last() - 1">
983                <xsl:if test="last() &gt; 2">,</xsl:if>
984                <xsl:text> and </xsl:text>
985              </xsl:when>
986              <xsl:otherwise>
987                <xsl:text>, </xsl:text>
988              </xsl:otherwise>
989            </xsl:choose>
990          </xsl:when>
991          <xsl:when test="organization/text()">
992            <xsl:choose>
993              <xsl:when test="address/uri">
994                <a href="{address/uri}"><xsl:value-of select="organization"/></a>
995              </xsl:when>
996              <xsl:otherwise>
997                <xsl:value-of select="organization"/>
998              </xsl:otherwise>
999            </xsl:choose>
1000           
1001            <xsl:choose>
1002              <xsl:when test="position()=last() - 1">
1003                <xsl:if test="last() &gt; 2">,</xsl:if>
1004                <xsl:text> and </xsl:text>
1005              </xsl:when>
1006              <xsl:otherwise>
1007                <xsl:text>, </xsl:text>
1008              </xsl:otherwise>
1009            </xsl:choose>
1010          </xsl:when>
1011          <xsl:otherwise/>
1012        </xsl:choose>
1013      </xsl:for-each>
1014         
1015      <xsl:choose>
1016        <xsl:when test="string-length($target) &gt; 0">
1017          <xsl:text>&#8220;</xsl:text><a href="{$target}"><xsl:value-of select="front/title"/></a><xsl:text>&#8221;</xsl:text>
1018        </xsl:when>
1019        <xsl:otherwise>
1020          <xsl:text>&#8220;</xsl:text><xsl:value-of select="front/title"/><xsl:text>&#8221;</xsl:text>
1021        </xsl:otherwise>
1022      </xsl:choose>
1023           
1024      <xsl:for-each select="seriesInfo">
1025        <xsl:text>, </xsl:text>
1026        <xsl:choose>
1027          <xsl:when test="not(@name) and not(@value) and ./text()"><xsl:value-of select="."/></xsl:when>
1028          <xsl:otherwise>
1029            <xsl:value-of select="@name"/>
1030            <xsl:if test="@value!=''"> <xsl:value-of select="@value"/></xsl:if>
1031            <xsl:if test="translate(@name,$ucase,$lcase)='internet-draft'"> (work in progress)</xsl:if>
1032          </xsl:otherwise>
1033        </xsl:choose>
1034      </xsl:for-each>
1035     
1036      <xsl:if test="front/date/@year != '' and front/date/@year != '???'">
1037        <xsl:text>, </xsl:text>
1038        <xsl:if test="front/date/@month and (front/date/@month!='???' and front/date/@month!='')"><xsl:value-of select="front/date/@month"/> </xsl:if>
1039        <xsl:value-of select="front/date/@year"/>
1040      </xsl:if>
1041     
1042      <xsl:if test="@target">
1043        <xsl:text>, &lt;</xsl:text>
1044        <a href="{@target}"><xsl:value-of select="@target"/></a>
1045        <xsl:text>&gt;</xsl:text>
1046      </xsl:if>
1047     
1048      <xsl:text>.</xsl:text>
1049
1050      <xsl:for-each select="annotation">
1051        <br/>
1052        <xsl:apply-templates/>
1053      </xsl:for-each>
1054
1055    </td>
1056  </tr>
1057 
1058 
1059</xsl:template>
1060
1061
1062<xsl:template match="references">
1063
1064  <xsl:variable name="name">
1065    <xsl:if test="ancestor::ed:del">
1066      <xsl:text>del-</xsl:text>
1067    </xsl:if>
1068    <xsl:number level="any"/>     
1069  </xsl:variable>
1070 
1071  <xsl:variable name="refseccount" select="count(/rfc/back/references)+count(/rfc/back/ed:replace/ed:ins/references)"/>
1072
1073  <!-- insert pseudo section when needed -->
1074  <xsl:if test="not(preceding::references) and $refseccount!=1">
1075    <xsl:call-template name="insert-conditional-hrule"/>
1076    <h1 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.references">
1077      <xsl:call-template name="insert-conditional-pagebreak"/>
1078      <xsl:variable name="sectionNumber">
1079        <xsl:call-template name="get-references-section-number"/>
1080      </xsl:variable>
1081      <a id="{$anchor-prefix}.section.{$sectionNumber}" href="#{$anchor-prefix}.section.{$sectionNumber}">
1082        <xsl:call-template name="emit-section-number">
1083          <xsl:with-param name="no" select="$sectionNumber"/>
1084        </xsl:call-template>
1085      </a>
1086      <xsl:text> References</xsl:text>
1087    </h1>
1088  </xsl:if>
1089 
1090  <xsl:variable name="elemtype">
1091    <xsl:choose>
1092      <xsl:when test="$refseccount!=1">h2</xsl:when>
1093      <xsl:otherwise>h1</xsl:otherwise>
1094    </xsl:choose>
1095  </xsl:variable>
1096 
1097  <xsl:variable name="title">
1098    <xsl:choose>
1099      <xsl:when test="not(@title) or @title=''">References</xsl:when>
1100      <xsl:otherwise><xsl:value-of select="@title"/></xsl:otherwise>
1101    </xsl:choose>
1102  </xsl:variable>
1103 
1104  <xsl:element namespace="http://www.w3.org/1999/xhtml" name="{$elemtype}">
1105    <xsl:if test="$name='1'">
1106      <xsl:call-template name="insert-conditional-pagebreak"/>
1107    </xsl:if>
1108    <xsl:variable name="sectionNumber">
1109      <xsl:call-template name="get-section-number"/>
1110    </xsl:variable>
1111    <xsl:variable name="anchorpref">
1112      <xsl:choose>
1113        <xsl:when test="$elemtype='h1'"/>
1114        <xsl:otherwise>.<xsl:value-of select="$name"/></xsl:otherwise>
1115      </xsl:choose>
1116    </xsl:variable>
1117    <xsl:attribute name="id"><xsl:value-of select="concat($anchor-prefix,'.references',$anchorpref)"/></xsl:attribute>
1118    <a xmlns="http://www.w3.org/1999/xhtml" href="#{$anchor-prefix}.section.{$sectionNumber}" id="{$anchor-prefix}.section.{$sectionNumber}">
1119      <xsl:call-template name="emit-section-number">
1120        <xsl:with-param name="no" select="$sectionNumber"/>
1121      </xsl:call-template>
1122    </a>
1123    <xsl:text> </xsl:text>
1124    <xsl:value-of select="$title"/>
1125  </xsl:element>
1126 
1127  <table xmlns="http://www.w3.org/1999/xhtml" summary="{$title}">
1128    <xsl:choose>
1129      <xsl:when test="$xml2rfc-sortrefs='yes' and $xml2rfc-symrefs!='no'">
1130        <xsl:apply-templates>
1131          <xsl:sort select="@anchor|.//ed:ins//reference/@anchor"/>
1132        </xsl:apply-templates>
1133      </xsl:when>
1134      <xsl:otherwise>
1135        <xsl:apply-templates/>
1136      </xsl:otherwise>
1137    </xsl:choose>
1138  </table>
1139
1140</xsl:template>
1141
1142<xsl:template match="rfc">
1143 
1144  <!-- conformance checks -->
1145  <xsl:if test="$xml2rfc-symrefs!='no' and $xml2rfc-symrefs!='yes' and //reference">
1146    <xsl:message>WARNING: symrefs PI not specified; default has changed from 'no' to 'yes'.</xsl:message>
1147  </xsl:if>
1148 
1149  <xsl:variable name="lang">
1150    <xsl:call-template name="get-lang"/>
1151  </xsl:variable>
1152
1153  <html xmlns="http://www.w3.org/1999/xhtml" lang="{$lang}">
1154    <head profile="http://www.w3.org/2006/03/hcard">
1155      <title>
1156        <xsl:apply-templates select="front/title" mode="get-text-content"/>
1157      </title>
1158      <style type="text/css" title="Xml2Rfc (sans serif)">
1159        <xsl:call-template name="insertCss"/>
1160      </style>
1161      <!-- <link rel="alternate stylesheet" type="text/css" media="screen" title="Plain (typewriter)" href="rfc2629tty.css" /> -->
1162           
1163      <!-- link elements -->
1164      <xsl:if test="$xml2rfc-toc='yes'">
1165        <link rel="Contents" href="#{$anchor-prefix}.toc"/>
1166      </xsl:if>
1167      <link rel="Author" href="#{$anchor-prefix}.authors"/>
1168      <xsl:if test="not($xml2rfc-private)">
1169        <link rel="Copyright" href="#{$anchor-prefix}.copyright"/>
1170      </xsl:if>
1171      <xsl:if test="$has-index">
1172        <link rel="Index" href="#{$anchor-prefix}.index"/>
1173      </xsl:if>
1174      <xsl:apply-templates select="/" mode="links"/>
1175      <xsl:for-each select="/rfc/x:link">
1176        <link><xsl:copy-of select="@*"/></link>
1177      </xsl:for-each>
1178      <xsl:if test="/rfc/@number">
1179        <link rel="Alternate" title="Authorative ASCII version" href="http://www.ietf.org/rfc/rfc{/rfc/@number}.txt"/>
1180      </xsl:if>
1181
1182      <!-- generator -->
1183      <xsl:variable name="gen">
1184        <xsl:call-template name="get-generator"/>
1185      </xsl:variable>
1186      <meta name="generator" content="{$gen}"/>
1187     
1188      <!-- keywords -->
1189      <xsl:if test="front/keyword">
1190        <xsl:variable name="keyw">
1191          <xsl:call-template name="get-keywords"/>
1192        </xsl:variable>
1193        <meta name="keywords" content="{$keyw}"/>
1194      </xsl:if>
1195
1196      <xsl:if test="$xml2rfc-ext-support-rfc2731!='no'">
1197        <!-- Dublin Core Metadata -->
1198        <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"/>
1199             
1200        <!-- DC creator, see RFC2731 -->
1201        <xsl:for-each select="/rfc/front/author">
1202          <xsl:variable name="initials">
1203            <xsl:call-template name="format-initials"/>
1204          </xsl:variable>
1205          <meta name="DC.Creator" content="{concat(@surname,', ',$initials)}"/>
1206        </xsl:for-each>
1207       
1208        <xsl:if test="not($xml2rfc-private)">
1209          <xsl:choose>
1210            <xsl:when test="/rfc/@number">
1211              <meta name="DC.Identifier" content="urn:ietf:rfc:{/rfc/@number}"/>
1212            </xsl:when>
1213            <xsl:when test="/rfc/@docName">
1214              <meta name="DC.Identifier" content="urn:ietf:id:{/rfc/@docName}"/>
1215            </xsl:when>
1216            <xsl:otherwise/>
1217          </xsl:choose>
1218          <xsl:variable name="month"><xsl:call-template name="get-month-as-num"/></xsl:variable>
1219          <meta name="DC.Date.Issued" scheme="ISO8601" content="{/rfc/front/date/@year}-{$month}"/>
1220 
1221          <xsl:if test="/rfc/@obsoletes!=''">
1222            <xsl:call-template name="rfclist-for-dcmeta">
1223              <xsl:with-param name="list" select="/rfc/@obsoletes"/>
1224            </xsl:call-template>
1225          </xsl:if>
1226        </xsl:if>
1227 
1228        <xsl:if test="/rfc/front/abstract">
1229          <meta name="DC.Description.Abstract" content="{normalize-space(/rfc/front/abstract)}"/>
1230        </xsl:if>     
1231      </xsl:if>     
1232    </head>
1233    <body>
1234      <!-- insert diagnostics -->
1235      <xsl:call-template name="insert-diagnostics"/>
1236
1237      <xsl:apply-templates select="front"/>
1238      <xsl:apply-templates select="middle"/>
1239      <xsl:apply-templates select="back"/>
1240    </body>
1241  </html>
1242</xsl:template>               
1243
1244
1245<xsl:template match="t">
1246  <xsl:if test="preceding-sibling::section or preceding-sibling::appendix">
1247    <xsl:call-template name="warning">
1248      <xsl:with-param name="msg">The paragraph below is misplaced; maybe a section is closed in the wrong place: </xsl:with-param>
1249      <xsl:with-param name="msg2"><xsl:value-of select="."/></xsl:with-param>
1250    </xsl:call-template>
1251  </xsl:if>
1252  <xsl:choose>
1253    <xsl:when test="@anchor">
1254      <div xmlns="http://www.w3.org/1999/xhtml" id="{@anchor}"><xsl:apply-templates mode="t-content" select="node()[1]"/></div>
1255    </xsl:when>
1256    <xsl:otherwise>
1257      <xsl:apply-templates mode="t-content" select="node()[1]"/>
1258    </xsl:otherwise>
1259  </xsl:choose>
1260</xsl:template>
1261
1262<!-- for t-content, dispatch to default templates if it's block-level content -->
1263<xsl:template mode="t-content" match="list|figure|texttable">
1264  <!-- <xsl:comment>t-content block-level</xsl:comment>  -->
1265  <xsl:apply-templates select="."/>
1266  <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content"/>
1267</xsl:template>               
1268               
1269<!-- ... otherwise group into p elements -->
1270<xsl:template mode="t-content" match="*|node()">
1271  <xsl:variable name="p">
1272    <xsl:call-template name="get-paragraph-number"/>
1273  </xsl:variable>
1274
1275  <!-- do not open a new p element if this is a whitespace-only text node and no siblings follow --> 
1276  <xsl:if test="not(self::text() and normalize-space(.)='' and not(following-sibling::node()))">
1277    <p xmlns="http://www.w3.org/1999/xhtml">
1278      <xsl:if test="$p!='' and not(ancestor::ed:del) and not(ancestor::ed:ins) and not(ancestor::x:lt) and count(preceding-sibling::node())=0">
1279        <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$p"/></xsl:attribute>
1280      </xsl:if>
1281      <xsl:call-template name="insertInsDelClass"/>
1282      <xsl:call-template name="editingMark"/>
1283      <xsl:apply-templates mode="t-content2" select="."/>
1284    </p>
1285  </xsl:if>
1286  <xsl:apply-templates mode="t-content" select="following-sibling::*[self::list or self::figure or self::texttable][1]"/>
1287</xsl:template>               
1288               
1289<xsl:template mode="t-content2" match="*">
1290  <xsl:apply-templates select="."/>
1291  <xsl:if test="not(following-sibling::node()[1] [self::list or self::figure or self::texttable])">
1292    <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content2"/>
1293  </xsl:if>
1294</xsl:template>       
1295
1296<xsl:template mode="t-content2" match="text()">
1297  <xsl:apply-templates select="."/>
1298  <xsl:if test="not(following-sibling::node()[1] [self::list or self::figure or self::texttable])">
1299    <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content2"/>
1300  </xsl:if>
1301</xsl:template>               
1302
1303<xsl:template match="title">
1304  <xsl:apply-templates/>
1305</xsl:template>
1306
1307<xsl:template name="insertTitle">
1308  <xsl:choose>
1309    <xsl:when test="@ed:old-title">
1310      <del xmlns="http://www.w3.org/1999/xhtml">
1311        <xsl:if test="ancestor-or-self::*[@ed:entered-by] and @ed:datetime">
1312          <xsl:attribute name="title"><xsl:value-of select="concat(@ed:datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
1313        </xsl:if>
1314        <xsl:value-of select="@ed:old-title"/>
1315      </del>
1316      <ins xmlns="http://www.w3.org/1999/xhtml">
1317        <xsl:if test="ancestor-or-self::*[@ed:entered-by] and @ed:datetime">
1318          <xsl:attribute name="title"><xsl:value-of select="concat(@ed:datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
1319        </xsl:if>
1320        <xsl:value-of select="@title"/>
1321      </ins>
1322    </xsl:when>
1323    <xsl:otherwise>
1324      <xsl:value-of select="@title"/>
1325    </xsl:otherwise>
1326  </xsl:choose>
1327</xsl:template>
1328
1329<xsl:template match="section|appendix">
1330
1331  <xsl:variable name="sectionNumber">
1332    <xsl:choose>
1333      <xsl:when test="@myns:unnumbered"/>
1334      <xsl:otherwise><xsl:call-template name="get-section-number"/></xsl:otherwise>
1335    </xsl:choose>
1336  </xsl:variable>
1337   
1338  <xsl:if test="not(ancestor::section) and not(@myns:notoclink)">
1339    <xsl:call-template name="insert-conditional-hrule"/>
1340  </xsl:if>
1341 
1342  <xsl:variable name="elemtype">
1343    <xsl:choose>
1344      <xsl:when test="count(ancestor::section) = 0">h1</xsl:when>
1345      <xsl:when test="count(ancestor::section) = 1">h2</xsl:when>
1346      <xsl:when test="count(ancestor::section) = 2">h3</xsl:when>
1347      <xsl:when test="count(ancestor::section) = 3">h4</xsl:when>
1348      <xsl:otherwise>h5</xsl:otherwise>
1349    </xsl:choose>
1350  </xsl:variable>
1351 
1352  <!-- process irefs immediadetely following the section so that their anchor
1353  actually is the section heading -->
1354  <xsl:apply-templates select="iref[count(preceding-sibling::*[not(self::iref)])=0]"/>
1355
1356  <xsl:element namespace="http://www.w3.org/1999/xhtml" name="{$elemtype}">
1357    <xsl:if test="$sectionNumber!=''">
1358      <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber"/></xsl:attribute>
1359    </xsl:if>
1360    <xsl:choose>
1361      <xsl:when test="$sectionNumber='1'">
1362        <!-- pagebreak, this the first section -->
1363        <xsl:attribute name="class">np</xsl:attribute>
1364      </xsl:when>
1365      <xsl:when test="not(ancestor::section) and not(@myns:notoclink)">
1366        <xsl:call-template name="insert-conditional-pagebreak"/>
1367      </xsl:when>
1368      <xsl:otherwise/>
1369    </xsl:choose>
1370   
1371    <xsl:call-template name="insertInsDelClass"/>
1372       
1373    <xsl:if test="$sectionNumber!=''">
1374      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$anchor-prefix}.section.{$sectionNumber}">
1375        <xsl:call-template name="emit-section-number">
1376          <xsl:with-param name="no" select="$sectionNumber"/>
1377        </xsl:call-template>
1378      </a>
1379      <xsl:text> </xsl:text>
1380    </xsl:if>
1381   
1382    <!-- issue tracking? -->
1383    <xsl:if test="@ed:resolves">
1384      <xsl:call-template name="insert-issue-pointer"/>
1385    </xsl:if>
1386   
1387    <xsl:choose>
1388      <xsl:when test="@anchor">
1389        <a xmlns="http://www.w3.org/1999/xhtml" id="{@anchor}" href="#{@anchor}"><xsl:call-template name="insertTitle"/></a>
1390      </xsl:when>
1391      <xsl:otherwise>
1392        <xsl:call-template name="insertTitle"/>
1393      </xsl:otherwise>
1394    </xsl:choose>
1395  </xsl:element>
1396  <!-- continue with all child elements but the irefs processed above -->
1397  <xsl:apply-templates select="*[not(self::iref)]|iref[count(preceding-sibling::*[not(self::iref)])!=0]"/>
1398</xsl:template>
1399
1400<xsl:template match="spanx[@style='emph' or not(@style)]">
1401  <em xmlns="http://www.w3.org/1999/xhtml">
1402    <xsl:if test="@anchor">
1403      <xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute>
1404    </xsl:if>
1405    <xsl:apply-templates/>
1406  </em>
1407</xsl:template>
1408
1409<xsl:template match="spanx[@style='verb']">
1410  <samp xmlns="http://www.w3.org/1999/xhtml">
1411    <xsl:if test="@anchor">
1412      <xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute>
1413    </xsl:if>
1414    <xsl:apply-templates/>
1415  </samp>
1416</xsl:template>
1417
1418<xsl:template match="spanx[@style='strong']">
1419  <strong xmlns="http://www.w3.org/1999/xhtml">
1420    <xsl:if test="@anchor">
1421      <xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute>
1422    </xsl:if>
1423    <xsl:apply-templates/>
1424  </strong>
1425</xsl:template>
1426
1427<xsl:template name="insert-blank-lines">
1428  <xsl:param name="no"/>
1429  <xsl:choose>
1430    <xsl:when test="$no &lt;= 0">
1431      <br xmlns="http://www.w3.org/1999/xhtml"/>
1432      <!-- done -->
1433    </xsl:when>
1434    <xsl:otherwise>
1435      <br xmlns="http://www.w3.org/1999/xhtml"/>
1436      <xsl:call-template name="insert-blank-lines">
1437        <xsl:with-param name="no" select="$no - 1"/>
1438      </xsl:call-template>
1439    </xsl:otherwise>
1440  </xsl:choose>
1441</xsl:template>
1442
1443<xsl:template match="vspace[not(@blankLines)]">
1444  <br xmlns="http://www.w3.org/1999/xhtml"/>
1445</xsl:template>
1446
1447<xsl:template match="vspace">
1448  <xsl:call-template name="insert-blank-lines">
1449    <xsl:with-param name="no" select="@blankLines"/>
1450  </xsl:call-template>
1451</xsl:template>
1452
1453<!-- keep the root for the case when we process XSLT-inline markup -->
1454<xsl:variable name="src" select="/"/>
1455
1456<xsl:template name="render-section-ref">
1457  <xsl:param name="from"/>
1458  <xsl:param name="to"/>
1459
1460  <xsl:variable name="refname">
1461    <xsl:for-each select="$to">
1462      <xsl:call-template name="get-section-type">
1463        <xsl:with-param name="prec" select="$from/preceding-sibling::node()[1]"/>
1464      </xsl:call-template>
1465    </xsl:for-each>
1466  </xsl:variable>
1467  <xsl:variable name="refnum">
1468    <xsl:for-each select="$to">
1469      <xsl:call-template name="get-section-number"/>
1470    </xsl:for-each>
1471  </xsl:variable>
1472  <xsl:attribute name="title">
1473    <xsl:value-of select="$to/@title"/>
1474  </xsl:attribute>
1475  <xsl:choose>
1476    <xsl:when test="@format='counter'">
1477      <xsl:value-of select="$refnum"/>
1478    </xsl:when>
1479    <xsl:when test="@format='title'">
1480      <xsl:value-of select="$to/@title"/>
1481    </xsl:when>
1482    <xsl:otherwise>
1483      <xsl:value-of select="normalize-space(concat($refname,' ',$refnum))"/>
1484    </xsl:otherwise>
1485  </xsl:choose>
1486</xsl:template>
1487
1488<xsl:template match="xref[node()]">
1489
1490  <xsl:variable name="target" select="@target"/>
1491  <xsl:variable name="node" select="$src//*[@anchor=$target]"/>
1492  <xsl:variable name="anchor"><xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/></xsl:variable>
1493
1494  <xsl:choose>
1495
1496    <!-- x:fmt='none': do not generate any links -->
1497    <xsl:when test="@x:fmt='none'">
1498      <xsl:choose>
1499        <xsl:when test="name($node)='reference'">
1500          <cite xmlns="http://www.w3.org/1999/xhtml" title="{normalize-space($node/front/title)}">
1501            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1502              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1503            </xsl:if>
1504            <!-- insert id when a backlink to this xref is needed in the index -->
1505            <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
1506              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1507            </xsl:if>
1508            <xsl:apply-templates/>
1509          </cite>
1510        </xsl:when>
1511        <xsl:otherwise>
1512          <xsl:apply-templates/>
1513        </xsl:otherwise>
1514      </xsl:choose>
1515    </xsl:when>
1516 
1517    <!-- Other x:fmt values than "none": unsupported -->
1518    <xsl:when test="@x:fmt and @x:fmt!='none'">
1519      <xsl:message>unknown xref/@x:fmt extension: <xsl:value-of select="@x:fmt"/></xsl:message>
1520      <span xmlns="http://www.w3.org/1999/xhtml" class="error">unknown xref/@x:fmt extension: <xsl:value-of select="@x:fmt"/></span>
1521    </xsl:when>
1522
1523    <!-- Section links -->
1524    <xsl:when test="name($node)='section' or name($node)='appendix'">
1525      <xsl:apply-templates/>
1526      <xsl:variable name="context" select="."/>
1527      <xsl:text> (</xsl:text>
1528      <a xmlns="http://www.w3.org/1999/xhtml" href="#{@target}">
1529        <!-- insert id when a backlink to this xref is needed in the index -->
1530        <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
1531          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1532        </xsl:if>
1533        <xsl:call-template name="render-section-ref">
1534          <xsl:with-param name="from" select="."/>
1535          <xsl:with-param name="to" select="$node"/>
1536        </xsl:call-template>
1537      </a>
1538      <xsl:text>)</xsl:text>
1539    </xsl:when>
1540
1541    <xsl:otherwise>
1542      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target}"><xsl:apply-templates/></a>
1543      <xsl:for-each select="$src/rfc/back/references//reference[@anchor=$target]">
1544        <xsl:text> </xsl:text>
1545        <cite xmlns="http://www.w3.org/1999/xhtml" title="{normalize-space(front/title)}">
1546          <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1547            <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1548          </xsl:if>
1549          <xsl:call-template name="referencename">
1550             <xsl:with-param name="node" select="."/>
1551          </xsl:call-template>
1552        </cite>
1553      </xsl:for-each>
1554    </xsl:otherwise>
1555  </xsl:choose>
1556
1557</xsl:template>
1558               
1559<xsl:template match="xref[not(node())]">
1560
1561  <xsl:variable name="context" select="."/>
1562  <xsl:variable name="target" select="@target"/>
1563  <xsl:variable name="anchor"><xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/></xsl:variable>
1564  <xsl:variable name="node" select="$src//*[@anchor=$target]"/>
1565  <xsl:if test="count($node)=0 and not(ancestor::ed:del)">
1566    <xsl:message>Undefined target: <xsl:value-of select="@target"/></xsl:message>
1567    <span xmlns="http://www.w3.org/1999/xhtml" class="error">Undefined target: <xsl:value-of select="@target"/></span>
1568  </xsl:if>
1569
1570  <xsl:choose>
1571 
1572    <!-- Section links -->
1573    <xsl:when test="name($node)='section' or name($node)='appendix'">
1574      <a xmlns="http://www.w3.org/1999/xhtml" href="#{@target}">
1575        <!-- insert id when a backlink to this xref is needed in the index -->
1576        <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
1577          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1578        </xsl:if>
1579        <xsl:call-template name="render-section-ref">
1580          <xsl:with-param name="from" select="."/>
1581          <xsl:with-param name="to" select="$node"/>
1582        </xsl:call-template>
1583      </a>
1584    </xsl:when>
1585
1586    <!-- Figure links -->
1587    <xsl:when test="name($node)='figure'">
1588      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target}">
1589        <xsl:variable name="figcnt">
1590          <xsl:for-each select="$node">
1591            <xsl:number level="any" count="figure[@title!='' or @anchor!='']"/>
1592          </xsl:for-each>
1593        </xsl:variable>
1594        <xsl:choose>
1595          <xsl:when test="@format='counter'">
1596            <xsl:value-of select="$figcnt"/>
1597          </xsl:when>
1598          <xsl:when test="@format='title'">
1599            <xsl:value-of select="$node/@title"/>
1600          </xsl:when>
1601          <xsl:otherwise>
1602            <xsl:value-of select="normalize-space(concat('Figure ',$figcnt))"/>
1603          </xsl:otherwise>
1604        </xsl:choose>
1605      </a>
1606    </xsl:when>
1607   
1608    <!-- Table links -->
1609    <xsl:when test="name($node)='texttable'">
1610      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target}">
1611        <xsl:variable name="tabcnt">
1612          <xsl:for-each select="$node">
1613            <xsl:number level="any" count="texttable[@title!='' or @anchor!='']"/>
1614          </xsl:for-each>
1615        </xsl:variable>
1616        <xsl:choose>
1617          <xsl:when test="@format='counter'">
1618            <xsl:value-of select="$tabcnt"/>
1619          </xsl:when>
1620          <xsl:when test="@format='title'">
1621            <xsl:value-of select="$node/@title"/>
1622          </xsl:when>
1623          <xsl:otherwise>
1624            <xsl:value-of select="normalize-space(concat('Table ',$tabcnt))"/>
1625          </xsl:otherwise>
1626        </xsl:choose>
1627      </a>
1628    </xsl:when>
1629   
1630    <!-- Reference links -->
1631    <xsl:when test="name($node)='reference'">
1632
1633      <xsl:variable name="href">
1634        <xsl:call-template name="computed-target">
1635          <xsl:with-param name="bib" select="$node"/>
1636          <xsl:with-param name="ref" select="."/>
1637        </xsl:call-template>
1638      </xsl:variable>
1639     
1640      <xsl:variable name="sec">
1641        <xsl:choose>
1642          <xsl:when test="starts-with(@x:rel,'#') and not(@x:sec) and $node/x:source/@href">
1643            <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
1644            <xsl:variable name="nodes" select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]"/>
1645            <xsl:if test="not($nodes)">
1646              <xsl:call-template name="error">
1647                <xsl:with-param name="msg">Anchor '<xsl:value-of select="substring-after(current()/@x:rel,'#')"/>' not found in <xsl:value-of select="$node/x:source/@href"/>.</xsl:with-param>
1648              </xsl:call-template>
1649            </xsl:if>
1650            <xsl:for-each select="$nodes">
1651              <xsl:call-template name="get-section-number"/>
1652            </xsl:for-each>
1653          </xsl:when>
1654          <xsl:otherwise>
1655            <xsl:value-of select="@x:sec"/>
1656          </xsl:otherwise>
1657        </xsl:choose>
1658      </xsl:variable>
1659
1660      <xsl:variable name="fmt">
1661        <xsl:choose>
1662          <xsl:when test="@x:fmt!=''"><xsl:value-of select="@x:fmt"/></xsl:when>
1663          <xsl:when test="ancestor::artwork">,</xsl:when>
1664          <xsl:otherwise>of</xsl:otherwise>
1665        </xsl:choose>
1666      </xsl:variable>
1667
1668      <xsl:variable name="title">
1669        <xsl:choose>
1670          <xsl:when test="starts-with(@x:rel,'#') and not(@x:sec) and $node/x:source/@href">
1671            <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
1672            <xsl:variable name="nodes" select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]"/>
1673            <xsl:if test="not($nodes)">
1674              <xsl:call-template name="error">
1675                <xsl:with-param name="msg">Anchor '<xsl:value-of select="substring-after(current()/@x:rel,'#')"/>' not found in <xsl:value-of select="$node/x:source/@href"/>.</xsl:with-param>
1676              </xsl:call-template>
1677            </xsl:if>
1678            <xsl:for-each select="$nodes">
1679              <xsl:value-of select="@title"/>
1680            </xsl:for-each>
1681          </xsl:when>
1682          <xsl:otherwise/>
1683        </xsl:choose>
1684      </xsl:variable>
1685
1686      <!--
1687      Formats:
1688     
1689        ()      [XXXX] (Section SS)
1690        ,       [XXXX], Section SS
1691        of      Section SS of [XXXX]
1692        sec     Section SS
1693        number  SS
1694      -->
1695     
1696      <xsl:if test="$fmt and not($fmt='()' or $fmt=',' or $fmt='of' or $fmt='sec' or $fmt='anchor' or $fmt='number')">
1697        <xsl:message>unknown xref/@x:fmt extension: <xsl:value-of select="$fmt"/></xsl:message>
1698        <span xmlns="http://www.w3.org/1999/xhtml" class="error">unknown xref/@x:fmt extension: <xsl:value-of select="$fmt"/></span>
1699      </xsl:if>
1700
1701      <xsl:if test="$sec!=''">
1702             
1703        <xsl:choose>
1704          <xsl:when test="$fmt='of' or $fmt='sec'">
1705            <xsl:choose>
1706              <xsl:when test="$href!=''">
1707                <a xmlns="http://www.w3.org/1999/xhtml" href="{$href}">
1708                  <xsl:if test="$title!=''">
1709                    <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1710                  </xsl:if>
1711                  <xsl:if test="$fmt='sec' and $xml2rfc-ext-include-references-in-index='yes'">
1712                    <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1713                  </xsl:if>
1714                  <xsl:text>Section </xsl:text>
1715                  <xsl:value-of select="$sec"/>
1716                </a>
1717              </xsl:when>
1718              <xsl:otherwise>Section <xsl:value-of select="$sec"/></xsl:otherwise>
1719            </xsl:choose>
1720            <xsl:if test="$fmt='of'">
1721              <xsl:text> of </xsl:text>
1722            </xsl:if>
1723          </xsl:when>
1724          <xsl:when test="$fmt='number'">
1725            <xsl:choose>
1726              <xsl:when test="$href!=''">
1727                <a xmlns="http://www.w3.org/1999/xhtml" href="{$href}">
1728                  <xsl:if test="$title!=''">
1729                    <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1730                  </xsl:if>
1731                  <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1732                    <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1733                  </xsl:if>
1734                  <xsl:value-of select="$sec"/>
1735                </a>
1736              </xsl:when>
1737              <xsl:otherwise><xsl:value-of select="$sec"/></xsl:otherwise>
1738            </xsl:choose>
1739          </xsl:when>
1740          <xsl:otherwise/>
1741        </xsl:choose>
1742      </xsl:if>
1743
1744      <xsl:if test="$sec='' or ($fmt!='sec' and $fmt!='number')">
1745        <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target}">
1746          <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1747            <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1748          </xsl:if>
1749          <cite title="{normalize-space($node/front/title)}">
1750            <xsl:variable name="val">
1751              <xsl:call-template name="referencename">
1752                <xsl:with-param name="node" select="$node"/>
1753              </xsl:call-template>
1754            </xsl:variable>
1755            <xsl:choose>
1756              <xsl:when test="$fmt='anchor'">
1757                <!-- remove brackets -->
1758                <xsl:value-of select="substring($val,2,string-length($val)-2)"/>
1759              </xsl:when>
1760              <xsl:otherwise>
1761                <xsl:value-of select="$val"/>
1762              </xsl:otherwise>
1763            </xsl:choose>
1764          </cite>
1765        </a>
1766      </xsl:if>
1767     
1768      <xsl:if test="$sec!=''">
1769        <xsl:choose>
1770          <xsl:when test="$fmt='()'">
1771            <xsl:text> (</xsl:text>
1772            <xsl:choose>
1773              <xsl:when test="$href!=''">
1774                <a xmlns="http://www.w3.org/1999/xhtml" href="{$href}">Section <xsl:value-of select="$sec"/></a>
1775              </xsl:when>
1776              <xsl:otherwise>Section <xsl:value-of select="$sec"/></xsl:otherwise>
1777            </xsl:choose>
1778            <xsl:text>)</xsl:text>
1779          </xsl:when>
1780          <xsl:when test="$fmt=','">
1781            <xsl:text>, </xsl:text>
1782            <xsl:choose>
1783              <xsl:when test="$href!=''">
1784                <a xmlns="http://www.w3.org/1999/xhtml" href="{$href}">
1785                  <xsl:if test="$title!=''">
1786                    <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
1787                  </xsl:if>
1788                  <xsl:text>Section </xsl:text>
1789                  <xsl:value-of select="$sec"/>
1790                </a>
1791              </xsl:when>
1792              <xsl:otherwise>Section <xsl:value-of select="$sec"/></xsl:otherwise>
1793            </xsl:choose>
1794          </xsl:when>
1795          <xsl:otherwise/>
1796        </xsl:choose>
1797      </xsl:if>
1798    </xsl:when>
1799   
1800    <xsl:otherwise>
1801      <xsl:message>xref to unknown element: <xsl:value-of select="name($node)"/></xsl:message>
1802      <span xmlns="http://www.w3.org/1999/xhtml" class="error">xref to unknown element: <xsl:value-of select="name($node)"/></span>
1803    </xsl:otherwise>
1804  </xsl:choose>
1805</xsl:template>
1806
1807
1808<!-- mark unmatched elements red -->
1809
1810<xsl:template match="*">
1811  <xsl:message>ERROR: no XSLT template for element: &lt;<xsl:value-of select="name()"/>&gt;</xsl:message>   
1812  <tt xmlns="http://www.w3.org/1999/xhtml" class="error">&lt;<xsl:value-of select="name()"/>&gt;</tt>
1813  <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
1814  <tt xmlns="http://www.w3.org/1999/xhtml" class="error">&lt;/<xsl:value-of select="name()"/>&gt;</tt>
1815</xsl:template>
1816
1817<xsl:template match="/">
1818  <xsl:apply-templates select="*"/>
1819</xsl:template>
1820
1821<!-- utility templates -->
1822
1823<xsl:template name="collectLeftHeaderColumn">
1824  <xsl:param name="mode"/>
1825  <!-- default case -->
1826  <xsl:if test="not($xml2rfc-private)">
1827    <myns:item>Network Working Group</myns:item>
1828    <myns:item>
1829       <xsl:choose>
1830        <xsl:when test="/rfc/@ipr and not(/rfc/@number)">Internet Draft</xsl:when>
1831        <xsl:otherwise>Request for Comments: <xsl:value-of select="/rfc/@number"/></xsl:otherwise>
1832      </xsl:choose>
1833    </myns:item>
1834    <xsl:if test="/rfc/@docName and $mode!='nroff'">
1835      <myns:item>
1836        &lt;<xsl:value-of select="/rfc/@docName"/>&gt;
1837      </myns:item>
1838    </xsl:if>
1839    <xsl:if test="/rfc/@obsoletes and /rfc/@obsoletes!=''">
1840      <myns:item>
1841        <xsl:text>Obsoletes: </xsl:text>
1842        <xsl:call-template name="rfclist">
1843          <xsl:with-param name="list" select="normalize-space(/rfc/@obsoletes)"/>
1844        </xsl:call-template>
1845        <xsl:if test="not(/rfc/@number)"> (if approved)</xsl:if>
1846      </myns:item>
1847    </xsl:if>
1848    <xsl:if test="/rfc/@seriesNo">
1849       <myns:item>
1850        <xsl:choose>
1851          <xsl:when test="/rfc/@category='bcp'">BCP: <xsl:value-of select="/rfc/@seriesNo"/></xsl:when>
1852          <xsl:when test="/rfc/@category='info'">FYI: <xsl:value-of select="/rfc/@seriesNo"/></xsl:when>
1853          <xsl:when test="/rfc/@category='std'">STD: <xsl:value-of select="/rfc/@seriesNo"/></xsl:when>
1854          <xsl:otherwise><xsl:value-of select="concat(/rfc/@category,': ',/rfc/@seriesNo)"/></xsl:otherwise>
1855        </xsl:choose>
1856      </myns:item>
1857    </xsl:if>
1858    <xsl:if test="/rfc/@updates and /rfc/@updates!=''">
1859      <myns:item>
1860        <xsl:text>Updates: </xsl:text>
1861          <xsl:call-template name="rfclist">
1862             <xsl:with-param name="list" select="normalize-space(/rfc/@updates)"/>
1863          </xsl:call-template>
1864          <xsl:if test="not(/rfc/@number)"> (if approved)</xsl:if>
1865      </myns:item>
1866    </xsl:if>
1867    <xsl:if test="$mode!='nroff'">
1868      <myns:item>
1869        <xsl:choose>
1870          <xsl:when test="/rfc/@number">
1871            <xsl:text>Category: </xsl:text>
1872          </xsl:when>
1873          <xsl:otherwise>
1874            <xsl:text>Intended status: </xsl:text>
1875          </xsl:otherwise>
1876        </xsl:choose>
1877        <xsl:call-template name="get-category-long"/>
1878      </myns:item>
1879    </xsl:if>
1880    <xsl:if test="/rfc/@ipr and not(/rfc/@number)">
1881       <myns:item>Expires: <xsl:call-template name="expirydate"/></myns:item>
1882    </xsl:if>
1883  </xsl:if>
1884   
1885  <!-- private case -->
1886  <xsl:if test="$xml2rfc-private">
1887    <myns:item><xsl:value-of select="$xml2rfc-private"/></myns:item>
1888  </xsl:if>
1889</xsl:template>
1890
1891<xsl:template name="collectRightHeaderColumn">
1892  <xsl:for-each select="author">
1893    <xsl:variable name="initials">
1894      <xsl:call-template name="format-initials"/>
1895    </xsl:variable>
1896    <xsl:if test="@surname">
1897      <myns:item>
1898        <xsl:value-of select="concat($initials,' ',@surname)"/>
1899        <xsl:if test="@role">
1900          <xsl:choose>
1901            <xsl:when test="@role='editor'">
1902              <xsl:text>, Editor</xsl:text>
1903            </xsl:when>
1904            <xsl:otherwise>
1905              <xsl:text>, </xsl:text><xsl:value-of select="@role"/>
1906            </xsl:otherwise>
1907          </xsl:choose>
1908        </xsl:if>
1909      </myns:item>
1910    </xsl:if>
1911    <xsl:variable name="org">
1912      <xsl:choose>
1913        <xsl:when test="organization/@abbrev"><xsl:value-of select="organization/@abbrev"/></xsl:when>
1914        <xsl:otherwise><xsl:value-of select="organization"/></xsl:otherwise>
1915      </xsl:choose>
1916    </xsl:variable>
1917    <xsl:variable name="orgOfFollowing">
1918      <xsl:choose>
1919        <xsl:when test="following-sibling::*[1]/organization/@abbrev"><xsl:value-of select="following-sibling::*[1]/organization/@abbrev"/></xsl:when>
1920        <xsl:otherwise><xsl:value-of select="following-sibling::*/organization"/></xsl:otherwise>
1921      </xsl:choose>
1922    </xsl:variable>
1923    <xsl:if test="$org != $orgOfFollowing and $org != ''">
1924      <myns:item><xsl:value-of select="$org"/></myns:item>
1925    </xsl:if>
1926  </xsl:for-each>
1927  <myns:item>
1928    <xsl:value-of select="concat(date/@month,' ',date/@year)"/>
1929  </myns:item>
1930</xsl:template>
1931
1932
1933<xsl:template name="emitheader">
1934  <xsl:param name="lc"/>
1935  <xsl:param name="rc"/>
1936
1937  <xsl:for-each select="$lc/myns:item | $rc/myns:item">
1938    <xsl:variable name="pos" select="position()"/>
1939    <xsl:if test="$pos &lt; count($lc/myns:item) + 1 or $pos &lt; count($rc/myns:item) + 1">
1940      <tr xmlns="http://www.w3.org/1999/xhtml">
1941        <td class="header left"><xsl:call-template name="copynodes"><xsl:with-param name="nodes" select="$lc/myns:item[$pos]/node()"/></xsl:call-template></td>
1942        <td class="header right"><xsl:call-template name="copynodes"><xsl:with-param name="nodes" select="$rc/myns:item[$pos]/node()"/></xsl:call-template></td>
1943      </tr>
1944    </xsl:if>
1945  </xsl:for-each>
1946</xsl:template>
1947
1948<!-- convenience template that avoids copying namespace nodes we don't want -->
1949<xsl:template name="copynodes">
1950  <xsl:param name="nodes"/>
1951  <xsl:for-each select="$nodes">
1952    <xsl:choose>
1953      <xsl:when test="namespace-uri()='http://www.w3.org/1999/xhtml'">
1954        <xsl:element namespace="{namespace-uri()}" name="{name()}">
1955          <xsl:copy-of select="@*|node()"/>
1956        </xsl:element>
1957      </xsl:when>
1958      <xsl:when test="self::*">
1959        <xsl:element namespace="http://www.w3.org/1999/xhtml" name="{name()}">
1960          <xsl:copy-of select="@*|node()"/>
1961        </xsl:element>
1962      </xsl:when>
1963      <!-- workaround for opera, remove when Opera > 9.0.x comes out -->
1964      <xsl:when test="self::text()">
1965        <xsl:value-of select="."/>
1966      </xsl:when>
1967      <xsl:otherwise>
1968        <xsl:copy-of select="."/>
1969      </xsl:otherwise>
1970    </xsl:choose>
1971  </xsl:for-each>
1972</xsl:template>
1973
1974
1975<xsl:template name="expirydate">
1976  <xsl:variable name="date" select="/rfc/front/date"/>
1977  <xsl:choose>
1978      <xsl:when test="$date/@month='January'">July <xsl:value-of select="$date/@year"/></xsl:when>
1979      <xsl:when test="$date/@month='February'">August <xsl:value-of select="$date/@year"/></xsl:when>
1980      <xsl:when test="$date/@month='March'">September <xsl:value-of select="$date/@year"/></xsl:when>
1981      <xsl:when test="$date/@month='April'">October <xsl:value-of select="$date/@year"/></xsl:when>
1982      <xsl:when test="$date/@month='May'">November <xsl:value-of select="$date/@year"/></xsl:when>
1983      <xsl:when test="$date/@month='June'">December <xsl:value-of select="$date/@year"/></xsl:when>
1984      <xsl:when test="$date/@month='July'">January <xsl:value-of select="$date/@year + 1"/></xsl:when>
1985      <xsl:when test="$date/@month='August'">February <xsl:value-of select="$date/@year + 1"/></xsl:when>
1986      <xsl:when test="$date/@month='September'">March <xsl:value-of select="$date/@year + 1"/></xsl:when>
1987      <xsl:when test="$date/@month='October'">April <xsl:value-of select="$date/@year + 1"/></xsl:when>
1988      <xsl:when test="$date/@month='November'">May <xsl:value-of select="$date/@year + 1"/></xsl:when>
1989      <xsl:when test="$date/@month='December'">June <xsl:value-of select="$date/@year + 1"/></xsl:when>
1990        <xsl:otherwise>WRONG SYNTAX FOR MONTH</xsl:otherwise>
1991     </xsl:choose>
1992</xsl:template>
1993
1994<xsl:template name="get-month-as-num">
1995  <xsl:variable name="date" select="/rfc/front/date"/>
1996  <xsl:choose>
1997      <xsl:when test="$date/@month='January'">01</xsl:when>
1998      <xsl:when test="$date/@month='February'">02</xsl:when>
1999      <xsl:when test="$date/@month='March'">03</xsl:when>
2000      <xsl:when test="$date/@month='April'">04</xsl:when>
2001      <xsl:when test="$date/@month='May'">05</xsl:when>
2002      <xsl:when test="$date/@month='June'">06</xsl:when>
2003      <xsl:when test="$date/@month='July'">07</xsl:when>
2004      <xsl:when test="$date/@month='August'">08</xsl:when>
2005      <xsl:when test="$date/@month='September'">09</xsl:when>
2006      <xsl:when test="$date/@month='October'">10</xsl:when>
2007      <xsl:when test="$date/@month='November'">11</xsl:when>
2008      <xsl:when test="$date/@month='December'">12</xsl:when>
2009        <xsl:otherwise>WRONG SYNTAX FOR MONTH</xsl:otherwise>
2010     </xsl:choose>
2011</xsl:template>
2012
2013<!-- produce back section with author information -->
2014<xsl:template name="get-authors-section-title">
2015  <xsl:choose>
2016    <xsl:when test="count(/rfc/front/author)=1">Author's Address</xsl:when>
2017    <xsl:otherwise>Authors' Addresses</xsl:otherwise>
2018  </xsl:choose>
2019</xsl:template>
2020
2021<xsl:template name="get-authors-section-number">
2022  <xsl:if test="/*/x:assign-section-number[@builtin-target='authors']">
2023    <xsl:value-of select="/*/x:assign-section-number[@builtin-target='authors']/@number"/>
2024  </xsl:if>
2025</xsl:template>
2026
2027<xsl:template name="insertAuthors">
2028
2029  <xsl:call-template name="insert-conditional-hrule"/>
2030 
2031  <xsl:variable name="number">
2032    <xsl:call-template name="get-authors-section-number"/>
2033  </xsl:variable>
2034   
2035  <h1 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.authors">
2036    <xsl:call-template name="insert-conditional-pagebreak"/>
2037    <xsl:if test="$number != ''">
2038      <a href="#{$anchor-prefix}.section.{$number}" id="{$anchor-prefix}.section.{$number}"><xsl:value-of select="$number"/>.</a>
2039      <xsl:text> </xsl:text>
2040    </xsl:if>
2041    <a href="#{$anchor-prefix}.authors"><xsl:call-template name="get-authors-section-title"/></a>
2042  </h1>
2043
2044  <xsl:apply-templates select="/rfc/front/author"/>
2045</xsl:template>
2046
2047
2048
2049<!-- insert copyright statement -->
2050
2051<xsl:template name="insertCopyright" myns:namespaceless-elements="xml2rfc">
2052
2053  <xsl:choose>
2054    <xsl:when test="$ipr-rfc3667">
2055      <section title="Full Copyright Statement" anchor="{$anchor-prefix}.copyright" myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2056        <t>
2057          <xsl:choose>
2058            <xsl:when test="$ipr-rfc4748">
2059              Copyright © The IETF Trust (<xsl:value-of select="/rfc/front/date/@year"/>).
2060            </xsl:when>
2061            <xsl:otherwise>
2062              Copyright © The Internet Society (<xsl:value-of select="/rfc/front/date/@year"/>).
2063            </xsl:otherwise>
2064          </xsl:choose>
2065        </t>
2066        <t>
2067          This document is subject to the rights, licenses and restrictions
2068          contained in BCP 78<xsl:if test="/rfc/@submissionType='independent'"> and at <eref target="http://www.rfc-editor.org/copyright.html"/></xsl:if>, and except as set forth therein, the authors
2069          retain all their rights.
2070        </t>
2071        <t>
2072          <xsl:choose>
2073            <xsl:when test="$ipr-rfc4748">
2074              This document and the information contained herein are provided
2075              on an &#8220;AS IS&#8221; basis and THE CONTRIBUTOR,
2076              THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY),
2077              THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING
2078              TASK FORCE DISCLAIM ALL WARRANTIES,
2079              EXPRESS OR IMPLIED,
2080              INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
2081              INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
2082              WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
2083            </xsl:when>
2084            <xsl:otherwise>
2085              This document and the information contained herein are provided
2086              on an &#8220;AS IS&#8221; basis and THE CONTRIBUTOR,
2087              THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY),
2088              THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM
2089              ALL WARRANTIES,
2090              EXPRESS OR IMPLIED,
2091              INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
2092              INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
2093              WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
2094            </xsl:otherwise>
2095          </xsl:choose>
2096        </t>
2097      </section>   
2098    </xsl:when>
2099    <xsl:otherwise>
2100      <!-- <http://tools.ietf.org/html/rfc2026#section-10.4> -->
2101      <section title="Full Copyright Statement" anchor="{$anchor-prefix}.copyright" myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2102        <t>
2103          Copyright © The Internet Society (<xsl:value-of select="/rfc/front/date/@year"/>). All Rights Reserved.
2104        </t>
2105        <t>
2106          This document and translations of it may be copied and furnished to
2107          others, and derivative works that comment on or otherwise explain it
2108          or assist in its implementation may be prepared, copied, published and
2109          distributed, in whole or in part, without restriction of any kind,
2110          provided that the above copyright notice and this paragraph are
2111          included on all such copies and derivative works. However, this
2112          document itself may not be modified in any way, such as by removing
2113          the copyright notice or references to the Internet Society or other
2114          Internet organizations, except as needed for the purpose of
2115          developing Internet standards in which case the procedures for
2116          copyrights defined in the Internet Standards process must be
2117          followed, or as required to translate it into languages other than
2118          English.
2119        </t>
2120        <t>
2121          The limited permissions granted above are perpetual and will not be
2122          revoked by the Internet Society or its successors or assignees.
2123        </t>
2124        <t>
2125          This document and the information contained herein is provided on an
2126          &#8220;;AS IS&#8221; basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
2127          TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
2128          BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
2129          HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
2130          MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
2131        </t>
2132      </section>
2133    </xsl:otherwise>
2134  </xsl:choose>
2135
2136  <section title="Intellectual Property" anchor="{$anchor-prefix}.ipr" myns:unnumbered="unnumbered">
2137    <xsl:choose>
2138      <xsl:when test="$ipr-rfc3667">
2139        <t>
2140          The IETF takes no position regarding the validity or scope of any
2141          Intellectual Property Rights or other rights that might be claimed to
2142          pertain to the implementation or use of the technology described in
2143          this document or the extent to which any license under such rights
2144          might or might not be available; nor does it represent that it has
2145          made any independent effort to identify any such rights.  Information
2146          on the procedures with respect to rights in RFC documents
2147          can be found in BCP 78 and BCP 79.
2148        </t>       
2149        <t>
2150          Copies of IPR disclosures made to the IETF Secretariat and any
2151          assurances of licenses to be made available, or the result of an
2152          attempt made to obtain a general license or permission for the use
2153          of such proprietary rights by implementers or users of this
2154          specification can be obtained from the IETF on-line IPR repository
2155          at <eref target="http://www.ietf.org/ipr"/>.
2156        </t>       
2157        <t>
2158          The IETF invites any interested party to bring to its attention any
2159          copyrights, patents or patent applications, or other proprietary
2160          rights that may cover technology that may be required to implement
2161          this standard. Please address the information to the IETF at
2162          <eref target="mailto:ietf-ipr@ietf.org">ietf-ipr@ietf.org</eref>.
2163        </t>       
2164      </xsl:when>
2165      <xsl:otherwise>
2166        <t>
2167          The IETF takes no position regarding the validity or scope of
2168          any intellectual property or other rights that might be claimed
2169          to  pertain to the implementation or use of the technology
2170          described in this document or the extent to which any license
2171          under such rights might or might not be available; neither does
2172          it represent that it has made any effort to identify any such
2173          rights. Information on the IETF's procedures with respect to
2174          rights in standards-track and standards-related documentation
2175          can be found in BCP-11. Copies of claims of rights made
2176          available for publication and any assurances of licenses to
2177          be made available, or the result of an attempt made
2178          to obtain a general license or permission for the use of such
2179          proprietary rights by implementors or users of this
2180          specification can be obtained from the IETF Secretariat.
2181        </t>
2182        <t>
2183          The IETF invites any interested party to bring to its
2184          attention any copyrights, patents or patent applications, or
2185          other proprietary rights which may cover technology that may be
2186          required to practice this standard. Please address the
2187          information to the IETF Executive Director.
2188        </t>
2189        <xsl:if test="$xml2rfc-iprnotified='yes'">
2190          <t>
2191            The IETF has been notified of intellectual property rights
2192            claimed in regard to some or all of the specification contained
2193            in this document. For more information consult the online list
2194            of claimed rights.
2195          </t>
2196        </xsl:if>
2197      </xsl:otherwise>
2198    </xsl:choose>
2199  </section>
2200 
2201  <section title="Acknowledgement" myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2202    <t>
2203      Funding for the RFC Editor function is provided by the IETF
2204      Administrative Support Activity (IASA).
2205    </t>
2206  </section>
2207
2208</xsl:template>
2209
2210
2211<!-- insert CSS style info -->
2212
2213<xsl:template name="insertCss">
2214a {
2215  text-decoration: none;
2216}
2217a.smpl {
2218  color: black;
2219}
2220a:hover {
2221  text-decoration: underline;
2222}
2223a:active {
2224  text-decoration: underline;
2225}
2226address {
2227  margin-top: 1em;
2228  margin-left: 2em;
2229  font-style: normal;
2230}<xsl:if test="//x:blockquote">
2231blockquote {
2232  border-style: solid;
2233  border-color: gray;
2234  border-width: 0 0 0 .25em;
2235  font-style: italic;
2236  padding-left: 0.5em;
2237}</xsl:if>
2238body {<xsl:if test="$xml2rfc-background!=''">
2239  background: url(<xsl:value-of select="$xml2rfc-background"/>) #ffffff left top;</xsl:if>
2240  color: black;
2241  font-family: verdana, helvetica, arial, sans-serif;
2242  font-size: 10pt;
2243}<xsl:if test="//xhtml:p">
2244br.p {
2245  line-height: 150%;
2246}</xsl:if>
2247cite {
2248  font-style: normal;
2249}
2250dd {
2251  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
2252  text-align: justify;</xsl:if>
2253}
2254dl {
2255  margin-left: 2em;
2256}
2257<!-- spacing between two entries in definition lists -->
2258dl.empty dd {
2259  margin-top: .5em;
2260}
2261dl p {
2262  margin-left: 0em;
2263}
2264dt {
2265  margin-top: .5em;
2266}
2267h1 {
2268  font-size: 14pt;
2269  line-height: 21pt;
2270  page-break-after: avoid;
2271}
2272h1.np {
2273  page-break-before: always;
2274}
2275h1 a {
2276  color: #333333;
2277}
2278h2 {
2279  font-size: 12pt;
2280  line-height: 15pt;
2281  page-break-after: avoid;
2282}
2283h2 a {
2284  color: black;
2285}
2286h3 {
2287  font-size: 10pt;
2288  page-break-after: avoid;
2289}
2290h3 a {
2291  color: black;
2292}
2293h4 {
2294  font-size: 10pt;
2295  page-break-after: avoid;
2296}
2297h4 a {
2298  color: black;
2299}
2300h5 {
2301  font-size: 10pt;
2302  page-break-after: avoid;
2303}
2304h5 a {
2305  color: black;
2306}
2307img {
2308  margin-left: 3em;
2309}
2310li {
2311  margin-left: 2em;
2312  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
2313  text-align: justify;</xsl:if>
2314}
2315ol {
2316  margin-left: 2em;
2317  margin-right: 2em;
2318}
2319ol p {
2320  margin-left: 0em;
2321}<xsl:if test="//xhtml:q">
2322q {
2323  font-style: italic;
2324}</xsl:if>
2325p {
2326  margin-left: 2em;
2327  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
2328  text-align: justify;</xsl:if>
2329}
2330pre {
2331  margin-left: 3em;
2332  background-color: lightyellow;
2333  padding: .25em;
2334}
2335pre.text2 {
2336  border-style: dotted;
2337  border-width: 1px;
2338  background-color: #f0f0f0;
2339  width: 69em;
2340}
2341pre.inline {
2342  background-color: white;
2343  padding: 0em;
2344}
2345pre.text {
2346  border-style: dotted;
2347  border-width: 1px;
2348  background-color: #f8f8f8;
2349  width: 69em;
2350}
2351pre.drawing {
2352  border-style: solid;
2353  border-width: 1px;
2354  background-color: #f8f8f8;
2355  padding: 2em;
2356}<xsl:if test="//x:q">
2357q {
2358  font-style: italic;
2359}</xsl:if>
2360table {
2361  margin-left: 2em;
2362}<xsl:if test="//texttable">
2363table.tt {
2364  vertical-align: top;
2365}
2366table.full {
2367  border-style: outset;
2368  border-width: 1px;
2369}
2370table.headers {
2371  border-style: outset;
2372  border-width: 1px;
2373}
2374table.tt td {
2375  vertical-align: top;
2376}
2377table.full td {
2378  border-style: inset;
2379  border-width: 1px;
2380}
2381table.tt th {
2382  vertical-align: top;
2383}
2384table.full th {
2385  border-style: inset;
2386  border-width: 1px;
2387}
2388table.headers th {
2389  border-style: none none inset none;
2390  border-width: 1px;
2391}</xsl:if>
2392table.header {
2393  width: 95%;
2394  font-size: 10pt;
2395  color: white;
2396}
2397td.top {
2398  vertical-align: top;
2399}
2400td.topnowrap {
2401  vertical-align: top;
2402  white-space: nowrap;
2403}
2404td.header {
2405  background-color: gray;
2406  width: 50%;
2407}
2408td.reference {
2409  vertical-align: top;
2410  white-space: nowrap;
2411  padding-right: 1em;
2412}
2413thead {
2414  display:table-header-group;
2415}
2416ul.toc {
2417  list-style: none;
2418  margin-left: 1.5em;
2419  margin-right: 0em;
2420  padding-left: 0em;
2421}
2422li.tocline0 {
2423  line-height: 150%;
2424  font-weight: bold;
2425  font-size: 10pt;
2426  margin-left: 0em;
2427  margin-right: 0em;
2428}
2429li.tocline1 {
2430  line-height: normal;
2431  font-weight: normal;
2432  font-size: 9pt;
2433  margin-left: 0em;
2434  margin-right: 0em;
2435}
2436li.tocline2 {
2437  font-size: 0pt;
2438}
2439ul p {
2440  margin-left: 0em;
2441}
2442ul.ind {
2443  list-style: none;
2444  margin-left: 1.5em;
2445  margin-right: 0em;
2446  padding-left: 0em;
2447}
2448li.indline0 {
2449  font-weight: bold;
2450  line-height: 200%;
2451  margin-left: 0em;
2452  margin-right: 0em;
2453}
2454li.indline1 {
2455  font-weight: normal;
2456  line-height: 150%;
2457  margin-left: 0em;
2458  margin-right: 0em;
2459}
2460<xsl:if test="//x:bcp14">.bcp14 {
2461  font-style: normal;
2462  text-transform: lowercase;
2463  font-variant: small-caps;
2464}</xsl:if><xsl:if test="//x:blockquote">
2465blockquote &gt; * .bcp14 {
2466  font-style: italic;
2467}</xsl:if>
2468.comment {
2469  background-color: yellow;
2470}<xsl:if test="$xml2rfc-editing='yes'">
2471.editingmark {
2472  background-color: khaki;
2473}</xsl:if>
2474.center {
2475  text-align: center;
2476}
2477.error {
2478  color: red;
2479  font-style: italic;
2480  font-weight: bold;
2481}
2482.figure {
2483  font-weight: bold;
2484  text-align: center;
2485  font-size: 9pt;
2486}
2487.filename {
2488  color: #333333;
2489  font-weight: bold;
2490  font-size: 12pt;
2491  line-height: 21pt;
2492  text-align: center;
2493}
2494.fn {
2495  font-weight: bold;
2496}
2497.hidden {
2498  display: none;
2499}
2500.left {
2501  text-align: left;
2502}
2503.right {
2504  text-align: right;
2505}
2506.title {
2507  color: #990000;
2508  font-size: 18pt;
2509  line-height: 18pt;
2510  font-weight: bold;
2511  text-align: center;
2512  margin-top: 36pt;
2513}
2514.vcardline {
2515  display: block;
2516}
2517.warning {
2518  font-size: 14pt;
2519  background-color: yellow;
2520}
2521<xsl:if test="//ed:del|//ed:replace|//ed:ins">del {
2522  color: red;
2523  text-decoration: line-through;
2524}
2525.del {
2526  color: red;
2527  text-decoration: line-through;
2528}
2529ins {
2530  color: green;
2531  text-decoration: underline;
2532}
2533.ins {
2534  color: green;
2535  text-decoration: underline;
2536}
2537div.issuepointer {
2538  float: left;
2539}</xsl:if><xsl:if test="//ed:issue">
2540table.openissue {
2541  background-color: khaki;
2542  border-width: thin;
2543  border-style: solid;
2544  border-color: black;
2545}
2546table.closedissue {
2547  background-color: white;
2548  border-width: thin;
2549  border-style: solid;
2550  border-color: gray;
2551  color: gray;
2552}
2553thead th {
2554  text-align: left;
2555}
2556.bg-issue {
2557  border: solid;
2558  border-width: 1px;
2559  font-size: 7pt;
2560}
2561.closed-issue {
2562  border: solid;
2563  border-width: thin;
2564  background-color: lime;
2565  font-size: smaller;
2566  font-weight: bold;
2567}
2568.open-issue {
2569  border: solid;
2570  border-width: thin;
2571  background-color: red;
2572  font-size: smaller;
2573  font-weight: bold;
2574}
2575.editor-issue {
2576  border: solid;
2577  border-width: thin;
2578  background-color: yellow;
2579  font-size: smaller;
2580  font-weight: bold;
2581}</xsl:if>
2582
2583@media print {
2584  .noprint {
2585    display: none;
2586  }
2587 
2588  a {
2589    color: black;
2590    text-decoration: none;
2591  }
2592
2593  table.header {
2594    width: 90%;
2595  }
2596
2597  td.header {
2598    width: 50%;
2599    color: black;
2600    background-color: white;
2601    vertical-align: top;
2602    font-size: 12pt;
2603  }
2604
2605  ul.toc a::after {
2606    content: leader('.') target-counter(attr(href), page);
2607  }
2608 
2609  a.iref {
2610    content: target-counter(attr(href), page);
2611  }
2612 
2613  .print2col {
2614    column-count: 2;
2615    -moz-column-count: 2;<!-- for Firefox -->
2616    column-fill: auto;<!-- for PrinceXML -->
2617  }
2618<xsl:if test="$xml2rfc-ext-justification='print'">
2619  dd {
2620    text-align: justify;
2621  }
2622  li {
2623    text-align: justify;
2624  }
2625  p {
2626    text-align: justify;
2627  }
2628</xsl:if>}
2629
2630@page {
2631  @top-left {
2632       content: "<xsl:call-template name="get-header-left"/>";
2633  }
2634  @top-right {
2635       content: "<xsl:call-template name="get-header-right"/>";
2636  }
2637  @top-center {
2638       content: "<xsl:call-template name="get-header-center"/>";
2639  }
2640  @bottom-left {
2641       content: "<xsl:call-template name="get-author-summary"/>";
2642  }
2643  @bottom-center {
2644       content: "<xsl:call-template name="get-category-long"/>";
2645  }
2646  @bottom-right {
2647       content: "[Page " counter(page) "]";
2648  }
2649}
2650
2651@page:first {
2652    @top-left {
2653      content: normal;
2654    }
2655    @top-right {
2656      content: normal;
2657    }
2658    @top-center {
2659      content: normal;
2660    }
2661}
2662</xsl:template>
2663
2664
2665<!-- generate the index section -->
2666
2667<xsl:template name="insertSingleIref">
2668  <xsl:choose>
2669    <xsl:when test="@ed:xref">
2670      <!-- special index generator mode -->
2671      <xsl:text>[</xsl:text>
2672      <a xmlns="http://www.w3.org/1999/xhtml" href="#{@ed:xref}"><xsl:value-of select="@ed:xref"/></a>
2673      <xsl:text>, </xsl:text>
2674      <a xmlns="http://www.w3.org/1999/xhtml">
2675        <xsl:variable name="htmluri" select="//reference[@anchor=current()/@ed:xref]/format[@type='HTML']/@target"/>
2676        <xsl:if test="$htmluri">
2677          <xsl:attribute name="href"><xsl:value-of select="concat($htmluri,'#',@ed:frag)"/></xsl:attribute>
2678        </xsl:if>       
2679        <xsl:choose>
2680          <xsl:when test="@primary='true'"><b><xsl:value-of select="@ed:label"/></b></xsl:when>
2681          <xsl:otherwise><xsl:value-of select="@ed:label"/></xsl:otherwise>
2682        </xsl:choose>
2683      </a>
2684      <xsl:text>]</xsl:text>
2685      <xsl:if test="position()!=last()">, </xsl:if>
2686    </xsl:when>
2687    <xsl:otherwise>
2688      <xsl:variable name="_n">
2689        <xsl:call-template name="get-section-number"/>
2690      </xsl:variable>
2691      <xsl:variable name="n">
2692        <xsl:choose>
2693          <xsl:when test="$_n!=''">
2694            <xsl:value-of select="$_n"/>
2695          </xsl:when>
2696          <xsl:otherwise>§</xsl:otherwise>
2697        </xsl:choose>
2698      </xsl:variable>
2699      <xsl:variable name="backlink">
2700        <xsl:choose>
2701          <xsl:when test="self::xref">
2702            <xsl:variable name="target" select="@target"/>
2703            <xsl:text>#</xsl:text>
2704            <xsl:value-of select="$anchor-prefix"/>
2705            <xsl:text>.xref.</xsl:text>
2706            <xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/>
2707          </xsl:when>
2708          <xsl:when test="self::iref">
2709            <xsl:text>#</xsl:text>
2710            <xsl:call-template name="compute-iref-anchor"/>
2711          </xsl:when>
2712          <xsl:otherwise>
2713            <xsl:message>Unsupported element type for insertSingleIref</xsl:message>
2714          </xsl:otherwise>
2715        </xsl:choose>
2716      </xsl:variable>
2717      <a xmlns="http://www.w3.org/1999/xhtml" class="iref" href="{$backlink}">
2718        <xsl:call-template name="insertInsDelClass"/>
2719        <xsl:choose>
2720          <xsl:when test="@primary='true'"><b><xsl:value-of select="$n"/></b></xsl:when>
2721          <xsl:otherwise><xsl:value-of select="$n"/></xsl:otherwise>
2722        </xsl:choose>
2723      </a>
2724      <xsl:if test="position()!=last()">, </xsl:if>
2725    </xsl:otherwise>
2726  </xsl:choose>
2727</xsl:template>
2728
2729<xsl:template name="insertSingleXref">
2730  <xsl:variable name="_n">
2731    <xsl:call-template name="get-section-number"/>
2732  </xsl:variable>
2733  <xsl:variable name="n">
2734    <xsl:choose>
2735      <xsl:when test="$_n!=''">
2736        <xsl:value-of select="$_n"/>
2737      </xsl:when>
2738      <xsl:otherwise>§</xsl:otherwise>
2739    </xsl:choose>
2740  </xsl:variable>
2741  <xsl:choose>
2742    <xsl:when test="self::reference">
2743      <a xmlns="http://www.w3.org/1999/xhtml" class="iref" href="#{@anchor}">
2744        <xsl:call-template name="insertInsDelClass"/>
2745        <b><xsl:value-of select="$n"/></b>
2746      </a>
2747    </xsl:when>
2748    <xsl:otherwise>
2749      <xsl:variable name="target" select="@target"/>
2750      <xsl:variable name="backlink">#<xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="$target"/>.<xsl:number level="any" count="xref[@target=$target]"/></xsl:variable>
2751      <a xmlns="http://www.w3.org/1999/xhtml" class="iref" href="{$backlink}">
2752        <xsl:call-template name="insertInsDelClass"/>
2753        <xsl:value-of select="$n"/>
2754      </a>
2755    </xsl:otherwise>
2756  </xsl:choose>
2757  <xsl:if test="position()!=last()">, </xsl:if>
2758</xsl:template>
2759
2760<xsl:template name="insertIndex">
2761
2762  <xsl:call-template name="insert-conditional-hrule"/>
2763
2764  <h1 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.index">
2765    <xsl:call-template name="insert-conditional-pagebreak"/>
2766    <a href="#{$anchor-prefix}.index">Index</a>
2767  </h1>
2768 
2769  <!-- generate navigation links to index subsections -->
2770  <p xmlns="http://www.w3.org/1999/xhtml" class="noprint">
2771    <xsl:variable name="irefs" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
2772    <xsl:variable name="xrefs" select="//reference[not(starts-with(@anchor,'deleted-'))][generate-id(.) = generate-id(key('index-first-letter',translate(substring(@anchor,1,1),$lcase,$ucase)))]"/>
2773 
2774    <xsl:for-each select="$irefs | $xrefs">
2775   
2776      <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)"/>
2777         
2778      <xsl:variable name="letter" select="translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase)"/>
2779
2780      <!-- character? -->
2781      <xsl:if test="translate($letter,concat($lcase,$ucase,'0123456789'),'')=''">
2782     
2783        <xsl:variable name="showit">
2784          <xsl:choose>
2785            <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
2786              <xsl:if test="$irefs[starts-with(translate(@item,$lcase,$ucase),$letter)]">
2787                <xsl:text>yes</xsl:text>
2788              </xsl:if>
2789            </xsl:when>
2790            <xsl:otherwise>
2791              <xsl:text>yes</xsl:text>
2792            </xsl:otherwise>
2793          </xsl:choose>
2794        </xsl:variable>
2795       
2796        <xsl:if test="$showit='yes'">
2797          <a href="#{$anchor-prefix}.index.{$letter}">
2798            <xsl:value-of select="$letter"/>
2799          </a>
2800          <xsl:text> </xsl:text>
2801        </xsl:if>
2802     
2803      </xsl:if>
2804
2805    </xsl:for-each>
2806  </p>
2807
2808  <!-- for each index subsection -->
2809  <div xmlns="http://www.w3.org/1999/xhtml" class="print2col">
2810  <ul class="ind">
2811    <xsl:variable name="irefs2" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
2812    <xsl:variable name="xrefs2" select="//reference[not(starts-with(@anchor,'deleted-'))][generate-id(.) = generate-id(key('index-first-letter',translate(substring(@anchor,1,1),$lcase,$ucase)))]"/>
2813 
2814    <xsl:for-each select="$irefs2 | $xrefs2">
2815      <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)"/>
2816      <xsl:variable name="letter" select="translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase)"/>
2817           
2818      <xsl:variable name="showit">
2819        <xsl:choose>
2820          <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
2821            <xsl:if test="$irefs2[starts-with(translate(@item,$lcase,$ucase),$letter)]">
2822              <xsl:text>yes</xsl:text>
2823            </xsl:if>
2824          </xsl:when>
2825          <xsl:otherwise>
2826            <xsl:text>yes</xsl:text>
2827          </xsl:otherwise>
2828        </xsl:choose>
2829      </xsl:variable>
2830
2831      <xsl:if test="$showit='yes'">
2832        <li class="indline0">
2833         
2834          <!-- make letters and digits stand out -->
2835          <xsl:choose>
2836            <xsl:when test="translate($letter,concat($lcase,$ucase,'0123456789'),'')=''">
2837              <a id="{$anchor-prefix}.index.{$letter}" href="#{$anchor-prefix}.index.{$letter}">
2838                <b><xsl:value-of select="$letter"/></b>
2839              </a>
2840            </xsl:when>
2841            <xsl:otherwise>
2842              <b><xsl:value-of select="$letter"/></b>
2843            </xsl:otherwise>
2844          </xsl:choose>
2845       
2846          <ul class="ind"> 
2847            <xsl:for-each select="key('index-first-letter',translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase))">
2848       
2849              <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)"/>
2850             
2851                <xsl:choose>
2852                  <xsl:when test="self::reference">
2853                    <xsl:if test="$xml2rfc-ext-include-references-in-index='yes' and not(starts-with(@anchor,'deleted-'))">
2854                      <li class="indline1">
2855                        <em>
2856                          <xsl:value-of select="@anchor"/>
2857                        </em>
2858                        <xsl:text>  </xsl:text>
2859                       
2860                        <xsl:variable name="rs" select="//xref[@target=current()/@anchor] | . | //reference[@anchor=concat('deleted-',current()/@anchor)]"/>
2861                        <xsl:for-each select="$rs">
2862                          <xsl:call-template name="insertSingleXref"/>
2863                        </xsl:for-each>
2864
2865                        <xsl:variable name="rs2" select="$rs[@x:sec]"/>
2866
2867                        <xsl:if test="$rs2">
2868                          <ul class="ind"> 
2869                            <xsl:for-each select="$rs2">
2870                              <xsl:sort select="substring-before(concat(@x:sec,'.'),'.')" data-type="number"/>
2871                              <xsl:sort select="substring(@x:sec,1+string-length(substring-before(@x:sec,'.')))" data-type="number"/>
2872                              <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-sec',concat(@target,'..',@x:sec)))">
2873                                <li class="indline1">
2874                                  <em>
2875                                    <xsl:text>Section </xsl:text>
2876                                    <xsl:value-of select="@x:sec"/>
2877                                  </em>
2878                                  <xsl:text>  </xsl:text>
2879                                  <xsl:for-each select="key('index-xref-by-sec',concat(@target,'..',@x:sec))">
2880                                    <xsl:call-template name="insertSingleXref"/>
2881                                  </xsl:for-each>
2882                                </li>
2883                              </xsl:if>
2884                            </xsl:for-each>
2885                          </ul>
2886                        </xsl:if>
2887
2888                        <xsl:if test="current()/x:source/@href">
2889                          <xsl:variable name="rs3" select="$rs[not(@x:sec) and @x:rel]"/>
2890                          <xsl:variable name="doc" select="document(current()/x:source/@href)"/>
2891                          <xsl:if test="$rs3">
2892                            <ul class="ind"> 
2893                              <xsl:for-each select="$rs3">
2894                                <xsl:sort select="count($doc//*[@anchor and following::*/@anchor=substring-after(current()/@x:rel,'#')])" order="ascending" data-type="number"/>
2895                                <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-anchor',concat(@target,'..',@x:rel)))">
2896                                  <li class="indline1">
2897                                    <em>
2898                                      <xsl:text>Section </xsl:text>
2899                                      <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
2900                                        <xsl:call-template name="get-section-number"/>
2901                                      </xsl:for-each>
2902                                    </em>
2903                                    <xsl:text>  </xsl:text>
2904                                    <xsl:for-each select="key('index-xref-by-anchor',concat(@target,'..',@x:rel))">
2905                                      <xsl:call-template name="insertSingleXref"/>
2906                                    </xsl:for-each>
2907                                  </li>
2908                                </xsl:if>
2909                              </xsl:for-each>
2910                            </ul>
2911                          </xsl:if>
2912                        </xsl:if>
2913                      </li>
2914                    </xsl:if>
2915                  </xsl:when>
2916                  <xsl:otherwise>
2917                    <!-- regular iref -->
2918                    <xsl:if test="generate-id(.) = generate-id(key('index-item',concat(@item,@anchor)))">
2919                      <xsl:variable name="item" select="@item"/>
2920                      <xsl:variable name="in-artwork" select="count(//iref[@item=$item and @primary='true' and ancestor::artwork])!=0"/>
2921                         
2922                      <li class="indline1">
2923                        <xsl:choose>
2924                          <xsl:when test="$in-artwork">
2925                            <tt><xsl:value-of select="@item"/></tt>
2926                          </xsl:when>
2927                          <xsl:otherwise>
2928                            <xsl:value-of select="@item"/>
2929                          </xsl:otherwise>
2930                        </xsl:choose>
2931                        <xsl:text>  </xsl:text>
2932                       
2933                        <xsl:variable name="irefs3" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
2934                        <xsl:variable name="xrefs3" select="//xref[@target=$irefs3[@x:for-anchor='']/../@anchor or @target=$irefs3/@x:for-anchor]"/>
2935
2936                        <xsl:for-each select="$irefs3|$xrefs3">
2937                          <!-- <xsl:sort select="translate(@item,$lcase,$ucase)" />  -->
2938                          <xsl:call-template name="insertSingleIref"/>
2939                        </xsl:for-each>
2940         
2941                        <xsl:variable name="s2" select="key('index-item',@item)[@subitem and @subitem!='']"/>
2942                        <xsl:if test="$s2">
2943                          <ul class="ind"> 
2944                            <xsl:for-each select="$s2">
2945                              <xsl:sort select="translate(@subitem,$lcase,$ucase)"/>
2946                             
2947                              <xsl:if test="generate-id(.) = generate-id(key('index-item-subitem',concat(@item,'..',@subitem)))">
2948                 
2949                                <xsl:variable name="itemsubitem" select="concat(@item,'..',@subitem)"/>
2950                                <xsl:variable name="in-artwork2" select="count(//iref[concat(@item,'..',@subitem)=$itemsubitem and @primary='true' and ancestor::artwork])!=0"/>
2951                 
2952                                <li class="indline1">
2953             
2954                                  <xsl:choose>
2955                                    <xsl:when test="$in-artwork2">
2956                                      <tt><xsl:value-of select="@subitem"/></tt>
2957                                    </xsl:when>
2958                                    <xsl:otherwise>
2959                                      <xsl:value-of select="@subitem"/>
2960                                    </xsl:otherwise>
2961                                  </xsl:choose>
2962                                  <xsl:text>  </xsl:text>
2963                                   
2964                                  <xsl:variable name="irefs4" select="key('index-item-subitem',concat(@item,'..',@subitem))"/>
2965                                  <xsl:variable name="xrefs4" select="//xref[@target=$irefs4[@x:for-anchor='']/../@anchor or @target=$irefs4/@x:for-anchor]"/>
2966
2967                                  <xsl:for-each select="$irefs4|$xrefs4">
2968                                    <!--<xsl:sort select="translate(@item,$lcase,$ucase)" />-->                   
2969                                    <xsl:call-template name="insertSingleIref"/>
2970                                  </xsl:for-each>
2971               
2972                                </li>
2973                              </xsl:if>
2974                            </xsl:for-each>
2975                          </ul>
2976                        </xsl:if>
2977                      </li>
2978                    </xsl:if>
2979                  </xsl:otherwise>
2980                </xsl:choose>
2981             
2982                     
2983            </xsl:for-each>           
2984          </ul>
2985        </li>
2986      </xsl:if>
2987     
2988    </xsl:for-each>
2989  </ul>
2990  </div>
2991 
2992</xsl:template>
2993
2994
2995
2996
2997<xsl:template name="insertPreamble" myns:namespaceless-elements="xml2rfc">
2998
2999  <section title="Status of this Memo" myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.status">
3000
3001  <xsl:choose>
3002    <xsl:when test="/rfc/@ipr and not(/rfc/@number)">
3003      <t>
3004        <xsl:choose>
3005         
3006          <!-- RFC2026 -->
3007          <xsl:when test="/rfc/@ipr = 'full2026'">
3008            This document is an Internet-Draft and is
3009            in full conformance with all provisions of Section 10 of RFC2026.   
3010          </xsl:when>
3011          <xsl:when test="/rfc/@ipr = 'noDerivativeWorks2026'">
3012            This document is an Internet-Draft and is
3013            in full conformance with all provisions of Section 10 of RFC2026
3014            except that the right to produce derivative works is not granted.   
3015          </xsl:when>
3016          <xsl:when test="/rfc/@ipr = 'noDerivativeWorksNow'">
3017            This document is an Internet-Draft and is
3018            in full conformance with all provisions of Section 10 of RFC2026
3019            except that the right to produce derivative works is not granted.
3020            (If this document becomes part of an IETF working group activity,
3021            then it will be brought into full compliance with Section 10 of RFC2026.) 
3022          </xsl:when>
3023          <xsl:when test="/rfc/@ipr = 'none'">
3024            This document is an Internet-Draft and is
3025            NOT offered in accordance with Section 10 of RFC2026,
3026            and the author does not provide the IETF with any rights other
3027            than to publish as an Internet-Draft.
3028          </xsl:when>
3029         
3030          <!-- RFC3667 -->
3031          <xsl:when test="/rfc/@ipr = 'full3667'">
3032            This document is an Internet-Draft and is subject to all provisions
3033            of section 3 of RFC 3667.  By submitting this Internet-Draft, each
3034            author represents that any applicable patent or other IPR claims of
3035            which he or she is aware have been or will be disclosed, and any of
3036            which he or she become aware will be disclosed, in accordance with
3037            RFC 3668.
3038          </xsl:when>
3039          <xsl:when test="/rfc/@ipr = 'noModification3667'">
3040            This document is an Internet-Draft and is subject to all provisions
3041            of section 3 of RFC 3667.  By submitting this Internet-Draft, each
3042            author represents that any applicable patent or other IPR claims of
3043            which he or she is aware have been or will be disclosed, and any of
3044            which he or she become aware will be disclosed, in accordance with
3045            RFC 3668.  This document may not be modified, and derivative works of
3046            it may not be created, except to publish it as an RFC and to
3047            translate it into languages other than English<xsl:if test="/rfc/@iprExtract">,
3048            other than to extract <xref target="{/rfc/@iprExtract}"/> as-is
3049            for separate use.</xsl:if>.
3050          </xsl:when>
3051          <xsl:when test="/rfc/@ipr = 'noDerivatives3667'">
3052            This document is an Internet-Draft and is subject to all provisions
3053            of section 3 of RFC 3667 except for the right to produce derivative
3054            works.  By submitting this Internet-Draft, each author represents
3055            that any applicable patent or other IPR claims of which he or she
3056            is aware have been or will be disclosed, and any of which he or she
3057            become aware will be disclosed, in accordance with RFC 3668.  This
3058            document may not be modified, and derivative works of it may
3059            not be created<xsl:if test="/rfc/@iprExtract">, other than to extract
3060            <xref target="{/rfc/@iprExtract}"/> as-is for separate use.</xsl:if>.
3061          </xsl:when>
3062         
3063          <!-- RFC3978 -->
3064          <xsl:when test="/rfc/@ipr = 'full3978'">
3065            By submitting this Internet-Draft, each
3066            author represents that any applicable patent or other IPR claims of
3067            which he or she is aware have been or will be disclosed, and any of
3068            which he or she becomes aware will be disclosed, in accordance with
3069            Section 6 of BCP 79.
3070          </xsl:when>
3071          <xsl:when test="/rfc/@ipr = 'noModification3978'">
3072            By submitting this Internet-Draft, each
3073            author represents that any applicable patent or other IPR claims of
3074            which he or she is aware have been or will be disclosed, and any of
3075            which he or she becomes aware will be disclosed, in accordance with
3076            Section 6 of BCP 79.  This document may not be modified, and derivative works of
3077            it may not be created, except to publish it as an RFC and to
3078            translate it into languages other than English<xsl:if test="/rfc/@iprExtract">,
3079            other than to extract <xref target="{/rfc/@iprExtract}"/> as-is
3080            for separate use.</xsl:if>.
3081          </xsl:when>
3082          <xsl:when test="/rfc/@ipr = 'noDerivatives3978'">
3083            By submitting this Internet-Draft, each author represents
3084            that any applicable patent or other IPR claims of which he or she
3085            is aware have been or will be disclosed, and any of which he or she
3086            becomes aware will be disclosed, in accordance with Section 6 of BCP 79.  This
3087            document may not be modified, and derivative works of it may
3088            not be created<xsl:if test="/rfc/@iprExtract">, other than to extract
3089            <xref target="{/rfc/@iprExtract}"/> as-is for separate use.</xsl:if>.
3090          </xsl:when>
3091
3092          <xsl:otherwise>CONFORMANCE UNDEFINED.</xsl:otherwise>
3093        </xsl:choose>
3094      </t>
3095      <t>
3096        Internet-Drafts are working documents of the Internet Engineering
3097        Task Force (IETF), its areas, and its working groups.
3098        Note that other groups may also distribute working documents as
3099        Internet-Drafts.
3100      </t>
3101      <t>
3102        Internet-Drafts are draft documents valid for a maximum of six months
3103        and may be updated, replaced, or obsoleted by other documents at any time.
3104        It is inappropriate to use Internet-Drafts as reference material or to cite
3105        them other than as &#8220;work in progress&#8221;.
3106      </t>
3107      <t>
3108        The list of current Internet-Drafts can be accessed at
3109        <eref target="http://www.ietf.org/ietf/1id-abstracts.txt"/>.
3110      </t>
3111      <t>
3112        The list of Internet-Draft Shadow Directories can be accessed at
3113        <eref target="http://www.ietf.org/shadow.html"/>.
3114      </t>
3115      <t>
3116        This Internet-Draft will expire in <xsl:call-template name="expirydate"/>.
3117      </t>
3118    </xsl:when>
3119
3120    <xsl:when test="/rfc/@category='bcp'">
3121      <t>
3122        This document specifies an Internet Best Current Practices for the Internet
3123        Community, and requests discussion and suggestions for improvements.
3124        Distribution of this memo is unlimited.
3125      </t>
3126    </xsl:when>
3127    <xsl:when test="/rfc/@category='exp'">
3128      <t>
3129        This memo defines an Experimental Protocol for the Internet community.
3130        It does not specify an Internet standard of any kind.
3131        Discussion and suggestions for improvement are requested.
3132        Distribution of this memo is unlimited.
3133      </t>
3134    </xsl:when>
3135    <xsl:when test="/rfc/@category='historic'">
3136      <t>
3137        This memo describes a historic protocol for the Internet community.
3138        It does not specify an Internet standard of any kind.
3139        Distribution of this memo is unlimited.
3140      </t>
3141    </xsl:when>
3142    <xsl:when test="/rfc/@category='info' or not(/rfc/@category)">
3143      <t>
3144        This memo provides information for the Internet community.
3145        It does not specify an Internet standard of any kind.
3146        Distribution of this memo is unlimited.
3147      </t>
3148    </xsl:when>
3149    <xsl:when test="/rfc/@category='std'">
3150      <t>
3151        This document specifies an Internet standards track protocol for the Internet
3152        community, and requests discussion and suggestions for improvements.
3153        Please refer to the current edition of the &#8220;Internet Official Protocol
3154        Standards&#8221; (STD 1) for the standardization state and status of this
3155        protocol. Distribution of this memo is unlimited.
3156      </t>
3157    </xsl:when>
3158    <xsl:otherwise>
3159      <t>UNSUPPORTED CATEGORY.</t>
3160    </xsl:otherwise>
3161  </xsl:choose>
3162 
3163  </section>
3164
3165  <section title="Copyright Notice" myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.copyrightnotice">
3166  <t>
3167    <xsl:choose>
3168      <xsl:when test="$ipr-rfc4748">
3169        Copyright © The IETF Trust (<xsl:value-of select="/rfc/front/date/@year"/>).  All Rights Reserved.
3170      </xsl:when>
3171      <xsl:otherwise>
3172        Copyright © The Internet Society (<xsl:value-of select="/rfc/front/date/@year"/>).  All Rights Reserved.
3173      </xsl:otherwise>
3174    </xsl:choose>
3175  </t>
3176  </section>
3177 
3178</xsl:template>
3179
3180<!-- TOC generation -->
3181
3182<xsl:template match="/" mode="toc">
3183  <hr xmlns="http://www.w3.org/1999/xhtml" class="noprint"/>
3184
3185  <h1 xmlns="http://www.w3.org/1999/xhtml" class="np" id="{$anchor-prefix}.toc"> <!-- this pagebreak occurs always -->
3186    <a href="#{$anchor-prefix}.toc">Table of Contents</a>
3187  </h1>
3188
3189  <ul xmlns="http://www.w3.org/1999/xhtml" class="toc">
3190    <xsl:apply-templates mode="toc"/>
3191  </ul>
3192</xsl:template>
3193
3194<xsl:template name="insert-toc-line">
3195  <xsl:param name="number"/>
3196  <xsl:param name="target"/>
3197  <xsl:param name="title"/>
3198  <xsl:param name="tocparam"/>
3199  <xsl:param name="oldtitle"/>
3200  <xsl:param name="waschanged"/>
3201
3202  <!-- handle tocdepth parameter -->
3203  <xsl:choose>
3204    <xsl:when test="($tocparam='' or $tocparam='default') and string-length(translate($number,'.ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890§','.')) &gt;= $parsedTocDepth">
3205      <!-- dropped entry because excluded -->
3206      <xsl:attribute name="class">tocline2</xsl:attribute>
3207    </xsl:when>
3208    <xsl:when test="$tocparam='exclude'">
3209      <!-- dropped entry because excluded -->
3210      <xsl:attribute name="class">tocline2</xsl:attribute>
3211    </xsl:when>
3212    <xsl:otherwise>
3213      <xsl:choose>
3214        <xsl:when test="starts-with($number,'del-')">
3215          <del xmlns="http://www.w3.org/1999/xhtml">
3216            <xsl:value-of select="$number"/>
3217            <a href="#{$target}"><xsl:value-of select="$title"/></a>
3218          </del>
3219        </xsl:when>
3220        <xsl:otherwise>
3221          <xsl:choose>
3222            <xsl:when test="not(contains($number,'.'))">
3223              <xsl:attribute name="class">tocline0</xsl:attribute>
3224            </xsl:when>
3225            <xsl:otherwise>
3226              <xsl:attribute name="class">tocline1</xsl:attribute>
3227            </xsl:otherwise>
3228          </xsl:choose>
3229          <xsl:if test="$number != ''">
3230            <xsl:call-template name="emit-section-number">
3231              <xsl:with-param name="no" select="$number"/>
3232            </xsl:call-template>
3233            <xsl:text>   </xsl:text>
3234          </xsl:if>
3235          <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target}">
3236            <xsl:choose>
3237              <xsl:when test="$waschanged!=''">
3238                <ins><xsl:value-of select="$title"/></ins>
3239                <del><xsl:value-of select="$oldtitle"/></del>
3240              </xsl:when>
3241              <xsl:otherwise>
3242                <xsl:value-of select="$title"/>
3243              </xsl:otherwise>
3244            </xsl:choose>
3245          </a>
3246        </xsl:otherwise>
3247      </xsl:choose>
3248    </xsl:otherwise>
3249  </xsl:choose>
3250</xsl:template>
3251
3252<xsl:template match="back" mode="toc">
3253
3254  <!-- <xsl:apply-templates select="references" mode="toc" /> -->
3255
3256  <xsl:if test="//cref and $xml2rfc-comments='yes' and $xml2rfc-inline!='yes'">
3257    <li xmlns="http://www.w3.org/1999/xhtml">
3258      <xsl:call-template name="insert-toc-line">
3259        <xsl:with-param name="target" select="concat($anchor-prefix,'.comments')"/>
3260        <xsl:with-param name="title" select="'Editorial Comments'"/>
3261      </xsl:call-template>
3262    </li>
3263  </xsl:if>
3264
3265  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
3266    <xsl:apply-templates select="/rfc/front" mode="toc"/>
3267  </xsl:if>
3268  <xsl:apply-templates select="*[not(self::references)]" mode="toc"/>
3269
3270  <xsl:if test="$xml2rfc-ext-authors-section='end'">
3271    <xsl:apply-templates select="/rfc/front" mode="toc"/>
3272  </xsl:if>
3273
3274  <!-- copyright statements -->
3275  <xsl:if test="not($xml2rfc-private)">
3276    <li xmlns="http://www.w3.org/1999/xhtml">
3277      <xsl:call-template name="insert-toc-line">
3278        <xsl:with-param name="target" select="concat($anchor-prefix,'.ipr')"/>
3279        <xsl:with-param name="title" select="'Intellectual Property and Copyright Statements'"/>
3280      </xsl:call-template>
3281    </li>
3282  </xsl:if>
3283 
3284  <!-- insert the index if index entries exist -->
3285  <xsl:if test="//iref">
3286    <li xmlns="http://www.w3.org/1999/xhtml">
3287      <xsl:call-template name="insert-toc-line">
3288        <xsl:with-param name="target" select="concat($anchor-prefix,'.index')"/>
3289        <xsl:with-param name="title" select="'Index'"/>
3290      </xsl:call-template>
3291    </li>
3292  </xsl:if>
3293
3294</xsl:template>
3295
3296<xsl:template match="front" mode="toc">
3297 
3298  <li xmlns="http://www.w3.org/1999/xhtml">
3299    <xsl:variable name="authors-title">
3300      <xsl:call-template name="get-authors-section-title"/>
3301    </xsl:variable>
3302    <xsl:variable name="authors-number">
3303      <xsl:call-template name="get-authors-section-number"/>
3304    </xsl:variable>
3305    <xsl:call-template name="insert-toc-line">
3306      <xsl:with-param name="target" select="concat($anchor-prefix,'.authors')"/>
3307      <xsl:with-param name="title" select="$authors-title"/>
3308      <xsl:with-param name="number" select="$authors-number"/>
3309    </xsl:call-template>
3310  </li>
3311
3312</xsl:template>
3313
3314<xsl:template name="references-toc">
3315
3316  <!-- distinguish two cases: (a) single references element (process
3317  as toplevel section; (b) multiple references sections (add one toplevel
3318  container with subsection) -->
3319
3320  <xsl:variable name="refsecs" select="/rfc/back/references|/rfc/back/ed:replace/ed:ins/references"/>
3321   
3322  <xsl:choose>
3323    <xsl:when test="count($refsecs) = 0">
3324      <!-- nop -->
3325    </xsl:when>
3326    <xsl:when test="count($refsecs) = 1">
3327      <xsl:for-each select="$refsecs">
3328        <xsl:variable name="title">
3329          <xsl:choose>
3330            <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
3331            <xsl:otherwise>References</xsl:otherwise>
3332          </xsl:choose>
3333        </xsl:variable>
3334     
3335        <li xmlns="http://www.w3.org/1999/xhtml">
3336          <xsl:call-template name="insert-toc-line">
3337            <xsl:with-param name="number">
3338              <xsl:call-template name="get-references-section-number"/>
3339            </xsl:with-param>
3340            <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
3341            <xsl:with-param name="title" select="$title"/>
3342          </xsl:call-template>
3343        </li>
3344      </xsl:for-each>
3345    </xsl:when>
3346    <xsl:otherwise>
3347      <li xmlns="http://www.w3.org/1999/xhtml">
3348        <!-- insert pseudo container -->   
3349        <xsl:call-template name="insert-toc-line">
3350          <xsl:with-param name="number">
3351            <xsl:call-template name="get-references-section-number"/>
3352          </xsl:with-param>
3353          <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
3354          <xsl:with-param name="title" select="'References'"/>
3355        </xsl:call-template>
3356 
3357        <ul class="toc">
3358          <!-- ...with subsections... -->   
3359          <xsl:for-each select="$refsecs">
3360            <xsl:variable name="title">
3361              <xsl:choose>
3362                <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
3363                <xsl:otherwise>References</xsl:otherwise>
3364              </xsl:choose>
3365            </xsl:variable>
3366         
3367            <xsl:variable name="sectionNumber">
3368              <xsl:call-template name="get-section-number"/>
3369            </xsl:variable>
3370   
3371            <xsl:variable name="num">
3372              <xsl:number level="any"/>
3373            </xsl:variable>
3374   
3375            <li>
3376              <xsl:call-template name="insert-toc-line">
3377                <xsl:with-param name="number" select="$sectionNumber"/>
3378                <xsl:with-param name="target" select="concat($anchor-prefix,'.references','.',$num)"/>
3379                <xsl:with-param name="title" select="$title"/>
3380              </xsl:call-template>
3381            </li>
3382          </xsl:for-each>
3383        </ul>
3384      </li>
3385    </xsl:otherwise>
3386  </xsl:choose>
3387</xsl:template>
3388
3389<xsl:template match="section|appendix" mode="toc">
3390  <xsl:variable name="sectionNumber">
3391    <xsl:call-template name="get-section-number"/>
3392  </xsl:variable>
3393
3394  <xsl:variable name="target">
3395    <xsl:choose>
3396      <xsl:when test="@anchor"><xsl:value-of select="@anchor"/></xsl:when>
3397       <xsl:otherwise><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber"/></xsl:otherwise>
3398    </xsl:choose>
3399  </xsl:variable>
3400
3401  <!-- obtain content, just to check whether we need to recurse at all -->
3402  <xsl:variable name="content">
3403    <li xmlns="http://www.w3.org/1999/xhtml">
3404      <xsl:call-template name="insert-toc-line">
3405        <xsl:with-param name="number" select="$sectionNumber"/>
3406        <xsl:with-param name="target" select="$target"/>
3407        <xsl:with-param name="title" select="@title"/>
3408        <xsl:with-param name="tocparam" select="@toc"/>
3409        <xsl:with-param name="oldtitle" select="@ed:old-title"/>
3410        <xsl:with-param name="waschanged" select="@ed:resolves"/>
3411      </xsl:call-template>
3412   
3413      <ul class="toc">
3414        <xsl:apply-templates mode="toc"/>
3415      </ul>
3416    </li>
3417  </xsl:variable>
3418 
3419  <xsl:if test="$content!=''">
3420    <li xmlns="http://www.w3.org/1999/xhtml">
3421      <xsl:call-template name="insert-toc-line">
3422        <xsl:with-param name="number" select="$sectionNumber"/>
3423        <xsl:with-param name="target" select="$target"/>
3424        <xsl:with-param name="title" select="@title"/>
3425        <xsl:with-param name="tocparam" select="@toc"/>
3426        <xsl:with-param name="oldtitle" select="@ed:old-title"/>
3427        <xsl:with-param name="waschanged" select="@ed:resolves"/>
3428      </xsl:call-template>
3429   
3430      <!-- obtain nested content, just to check whether we need to recurse at all -->
3431      <xsl:variable name="nested-content">
3432        <ul class="toc">
3433          <xsl:apply-templates mode="toc"/>
3434        </ul>
3435      </xsl:variable>
3436     
3437      <!-- only recurse if we need to (do not produce useless list container) -->     
3438      <xsl:if test="$nested-content!=''">
3439        <ul class="toc">
3440          <xsl:apply-templates mode="toc"/>
3441        </ul>
3442      </xsl:if>
3443    </li>
3444  </xsl:if>
3445</xsl:template>
3446
3447<xsl:template match="middle" mode="toc">
3448  <xsl:apply-templates mode="toc"/>
3449  <xsl:call-template name="references-toc"/>
3450</xsl:template>
3451
3452<xsl:template match="rfc" mode="toc">
3453  <xsl:apply-templates select="middle|back" mode="toc"/>
3454</xsl:template>
3455
3456<xsl:template match="ed:del|ed:ins|ed:replace" mode="toc">
3457  <xsl:apply-templates mode="toc"/>
3458</xsl:template>
3459
3460<xsl:template match="*|text()" mode="toc"/>
3461
3462
3463<xsl:template name="insertTocAppendix">
3464 
3465  <xsl:if test="//figure[@title!='' or @anchor!='']">
3466    <ul xmlns="http://www.w3.org/1999/xhtml" class="toc">
3467      <xsl:for-each select="//figure[@title!='' or @anchor!='']">
3468        <xsl:variable name="title">Figure <xsl:value-of select="position()"/><xsl:if test="@title">: <xsl:value-of select="@title"/></xsl:if>
3469        </xsl:variable>
3470        <li>
3471          <xsl:call-template name="insert-toc-line">
3472            <xsl:with-param name="target" select="concat($anchor-prefix,'.figure.',position())"/>
3473            <xsl:with-param name="title" select="$title"/>
3474          </xsl:call-template>
3475        </li>
3476      </xsl:for-each>
3477    </ul>
3478  </xsl:if>
3479 
3480  <!-- experimental -->
3481  <xsl:if test="//ed:issue">
3482    <xsl:call-template name="insertIssuesList"/>
3483  </xsl:if>
3484
3485</xsl:template>
3486
3487<xsl:template name="referencename">
3488  <xsl:param name="node"/>
3489 
3490  <xsl:for-each select="$node">
3491    <xsl:choose>
3492      <xsl:when test="$xml2rfc-symrefs!='no' and ancestor::ed:del">
3493        <xsl:variable name="unprefixed" select="substring-after(@anchor,'deleted-')"/>
3494        <xsl:choose>
3495          <xsl:when test="$unprefixed!=''">
3496            <xsl:value-of select="concat('[',$unprefixed,']')"/>
3497          </xsl:when>
3498          <xsl:otherwise>
3499            <xsl:if test="count(//reference[@anchor=current()/@anchor])!=1">
3500              <xsl:message>Deleted duplicate anchors should have the prefix "deleted-": <xsl:value-of select="@anchor"/></xsl:message>
3501            </xsl:if>
3502            <xsl:value-of select="concat('[',@anchor,']')"/>
3503          </xsl:otherwise>
3504        </xsl:choose>
3505      </xsl:when>
3506      <xsl:when test="$xml2rfc-symrefs!='no'">[<xsl:value-of select="@anchor"/>]</xsl:when>
3507      <xsl:when test="ancestor::ed:del">
3508        <xsl:text>[del]</xsl:text>
3509      </xsl:when>
3510      <xsl:otherwise>[<xsl:number level="any" count="reference[not(ancestor::ed:del)]"/>]</xsl:otherwise>
3511    </xsl:choose>
3512  </xsl:for-each> 
3513</xsl:template>
3514
3515
3516
3517<xsl:template name="replace-substring">
3518
3519  <xsl:param name="string"/>
3520  <xsl:param name="replace"/>
3521  <xsl:param name="by"/>
3522
3523  <xsl:choose>
3524    <xsl:when test="contains($string,$replace)">
3525      <xsl:value-of select="concat(substring-before($string, $replace),$by)"/>
3526      <xsl:call-template name="replace-substring">
3527        <xsl:with-param name="string" select="substring-after($string,$replace)"/>
3528        <xsl:with-param name="replace" select="$replace"/>
3529        <xsl:with-param name="by" select="$by"/>
3530      </xsl:call-template>
3531    </xsl:when>
3532    <xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise>
3533  </xsl:choose>
3534
3535</xsl:template>
3536
3537
3538<xsl:template name="rfclist">
3539  <xsl:param name="list"/>
3540  <xsl:choose>
3541    <xsl:when test="contains($list,',')">
3542      <xsl:variable name="rfcNo" select="substring-before($list,',')"/>
3543      <a xmlns="http://www.w3.org/1999/xhtml" href="{concat($rfcUrlPrefix,$rfcNo,$rfcUrlPostfix)}"><xsl:value-of select="$rfcNo"/></a>,
3544      <xsl:call-template name="rfclist">
3545        <xsl:with-param name="list" select="normalize-space(substring-after($list,','))"/>
3546      </xsl:call-template>
3547    </xsl:when>
3548    <xsl:otherwise>
3549      <xsl:variable name="rfcNo" select="$list"/>
3550      <a xmlns="http://www.w3.org/1999/xhtml" href="{concat($rfcUrlPrefix,$rfcNo,$rfcUrlPostfix)}"><xsl:value-of select="$rfcNo"/></a>
3551    </xsl:otherwise>
3552  </xsl:choose>
3553</xsl:template>
3554
3555<xsl:template name="rfclist-for-dcmeta">
3556  <xsl:param name="list"/>
3557  <xsl:choose>
3558    <xsl:when test="contains($list,',')">
3559      <xsl:variable name="rfcNo" select="substring-before($list,',')"/>
3560      <meta xmlns="http://www.w3.org/1999/xhtml" name="DC.Relation.Replaces" content="urn:ietf:rfc:{$rfcNo}"/>
3561      <xsl:call-template name="rfclist-for-dcmeta">
3562        <xsl:with-param name="list" select="normalize-space(substring-after($list,','))"/>
3563      </xsl:call-template>
3564    </xsl:when>
3565    <xsl:otherwise>
3566      <xsl:variable name="rfcNo" select="$list"/>
3567      <meta xmlns="http://www.w3.org/1999/xhtml" name="DC.Relation.Replaces" content="urn:ietf:rfc:{$rfcNo}"/>
3568    </xsl:otherwise>
3569  </xsl:choose>
3570</xsl:template>
3571
3572<xsl:template name="get-paragraph-number">
3573  <!-- get section number of ancestor section element, then add t or figure number -->
3574  <xsl:if test="ancestor::section and not(ancestor::section[@myns:unnumbered='unnumbered']) and not(ancestor::x:blockquote)">
3575    <xsl:for-each select="ancestor::section[1]"><xsl:call-template name="get-section-number"/>.p.</xsl:for-each><xsl:number count="t|figure|x:blockquote"/>
3576  </xsl:if>
3577</xsl:template>
3578
3579<xsl:template name="editingMark">
3580  <xsl:if test="$xml2rfc-editing='yes' and ancestor::rfc">
3581    <sup xmlns="http://www.w3.org/1999/xhtml" class="editingmark"><span><xsl:number level="any" count="postamble|preamble|t"/></span> </sup>
3582  </xsl:if>
3583</xsl:template>
3584
3585<!-- internal ref support -->
3586<xsl:template match="x:ref">
3587  <xsl:variable name="val" select="."/>
3588  <xsl:variable name="target" select="//*[(@anchor and x:anchor-alias/@value=$val) or (@anchor and ed:replace/ed:ins/x:anchor-alias/@value=$val) or (@anchor=$val)]"/>
3589  <xsl:choose>
3590    <xsl:when test="$target">
3591      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$target/@anchor}" class="smpl"><xsl:value-of select="."/></a>
3592    </xsl:when>
3593    <xsl:otherwise>
3594      <xsl:message>WARNING: internal link target for '<xsl:value-of select="."/>' does not exist.<xsl:call-template name="lineno"/></xsl:message>
3595      <xsl:value-of select="."/>
3596    </xsl:otherwise>
3597  </xsl:choose>
3598</xsl:template>
3599
3600<!-- Nothing to do here -->
3601<xsl:template match="x:anchor-alias"/>
3602
3603<!-- Quotes -->
3604<xsl:template match="x:q">
3605  <q xmlns="http://www.w3.org/1999/xhtml">
3606    <xsl:copy-of select="@cite"/>
3607    <xsl:apply-templates/>
3608  </q>
3609</xsl:template>
3610
3611<xsl:template match="x:bcp14">
3612  <!-- check valid BCP14 keywords, then emphasize them -->
3613  <xsl:variable name="c" select="normalize-space(.)"/>
3614  <xsl:choose>
3615    <xsl:when test="$c='MUST' or $c='REQUIRED' or $c='SHALL'">
3616      <em xmlns="http://www.w3.org/1999/xhtml" class="bcp14"><xsl:value-of select="."/></em>
3617    </xsl:when>
3618    <xsl:when test="$c='MUST NOT' or $c='SHALL NOT'">
3619      <em xmlns="http://www.w3.org/1999/xhtml" class="bcp14"><xsl:value-of select="."/></em>
3620    </xsl:when>
3621    <xsl:when test="$c='SHOULD' or $c='RECOMMENDED'">
3622      <em xmlns="http://www.w3.org/1999/xhtml" class="bcp14"><xsl:value-of select="."/></em>
3623    </xsl:when>
3624    <xsl:when test="$c='SHOULD NOT' or $c='NOT RECOMMENDED'">
3625      <em xmlns="http://www.w3.org/1999/xhtml" class="bcp14"><xsl:value-of select="."/></em>
3626    </xsl:when>
3627    <xsl:when test="$c='MAY' or $c='OPTIONAL'">
3628      <em xmlns="http://www.w3.org/1999/xhtml" class="bcp14"><xsl:value-of select="."/></em>
3629    </xsl:when>
3630    <xsl:otherwise>
3631      <xsl:value-of select="."/>
3632      <xsl:message>ERROR: unknown BCP14 keyword: <xsl:value-of select="."/></xsl:message>
3633    </xsl:otherwise>
3634  </xsl:choose>
3635</xsl:template>
3636
3637<xsl:template match="x:blockquote">
3638  <xsl:variable name="p">
3639    <xsl:call-template name="get-paragraph-number"/>
3640  </xsl:variable>
3641
3642  <blockquote xmlns="http://www.w3.org/1999/xhtml">
3643    <xsl:if test="string-length($p) &gt; 0 and not(ancestor::ed:del) and not(ancestor::ed:ins)">
3644      <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$p"/></xsl:attribute>
3645    </xsl:if>
3646    <xsl:call-template name="insertInsDelClass"/>
3647    <xsl:call-template name="editingMark"/>
3648    <xsl:copy-of select="@cite"/>
3649    <xsl:apply-templates/>
3650  </blockquote>
3651</xsl:template>
3652
3653<!-- Definitions -->
3654<xsl:template match="x:dfn">
3655  <dfn xmlns="http://www.w3.org/1999/xhtml">
3656    <xsl:apply-templates/>
3657  </dfn>
3658</xsl:template>
3659
3660<!-- headings -->
3661<xsl:template match="x:h">
3662  <b xmlns="http://www.w3.org/1999/xhtml">
3663    <xsl:apply-templates/>
3664  </b>
3665</xsl:template>
3666
3667<!-- box drawing -->
3668
3669<!-- nop for alignment -->
3670<xsl:template match="x:x"/>
3671
3672<!-- box (top) -->
3673<xsl:template match="x:bt">
3674  <xsl:text>&#9484;</xsl:text>
3675  <xsl:value-of select="translate(substring(.,2,string-length(.)-2),'-','&#9472;')"/>
3676  <xsl:text>&#9488;</xsl:text>
3677</xsl:template>
3678
3679<!-- box (center) -->
3680<xsl:template match="x:bc">
3681  <xsl:variable name="first" select="substring(.,1)"/>
3682  <xsl:variable name="last" select="substring(.,string-length(.)-1)"/>
3683  <xsl:variable name="content" select="substring(.,2,string-length(.)-2)"/>
3684  <xsl:variable name="is-delimiter" select="translate($content,'-','')=''"/>
3685 
3686  <xsl:choose>
3687    <xsl:when test="$is-delimiter">
3688      <xsl:text>&#9500;</xsl:text>
3689      <xsl:value-of select="translate($content,'-','&#9472;')"/>
3690      <xsl:text>&#9508;</xsl:text>
3691    </xsl:when>
3692    <xsl:when test="*">
3693      <xsl:for-each select="node()">
3694        <xsl:choose>
3695          <xsl:when test="position()=1">
3696            <xsl:text>&#9474;</xsl:text>
3697            <xsl:value-of select="substring(.,2)"/>
3698          </xsl:when>
3699          <xsl:when test="position()=last()">
3700            <xsl:value-of select="substring(.,1,string-length(.)-1)"/>
3701            <xsl:text>&#9474;</xsl:text>
3702          </xsl:when>
3703          <xsl:otherwise>
3704            <xsl:apply-templates select="."/>
3705          </xsl:otherwise>
3706        </xsl:choose>
3707      </xsl:for-each>
3708    </xsl:when>
3709    <xsl:otherwise>
3710      <xsl:text>&#9474;</xsl:text>
3711      <xsl:value-of select="$content"/>
3712      <xsl:text>&#9474;</xsl:text>
3713    </xsl:otherwise>
3714  </xsl:choose>
3715 
3716</xsl:template>
3717
3718<!-- box (bottom) -->
3719<xsl:template match="x:bb">
3720  <xsl:text>&#9492;</xsl:text>
3721  <xsl:value-of select="translate(substring(.,2,string-length(.)-2),'-','&#9472;')"/>
3722  <xsl:text>&#9496;</xsl:text>
3723</xsl:template>
3724
3725<!-- experimental annotation support -->
3726
3727<xsl:template match="ed:issueref">
3728  <xsl:choose>
3729    <xsl:when test=".=//ed:issue/@name">
3730      <a xmlns="http://www.w3.org/1999/xhtml" href="#{$anchor-prefix}.issue.{.}">
3731        <xsl:apply-templates/>
3732      </a>
3733    </xsl:when>
3734    <xsl:otherwise>
3735      <xsl:call-template name="warning">
3736        <xsl:with-param name="msg">Dangling ed:issueref: <xsl:value-of select="."/></xsl:with-param>
3737      </xsl:call-template>
3738      <xsl:apply-templates/>
3739    </xsl:otherwise>
3740  </xsl:choose>
3741</xsl:template>
3742
3743<xsl:template match="ed:issue">
3744  <xsl:variable name="class">
3745    <xsl:choose>
3746      <xsl:when test="@status='closed'">closedissue</xsl:when>
3747      <xsl:otherwise>openissue</xsl:otherwise>
3748    </xsl:choose>
3749  </xsl:variable>
3750 
3751  <table xmlns="http://www.w3.org/1999/xhtml" summary="issue {@name}" class="{$class}">
3752    <tr>
3753      <td colspan="3">
3754        <a id="{$anchor-prefix}.issue.{@name}">
3755          <xsl:choose>
3756            <xsl:when test="@status='closed'">
3757              <xsl:attribute name="class">closed-issue</xsl:attribute>
3758            </xsl:when>
3759            <xsl:when test="@status='editor'">
3760              <xsl:attribute name="class">editor-issue</xsl:attribute>
3761            </xsl:when>
3762            <xsl:otherwise>
3763              <xsl:attribute name="class">open-issue</xsl:attribute>
3764            </xsl:otherwise>
3765          </xsl:choose>
3766          <xsl:text> I </xsl:text>
3767        </a>
3768        <xsl:text> </xsl:text>
3769        <xsl:choose>
3770          <xsl:when test="@href">
3771            <em><a href="{@href}"><xsl:value-of select="@name"/></a></em>
3772          </xsl:when>
3773          <xsl:when test="@alternate-href">
3774            <em>[<a href="{@alternate-href}">alternate link</a>]</em>
3775          </xsl:when>
3776          <xsl:otherwise>
3777            <em><xsl:value-of select="@name"/></em>
3778          </xsl:otherwise>
3779        </xsl:choose>
3780         
3781        (type: <xsl:value-of select="@type"/>, status: <xsl:value-of select="@status"/>)
3782      </td>
3783    </tr>
3784
3785    <xsl:apply-templates select="ed:item"/>
3786    <xsl:apply-templates select="ed:resolution"/>
3787
3788    <xsl:variable name="changes" select="//*[@ed:resolves=current()/@name or ed:resolves=current()/@name]"/>
3789    <xsl:if test="$changes">
3790      <tr>
3791        <td class="top" colspan="3">
3792          Associated changes in this document:
3793          <xsl:variable name="issue" select="@name"/>
3794          <xsl:for-each select="$changes">
3795            <a href="#{$anchor-prefix}.change.{$issue}.{position()}">
3796              <xsl:variable name="label">
3797                <xsl:call-template name="get-section-number"/>
3798              </xsl:variable>
3799              <xsl:choose>
3800                <xsl:when test="$label!=''"><xsl:value-of select="$label"/></xsl:when>
3801                <xsl:otherwise>&lt;<xsl:value-of select="concat('#',$anchor-prefix,'.change.',$issue,'.',position())"/>&gt;</xsl:otherwise>
3802              </xsl:choose>
3803            </a>
3804            <xsl:if test="position()!=last()">, </xsl:if>
3805          </xsl:for-each>
3806          <xsl:text>.</xsl:text>
3807        </td>
3808      </tr>
3809    </xsl:if>
3810  </table>
3811   
3812</xsl:template>
3813
3814<xsl:template match="ed:item">
3815  <tr xmlns="http://www.w3.org/1999/xhtml">
3816    <td class="top">
3817      <xsl:if test="@entered-by">
3818        <a href="mailto:{@entered-by}?subject={/rfc/@docName},%20{../@name}">
3819          <i><xsl:value-of select="@entered-by"/></i>
3820        </a>
3821      </xsl:if>
3822    </td>
3823    <td class="topnowrap">
3824      <xsl:value-of select="@date"/>
3825    </td>
3826    <td class="top">
3827      <xsl:apply-templates select="node()" mode="issuehtml"/>
3828    </td>
3829  </tr>
3830</xsl:template>
3831
3832<xsl:template match="ed:resolution">
3833  <tr xmlns="http://www.w3.org/1999/xhtml">
3834    <td class="top">
3835      <xsl:if test="@entered-by">
3836        <a href="mailto:{@entered-by}?subject={/rfc/@docName},%20{../@name}"><i><xsl:value-of select="@entered-by"/></i></a>
3837      </xsl:if>
3838    </td>
3839    <td class="topnowrap">
3840      <xsl:value-of select="@datetime"/>
3841    </td>
3842    <td class="top">
3843      <em>Resolution:</em>
3844      <xsl:apply-templates select="node()" mode="issuehtml"/>
3845    </td>
3846  </tr>
3847</xsl:template>
3848
3849<xsl:template match="ed:annotation">
3850  <em xmlns="http://www.w3.org/1999/xhtml">
3851    <xsl:apply-templates/>
3852  </em>
3853</xsl:template>
3854
3855<!-- special templates for handling XHTML in issues -->
3856<xsl:template match="text()" mode="issuehtml">
3857  <xsl:value-of select="."/>
3858</xsl:template>
3859
3860<xsl:template match="*|@*" mode="issuehtml">
3861  <xsl:message terminate="yes">Unexpected node in issue HTML: <xsl:value-of select="local-name(.)"/></xsl:message>
3862</xsl:template>
3863
3864<xsl:template match="xhtml:a|xhtml:b|xhtml:br|xhtml:cite|xhtml:del|xhtml:em|xhtml:i|xhtml:ins|xhtml:q|xhtml:pre|xhtml:tt" mode="issuehtml">
3865  <xsl:element namespace="http://www.w3.org/1999/xhtml" name="{local-name()}">
3866    <xsl:apply-templates select="@*|node()" mode="issuehtml"/>
3867  </xsl:element>
3868</xsl:template>
3869
3870<xsl:template match="xhtml:p" mode="issuehtml">
3871  <xsl:apply-templates select="node()" mode="issuehtml"/>
3872  <br xmlns="http://www.w3.org/1999/xhtml" class="p"/>
3873</xsl:template>
3874
3875<xsl:template match="xhtml:a/@href|xhtml:q/@cite" mode="issuehtml">
3876  <xsl:attribute name="{local-name(.)}">
3877    <xsl:value-of select="."/>
3878  </xsl:attribute>
3879</xsl:template>
3880
3881<xsl:template match="ed:issueref" mode="issuehtml">
3882  <xsl:apply-templates select="."/>
3883</xsl:template>
3884
3885<xsl:template match="ed:eref" mode="issuehtml">
3886  <xsl:text>&lt;</xsl:text>
3887  <a xmlns="http://www.w3.org/1999/xhtml" href="{.}"><xsl:value-of select="."/></a>
3888  <xsl:text>&gt;</xsl:text>
3889</xsl:template>
3890
3891<xsl:template name="insertIssuesList">
3892
3893  <h2 xmlns="http://www.w3.org/1999/xhtml" id="{$anchor-prefix}.issues-list"><a href="#{$anchor-prefix}.issues-list">Issues list</a></h2>
3894  <table xmlns="http://www.w3.org/1999/xhtml" summary="Issues list">
3895    <thead>
3896      <tr>
3897        <th>Id</th>
3898        <th>Type</th>
3899        <th>Status</th>
3900        <th>Date</th>
3901        <th>Raised By</th>
3902      </tr>
3903    </thead>
3904    <tbody>
3905      <xsl:for-each select="//ed:issue">
3906        <xsl:sort select="@status"/>
3907        <xsl:sort select="@name"/>
3908        <tr>
3909          <td><a href="#{$anchor-prefix}.issue.{@name}"><xsl:value-of select="@name"/></a></td>
3910          <td><xsl:value-of select="@type"/></td>
3911          <td><xsl:value-of select="@status"/></td>
3912          <td><xsl:value-of select="ed:item[1]/@date"/></td>
3913          <td><a href="mailto:{ed:item[1]/@entered-by}?subject={/rfc/@docName},%20{@name}"><xsl:value-of select="ed:item[1]/@entered-by"/></a></td>
3914        </tr>
3915      </xsl:for-each>
3916    </tbody>
3917  </table>
3918 
3919</xsl:template>
3920
3921<xsl:template name="formatTitle">
3922  <xsl:if test="@who">
3923    <xsl:value-of select="@who"/>
3924  </xsl:if>
3925  <xsl:if test="@datetime">
3926    <xsl:value-of select="concat(' (',@datetime,')')"/>
3927  </xsl:if>
3928  <xsl:if test="@reason">
3929    <xsl:value-of select="concat(': ',@reason)"/>
3930  </xsl:if>
3931  <xsl:if test="@cite">
3932    <xsl:value-of select="concat(' &lt;',@cite,'&gt;')"/>
3933  </xsl:if>
3934</xsl:template>
3935
3936<xsl:template name="insert-diagnostics">
3937 
3938  <!-- check anchor names -->
3939  <xsl:variable name="badAnchors" select="//*[starts-with(@anchor,concat($anchor-prefix,'.'))]"/>
3940  <xsl:if test="$badAnchors">
3941    <p xmlns="http://www.w3.org/1999/xhtml" class="warning">
3942      The following anchor names may collide with internally generated anchors because of their prefix "<xsl:value-of select="$anchor-prefix"/>":
3943      <xsl:for-each select="$badAnchors">
3944        <xsl:value-of select="@anchor"/><xsl:if test="position()!=last()">, </xsl:if>
3945      </xsl:for-each>
3946    </p>
3947    <xsl:message>
3948      The following anchor names may collide with internally generated anchors because of their prefix "<xsl:value-of select="$anchor-prefix"/>":
3949      <xsl:for-each select="$badAnchors">
3950        <xsl:value-of select="@anchor"/><xsl:if test="position()!=last()">, </xsl:if>
3951      </xsl:for-each>
3952    </xsl:message>
3953  </xsl:if>
3954 
3955  <!-- check IDs -->
3956  <xsl:variable name="badTargets" select="//xref[not(@target=//@anchor) and not(ancestor::ed:del)]"/>
3957  <xsl:if test="$badTargets">
3958    <p xmlns="http://www.w3.org/1999/xhtml" class="error">
3959      The following target names do not exist:
3960      <xsl:for-each select="$badTargets">
3961        <xsl:value-of select="@target"/><xsl:if test="position()!=last()">, </xsl:if>
3962      </xsl:for-each>
3963    </p>
3964    <xsl:message>
3965      The following target names do not exist:
3966      <xsl:for-each select="$badTargets">
3967        <xsl:value-of select="@target"/><xsl:if test="position()!=last()">, </xsl:if>
3968      </xsl:for-each>
3969    </xsl:message>
3970  </xsl:if>
3971 
3972 
3973</xsl:template>
3974
3975<!-- special change mark support, not supported by RFC2629 yet -->
3976
3977<xsl:template match="@ed:*"/>
3978
3979<xsl:template match="ed:del">
3980  <xsl:call-template name="insert-issue-pointer"/>
3981  <del xmlns="http://www.w3.org/1999/xhtml">
3982    <xsl:copy-of select="@*[namespace-uri()='']"/>
3983    <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
3984      <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
3985    </xsl:if>
3986    <xsl:apply-templates/>
3987  </del>
3988</xsl:template>
3989
3990<xsl:template match="ed:ins">
3991  <xsl:call-template name="insert-issue-pointer"/>
3992  <ins xmlns="http://www.w3.org/1999/xhtml">
3993    <xsl:copy-of select="@*[namespace-uri()='']"/>
3994    <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
3995      <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
3996    </xsl:if>
3997    <xsl:apply-templates/>
3998  </ins>
3999</xsl:template>
4000
4001<xsl:template name="insert-issue-pointer">
4002  <xsl:param name="deleted-anchor"/>
4003  <xsl:variable name="change" select="."/>
4004  <xsl:for-each select="@ed:resolves|ed:resolves">
4005    <xsl:variable name="resolves" select="."/>
4006    <!-- need the right context node for proper numbering -->
4007    <xsl:variable name="count"><xsl:for-each select=".."><xsl:number level="any" count="*[@ed:resolves=$resolves or ed:resolves=$resolves]"/></xsl:for-each></xsl:variable>
4008    <xsl:variable name="total" select="count(//*[@ed:resolves=$resolves or ed:resolves=$resolves])"/>
4009    <xsl:variable name="id">
4010      <xsl:value-of select="$anchor-prefix"/>.change.<xsl:value-of select="$resolves"/>.<xsl:value-of select="$count"/>
4011    </xsl:variable>
4012    <xsl:choose>
4013      <!-- block level? -->
4014      <xsl:when test="not(ancestor::t) and not(ancestor::title) and not(ancestor::figure) and not($change/@ed:old-title)">
4015        <div xmlns="http://www.w3.org/1999/xhtml" class="issuepointer noprint">
4016          <xsl:if test="not($deleted-anchor)">
4017            <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4018          </xsl:if>
4019          <xsl:if test="$count &gt; 1">
4020            <a class="bg-issue" title="previous change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count - 1}">&#8593;</a>
4021          </xsl:if>
4022          <a class="open-issue" href="#{$anchor-prefix}.issue.{$resolves}" title="resolves: {$resolves}">
4023            <xsl:choose>
4024              <xsl:when test="//ed:issue[@name=$resolves and @status='closed']">
4025                <xsl:attribute name="class">closed-issue</xsl:attribute>
4026              </xsl:when>
4027              <xsl:when test="//ed:issue[@name=$resolves and @status='editor']">
4028                <xsl:attribute name="class">editor-issue</xsl:attribute>
4029              </xsl:when>
4030              <xsl:otherwise>
4031                <xsl:attribute name="class">open-issue</xsl:attribute>
4032              </xsl:otherwise>
4033            </xsl:choose>
4034            <xsl:text> I </xsl:text>
4035          </a>
4036          <xsl:if test="$count &lt; $total">
4037            <a class="bg-issue" title="next change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count + 1}">&#8595;</a>
4038          </xsl:if>
4039          <xsl:text> </xsl:text>
4040        </div>
4041      </xsl:when>
4042      <xsl:otherwise>
4043        <xsl:if test="$count &gt; 1">
4044          <a xmlns="http://www.w3.org/1999/xhtml" class="bg-issue" title="previous change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count - 1}">&#8593;</a>
4045        </xsl:if>
4046        <a xmlns="http://www.w3.org/1999/xhtml" title="resolves: {$resolves}" href="#{$anchor-prefix}.issue.{$resolves}">
4047          <xsl:if test="not($deleted-anchor)">
4048            <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4049          </xsl:if>
4050          <xsl:choose>
4051            <xsl:when test="//ed:issue[@name=$resolves and @status='closed']">
4052              <xsl:attribute name="class">closed-issue noprint</xsl:attribute>
4053            </xsl:when>
4054            <xsl:when test="//ed:issue[@name=$resolves and @status='editor']">
4055              <xsl:attribute name="class">editor-issue noprint</xsl:attribute>
4056            </xsl:when>
4057            <xsl:otherwise>
4058              <xsl:attribute name="class">open-issue noprint</xsl:attribute>
4059            </xsl:otherwise>
4060          </xsl:choose>
4061          <xsl:text> I </xsl:text>
4062        </a>
4063        <xsl:if test="$count &lt; $total">
4064          <a xmlns="http://www.w3.org/1999/xhtml" class="bg-issue" title="next change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count + 1}">&#8595;</a>
4065        </xsl:if>
4066      </xsl:otherwise>
4067    </xsl:choose>
4068  </xsl:for-each>
4069</xsl:template>
4070
4071<xsl:template match="ed:replace">
4072  <!-- we need to special-case things like lists and tables -->
4073  <xsl:choose>
4074    <xsl:when test="parent::list">
4075      <xsl:apply-templates select="ed:del/node()"/>
4076      <xsl:apply-templates select="ed:ins/node()"/>
4077    </xsl:when>
4078    <xsl:when test="ancestor::references">
4079      <xsl:apply-templates select="ed:del/node()"/>
4080      <xsl:apply-templates select="ed:ins/node()"/>
4081    </xsl:when>
4082    <xsl:otherwise>
4083      <xsl:if test="@cite">
4084        <a xmlns="http://www.w3.org/1999/xhtml" class="editor-issue" href="{@cite}" target="_blank" title="see {@cite}">
4085          <xsl:text> i </xsl:text>
4086        </a>
4087      </xsl:if>
4088      <xsl:call-template name="insert-issue-pointer"/>
4089      <xsl:if test="ed:del">
4090        <del xmlns="http://www.w3.org/1999/xhtml">
4091          <xsl:copy-of select="@*[namespace-uri()='']"/>
4092          <xsl:if test="not(@title) and ancestor-or-self::xsl:template[@ed:entered-by] and @datetime">
4093            <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
4094          </xsl:if>
4095          <xsl:apply-templates select="ed:del/node()"/>
4096        </del>
4097      </xsl:if>
4098      <xsl:if test="ed:ins">
4099        <ins xmlns="http://www.w3.org/1999/xhtml">
4100          <xsl:copy-of select="@*[namespace-uri()='']"/>
4101          <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
4102            <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
4103          </xsl:if>
4104          <xsl:apply-templates select="ed:ins/node()"/>
4105        </ins>
4106      </xsl:if>
4107    </xsl:otherwise>
4108  </xsl:choose>
4109</xsl:template>
4110
4111<!-- convenience template for helping Mozilla (pre/ins inheritance problem) -->
4112<xsl:template name="insertInsDelClass">
4113  <xsl:if test="ancestor::ed:del">
4114    <xsl:attribute name="class">del</xsl:attribute>
4115  </xsl:if>
4116  <xsl:if test="ancestor::ed:ins">
4117    <xsl:attribute name="class">ins</xsl:attribute>
4118  </xsl:if>
4119</xsl:template>
4120
4121
4122<xsl:template name="sectionnumberAndEdits">
4123  <xsl:choose>
4124    <xsl:when test="ancestor::ed:del">del-<xsl:number count="ed:del//section" level="any"/></xsl:when>
4125    <xsl:when test="@x:fixed-section-number">
4126      <xsl:value-of select="@x:fixed-section-number"/>
4127    </xsl:when>
4128    <xsl:when test="self::section and parent::ed:ins and local-name(../..)='replace'">
4129      <xsl:for-each select="../.."><xsl:call-template name="sectionnumberAndEdits"/></xsl:for-each>
4130      <xsl:for-each select="..">
4131        <xsl:if test="parent::ed:replace">
4132          <xsl:for-each select="..">
4133            <xsl:if test="parent::section">.</xsl:if>
4134            <xsl:variable name="cnt" select="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)"/>
4135            <xsl:choose>
4136              <xsl:when test="ancestor::back and not(ancestor::section)"><xsl:number format="A" value="$cnt"/></xsl:when>
4137              <xsl:otherwise><xsl:value-of select="$cnt"/></xsl:otherwise>
4138            </xsl:choose>
4139          </xsl:for-each>
4140        </xsl:if>
4141      </xsl:for-each>
4142    </xsl:when>
4143    <xsl:when test="self::section[parent::ed:ins]">
4144      <xsl:for-each select="../.."><xsl:call-template name="sectionnumberAndEdits"/></xsl:for-each>
4145      <xsl:for-each select="..">
4146        <xsl:if test="parent::section">.</xsl:if><xsl:value-of select="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)"/>
4147      </xsl:for-each>
4148    </xsl:when>
4149    <xsl:when test="self::section">
4150      <xsl:for-each select=".."><xsl:call-template name="sectionnumberAndEdits"/></xsl:for-each>
4151      <xsl:if test="parent::section">.</xsl:if>
4152      <xsl:choose>
4153        <xsl:when test="parent::back">
4154          <xsl:number format="A" value="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)"/>
4155        </xsl:when>
4156        <xsl:otherwise>
4157          <xsl:number value="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)"/>
4158        </xsl:otherwise>
4159      </xsl:choose>
4160    </xsl:when>
4161    <xsl:when test="self::references">
4162      <xsl:choose>
4163        <xsl:when test="count(/*/back/references)+count(/*/back/ed:replace/ed:ins/references)=1"><xsl:call-template name="get-references-section-number"/></xsl:when>
4164        <xsl:otherwise><xsl:call-template name="get-references-section-number"/>.<xsl:number level="any"/></xsl:otherwise>
4165      </xsl:choose>
4166    </xsl:when>
4167    <xsl:when test="self::middle or self::back"><!-- done --></xsl:when>
4168    <xsl:otherwise>
4169      <!-- go up one level -->
4170      <xsl:for-each select=".."><xsl:call-template name="sectionnumberAndEdits"/></xsl:for-each>
4171    </xsl:otherwise>
4172  </xsl:choose>
4173</xsl:template>
4174
4175<!-- utilities for warnings -->
4176
4177<xsl:template name="warning">
4178  <xsl:param name="msg"/>
4179  <xsl:param name="msg2"/>
4180  <div xmlns="http://www.w3.org/1999/xhtml" class="error">WARNING: <xsl:value-of select="$msg"/></div>
4181  <xsl:message>WARNING: <xsl:value-of select="$msg"/><xsl:value-of select="$msg2"/><xsl:call-template name="lineno"/></xsl:message>
4182</xsl:template>
4183
4184<xsl:template name="error">
4185  <xsl:param name="msg"/>
4186  <xsl:param name="msg2"/>
4187  <div xmlns="http://www.w3.org/1999/xhtml" class="error">ERROR: <xsl:value-of select="$msg"/></div>
4188  <xsl:message>ERROR: <xsl:value-of select="$msg"/><xsl:value-of select="$msg2"/><xsl:call-template name="lineno"/></xsl:message>
4189</xsl:template>
4190
4191<!-- table formatting -->
4192
4193<xsl:template match="texttable">
4194
4195  <xsl:variable name="anch">
4196    <xsl:call-template name="get-table-anchor"/>
4197  </xsl:variable>
4198
4199  <div xmlns="http://www.w3.org/1999/xhtml" id="{$anch}">
4200    <xsl:if test="@anchor!=''">
4201      <div id="{@anchor}"/>
4202    </xsl:if>
4203    <xsl:apply-templates select="preamble"/>
4204    <xsl:variable name="style">
4205      <xsl:text>tt </xsl:text>
4206      <xsl:choose>
4207        <xsl:when test="@style!=''">
4208          <xsl:value-of select="@style"/>
4209        </xsl:when>
4210        <xsl:otherwise>full</xsl:otherwise>
4211      </xsl:choose>
4212    </xsl:variable>
4213    <table summary="{preamble}" class="{$style}" cellpadding="3" cellspacing="0">
4214      <thead>
4215        <tr>
4216          <xsl:apply-templates select="ttcol"/>
4217        </tr>
4218      </thead>
4219      <tbody>
4220        <xsl:variable name="columns" select="count(ttcol)"/>
4221        <xsl:variable name="fields" select="c | ed:replace/ed:ins/c | ed:replace/ed:del/c"/>
4222        <xsl:for-each select="$fields[(position() mod $columns) = 1]">
4223          <tr>
4224            <xsl:for-each select=". | following-sibling::c[position() &lt; $columns]">
4225              <td>
4226                <xsl:call-template name="insertInsDelClass"/>
4227                <xsl:variable name="pos" select="position()"/>
4228                <xsl:variable name="col" select="../ttcol[position() = $pos]"/>
4229                <xsl:choose>
4230                  <xsl:when test="$col/@align='right' or $col/@align='center'">
4231                    <xsl:attribute name="class"><xsl:value-of select="$col/@align"/></xsl:attribute>
4232                  </xsl:when>
4233                  <xsl:when test="$col/@align='left' or not($col/@align)">
4234                    <!-- that's the default, nothing to do here -->
4235                  </xsl:when>
4236                  <xsl:otherwise>
4237                    <xsl:message>Unknown align attribute on ttcol: <xsl:value-of select="$col/@align"/></xsl:message>
4238                  </xsl:otherwise>
4239                </xsl:choose>
4240                <xsl:apply-templates select="node()"/>
4241              </td>
4242            </xsl:for-each>
4243          </tr>
4244        </xsl:for-each>
4245      </tbody>
4246    </table>
4247    <xsl:apply-templates select="postamble"/>
4248
4249    <xsl:if test="@title!='' or @anchor!=''">
4250      <xsl:variable name="n"><xsl:number level="any" count="texttable[@title!='' or @anchor!='']"/></xsl:variable>
4251      <p class="figure">Table <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title"/></xsl:if></p>
4252    </xsl:if>
4253  </div>
4254 
4255</xsl:template>
4256
4257<xsl:template match="ttcol">
4258  <th xmlns="http://www.w3.org/1999/xhtml">
4259   
4260    <xsl:choose>
4261      <xsl:when test="@align='right' or @align='center' or @align='left'">
4262        <xsl:attribute name="class"><xsl:value-of select="@align"/></xsl:attribute>
4263      </xsl:when>
4264      <xsl:when test="not(@align)">
4265        <!-- that's the default, nothing to do here -->
4266      </xsl:when>
4267      <xsl:otherwise>
4268        <xsl:message>Unknown align attribute on ttcol: <xsl:value-of select="@align"/></xsl:message>
4269      </xsl:otherwise>
4270    </xsl:choose>
4271   
4272    <xsl:if test="@width">
4273      <xsl:attribute name="style">width: <xsl:value-of select="@width"/>;</xsl:attribute>
4274    </xsl:if>
4275
4276    <xsl:apply-templates/>
4277  </th>
4278</xsl:template>
4279
4280<!-- cref support -->
4281
4282<xsl:template match="cref">
4283  <xsl:if test="$xml2rfc-comments!='no'">
4284    <xsl:variable name="cid">
4285      <xsl:choose>
4286        <xsl:when test="@anchor">
4287          <xsl:value-of select="@anchor"/>
4288        </xsl:when>
4289        <xsl:otherwise>
4290          <xsl:value-of select="$anchor-prefix"/>
4291          <xsl:text>.comment.</xsl:text>
4292          <xsl:number count="cref[not(@anchor)]" level="any"/>
4293        </xsl:otherwise>
4294      </xsl:choose>
4295    </xsl:variable>
4296   
4297    <span xmlns="http://www.w3.org/1999/xhtml" class="comment">
4298      <xsl:if test="$xml2rfc-inline!='yes'">
4299        <xsl:attribute name="title">
4300          <xsl:if test="@source"><xsl:value-of select="@source"/>: </xsl:if>
4301          <xsl:value-of select="."/>
4302        </xsl:attribute>
4303      </xsl:if>
4304      <xsl:text>[</xsl:text>
4305      <xsl:choose>
4306        <xsl:when test="$xml2rfc-inline='yes'">
4307          <xsl:value-of select="$cid"/>
4308          <xsl:text>: </xsl:text>
4309          <xsl:value-of select="."/>
4310          <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
4311        </xsl:when>
4312        <xsl:otherwise>
4313          <a href="#{$cid}">
4314            <xsl:value-of select="$cid"/>
4315          </a>
4316        </xsl:otherwise>
4317      </xsl:choose>
4318      <xsl:text>]</xsl:text>
4319    </span>
4320  </xsl:if>
4321</xsl:template>
4322
4323<xsl:template name="insertComments">
4324
4325  <xsl:call-template name="insert-conditional-hrule"/>
4326   
4327  <h1 xmlns="http://www.w3.org/1999/xhtml">
4328    <xsl:call-template name="insert-conditional-pagebreak"/>
4329    <a id="{$anchor-prefix}.comments" href="#{$anchor-prefix}.comments">Editorial Comments</a>
4330  </h1>
4331
4332  <dl xmlns="http://www.w3.org/1999/xhtml">
4333    <xsl:for-each select="//cref">
4334      <xsl:variable name="cid">
4335        <xsl:choose>
4336          <xsl:when test="@anchor">
4337            <xsl:value-of select="@anchor"/>
4338          </xsl:when>
4339          <xsl:otherwise>
4340            <xsl:value-of select="$anchor-prefix"/>
4341            <xsl:text>.comment.</xsl:text>
4342            <xsl:number count="cref[not(@anchor)]" level="any"/>
4343          </xsl:otherwise>
4344        </xsl:choose>
4345      </xsl:variable>
4346      <dt id="{$cid}">
4347        [<xsl:value-of select="$cid"/>]
4348      </dt>
4349      <dd>
4350        <xsl:value-of select="."/>
4351        <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
4352      </dd>
4353    </xsl:for-each>
4354  </dl>
4355</xsl:template>
4356
4357
4358<!-- Chapter Link Generation -->
4359
4360<xsl:template match="*" mode="links"><xsl:apply-templates mode="links"/></xsl:template>
4361<xsl:template match="text()" mode="links"/>
4362
4363<xsl:template match="/*/middle//section[not(myns:unnumbered) and not(ancestor::section)]" mode="links">
4364  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number"/></xsl:variable>
4365  <link xmlns="http://www.w3.org/1999/xhtml" rel="Chapter" title="{$sectionNumber} {@title}" href="#{$anchor-prefix}.section.{$sectionNumber}"/>
4366  <xsl:apply-templates mode="links"/>
4367</xsl:template>
4368
4369<xsl:template match="/*/back//section[not(myns:unnumbered) and not(ancestor::section)]" mode="links">
4370  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number"/></xsl:variable>
4371  <link xmlns="http://www.w3.org/1999/xhtml" rel="Appendix" title="{$sectionNumber} {@title}" href="#{$anchor-prefix}.section.{$sectionNumber}"/>
4372  <xsl:apply-templates mode="links"/>
4373</xsl:template>
4374
4375<xsl:template match="/*/back/references[position()=1]" mode="links">
4376  <xsl:variable name="sectionNumber"><xsl:call-template name="get-references-section-number"/></xsl:variable>
4377  <link xmlns="http://www.w3.org/1999/xhtml" rel="Chapter" href="#{$anchor-prefix}.section.{$sectionNumber}">
4378    <xsl:choose>
4379      <xsl:when test="@title and count(/*/back/references)=1">
4380        <xsl:attribute name="title">
4381          <xsl:call-template name="get-references-section-number"/>
4382          <xsl:text> </xsl:text>
4383          <xsl:value-of select="@title"/>
4384        </xsl:attribute>
4385      </xsl:when>
4386      <xsl:otherwise>
4387        <xsl:attribute name="title">
4388          <xsl:call-template name="get-references-section-number"/>
4389          <xsl:text> References</xsl:text>
4390        </xsl:attribute>
4391      </xsl:otherwise>
4392    </xsl:choose>
4393  </link>
4394</xsl:template>
4395
4396<!-- convenience templates -->
4397
4398<xsl:template name="get-author-summary">
4399  <xsl:choose>
4400    <xsl:when test="count(/rfc/front/author)=1">
4401      <xsl:value-of select="/rfc/front/author[1]/@surname"/>
4402    </xsl:when>
4403    <xsl:when test="count(/rfc/front/author)=2">
4404      <xsl:value-of select="concat(/rfc/front/author[1]/@surname,' &amp; ',/rfc/front/author[2]/@surname)"/>
4405    </xsl:when>
4406    <xsl:otherwise>
4407      <xsl:value-of select="concat(/rfc/front/author[1]/@surname,', et al.')"/>
4408    </xsl:otherwise>
4409  </xsl:choose>
4410</xsl:template>
4411
4412<xsl:template name="get-authors">
4413  <xsl:for-each select="/rfc/front/author">
4414    <xsl:value-of select="@fullname"/>
4415    <xsl:if test="position()!=last()">, </xsl:if>
4416  </xsl:for-each>
4417</xsl:template>
4418
4419<xsl:template name="get-category-long">
4420  <xsl:choose>
4421    <xsl:when test="$xml2rfc-footer"><xsl:value-of select="$xml2rfc-footer"/></xsl:when>
4422    <xsl:when test="$xml2rfc-private"/> <!-- private draft, footer not set -->
4423    <xsl:when test="/rfc/@category='bcp'">Best Current Practice</xsl:when>
4424    <xsl:when test="/rfc/@category='historic'">Historic</xsl:when>
4425    <xsl:when test="/rfc/@category='info' or not(/rfc/@category)">Informational</xsl:when>
4426    <xsl:when test="/rfc/@category='std'">Standards Track</xsl:when>
4427    <xsl:when test="/rfc/@category='exp'">Experimental</xsl:when>
4428    <xsl:otherwise>(category unknown)</xsl:otherwise>
4429  </xsl:choose>
4430</xsl:template>
4431
4432<xsl:template name="get-header-center">
4433  <xsl:choose>
4434    <xsl:when test="string-length(/rfc/front/title/@abbrev) &gt; 0">
4435      <xsl:value-of select="/rfc/front/title/@abbrev"/>
4436    </xsl:when>
4437    <xsl:otherwise>
4438      <xsl:apply-templates select="/rfc/front/title" mode="get-text-content"/>
4439    </xsl:otherwise>
4440  </xsl:choose>
4441</xsl:template>
4442
4443<xsl:template name="get-header-left">
4444  <xsl:choose>
4445    <xsl:when test="$xml2rfc-header"><xsl:value-of select="$xml2rfc-header"/></xsl:when>
4446    <xsl:when test="$xml2rfc-private"/> <!-- private draft, header not set -->
4447    <xsl:when test="/rfc/@ipr and not(/rfc/@number)">INTERNET DRAFT</xsl:when>
4448    <xsl:otherwise>RFC <xsl:value-of select="/rfc/@number"/></xsl:otherwise>
4449  </xsl:choose>
4450</xsl:template>
4451
4452<xsl:template name="get-generator">
4453  <xsl:variable name="gen">
4454    <xsl:text>http://greenbytes.de/tech/webdav/rfc2629.xslt, </xsl:text>
4455    <!-- when RCS keyword substitution in place, add version info -->
4456    <xsl:if test="contains('$Revision: 1.352 $',':')">
4457      <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.352 $', 'Revision: '),'$','')),', ')"/>
4458    </xsl:if>
4459    <xsl:if test="contains('$Date: 2007/12/09 19:23:50 $',':')">
4460      <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2007/12/09 19:23:50 $', 'Date: '),'$','')),', ')"/>
4461    </xsl:if>
4462    <xsl:value-of select="concat('XSLT vendor: ',system-property('xsl:vendor'),' ',system-property('xsl:vendor-url'))"/>
4463  </xsl:variable>
4464  <xsl:value-of select="$gen"/>
4465</xsl:template>
4466
4467<xsl:template name="get-header-right">
4468  <xsl:value-of select="concat(/rfc/front/date/@month,' ',/rfc/front/date/@year)"/>
4469</xsl:template>
4470
4471<xsl:template name="get-keywords">
4472  <xsl:variable name="keyw">
4473    <xsl:for-each select="/rfc/front/keyword">
4474      <xsl:value-of select="translate(.,',',' ')"/>
4475      <xsl:if test="position()!=last()">, </xsl:if>
4476    </xsl:for-each>
4477  </xsl:variable>
4478  <xsl:value-of select="normalize-space($keyw)"/>
4479</xsl:template>
4480
4481<!-- get language from context node. nearest ancestor or return the default of "en" -->
4482<xsl:template name="get-lang">
4483  <xsl:choose>
4484    <xsl:when test="ancestor-or-self::*[@xml:lang]"><xsl:value-of select="ancestor-or-self::*/@xml:lang"/></xsl:when>
4485    <xsl:otherwise>en</xsl:otherwise>
4486  </xsl:choose>
4487</xsl:template>
4488
4489<xsl:template name="get-section-number">
4490  <xsl:variable name="hasEdits" select="count(//ed:del|//ed:ins)!=0"/>
4491  <xsl:variable name="anchor" select="@anchor"/>
4492  <xsl:choose>
4493    <xsl:when test="@x:fixed-section-number">
4494      <xsl:value-of select="@x:fixed-section-number"/>
4495    </xsl:when>
4496    <xsl:when test="$hasEdits or ancestor::*/@x:fixed-section-number">
4497      <xsl:call-template name="sectionnumberAndEdits"/>
4498    </xsl:when>
4499    <xsl:otherwise>
4500      <xsl:choose>
4501        <xsl:when test="self::references">
4502          <xsl:choose>
4503            <xsl:when test="count(/*/back/references)=1">
4504              <xsl:call-template name="get-references-section-number"/>
4505            </xsl:when>
4506            <xsl:otherwise>
4507              <xsl:call-template name="get-references-section-number"/>.<xsl:number count="references"/>
4508            </xsl:otherwise>
4509          </xsl:choose>
4510        </xsl:when>
4511        <xsl:when test="self::reference">
4512          <xsl:for-each select="parent::references">
4513            <xsl:choose>
4514              <xsl:when test="count(/*/back/references)=1">
4515                <xsl:call-template name="get-references-section-number"/>
4516              </xsl:when>
4517              <xsl:otherwise>
4518                <xsl:call-template name="get-references-section-number"/>.<xsl:number count="references"/>
4519              </xsl:otherwise>
4520            </xsl:choose>
4521          </xsl:for-each>
4522        </xsl:when>
4523        <xsl:when test="ancestor::back"><xsl:number count="section|appendix" level="multiple" format="A.1.1.1.1.1.1.1"/></xsl:when>
4524        <xsl:when test="self::appendix"><xsl:number count="appendix" level="multiple" format="A.1.1.1.1.1.1.1"/></xsl:when>
4525        <xsl:otherwise><xsl:number count="section" level="multiple"/></xsl:otherwise>
4526      </xsl:choose>
4527    </xsl:otherwise>
4528  </xsl:choose>
4529</xsl:template>
4530
4531<!-- get the section number for the references section -->
4532<xsl:template name="get-references-section-number">
4533  <xsl:value-of select="count(/rfc/middle/section) + count(/rfc/middle/ed:replace/ed:ins/section) + 1"/>
4534</xsl:template>
4535
4536<xsl:template name="emit-section-number">
4537  <xsl:param name="no"/>
4538  <xsl:value-of select="$no"/><xsl:if test="not(contains($no,'.')) or $xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
4539</xsl:template>
4540
4541<xsl:template name="get-section-type">
4542  <xsl:param name="prec"/>
4543  <xsl:choose>
4544    <xsl:when test="ancestor::back">Appendix</xsl:when>
4545    <xsl:otherwise>Section</xsl:otherwise>
4546  </xsl:choose>
4547</xsl:template>
4548
4549<xsl:template name="get-table-anchor">
4550  <xsl:value-of select="$anchor-prefix"/>
4551  <xsl:text>.table.</xsl:text>
4552  <xsl:choose>
4553    <xsl:when test="@title!='' or @anchor!=''">
4554      <xsl:number level="any" count="texttable[@title!='' or @anchor!='']"/>
4555    </xsl:when>
4556    <xsl:otherwise>
4557      <xsl:text>u.</xsl:text>
4558      <xsl:number level="any" count="texttable[not(@title!='' or @anchor!='')]"/>
4559    </xsl:otherwise>
4560  </xsl:choose>
4561</xsl:template>
4562
4563<xsl:template name="get-figure-anchor">
4564  <xsl:value-of select="$anchor-prefix"/>
4565  <xsl:text>.figure.</xsl:text>
4566  <xsl:choose>
4567    <xsl:when test="@title!='' or @anchor!=''">
4568      <xsl:number level="any" count="figure[@title!='' or @anchor!='']"/>
4569    </xsl:when>
4570    <xsl:otherwise>
4571      <xsl:text>u.</xsl:text>
4572      <xsl:number level="any" count="figure[not(@title!='' or @anchor!='')]"/>
4573    </xsl:otherwise>
4574  </xsl:choose>
4575</xsl:template>
4576
4577<!-- reformat contents of author/@initials -->
4578<xsl:template name="format-initials">
4579  <xsl:choose>
4580    <xsl:when test="string-length(@initials)=1">
4581      <xsl:value-of select="concat(@initials,'.')"/>
4582    </xsl:when>
4583    <xsl:otherwise>
4584      <xsl:value-of select="@initials"/>
4585    </xsl:otherwise>
4586  </xsl:choose>
4587</xsl:template>
4588
4589<xsl:template name="insert-conditional-pagebreak">
4590  <xsl:if test="$xml2rfc-compact!='yes'">
4591    <xsl:attribute name="class">np</xsl:attribute>
4592  </xsl:if>
4593</xsl:template>
4594
4595<xsl:template name="insert-conditional-hrule">
4596  <xsl:if test="$xml2rfc-compact!='yes'">
4597    <hr xmlns="http://www.w3.org/1999/xhtml" class="noprint"/>
4598  </xsl:if>
4599</xsl:template>
4600
4601<!-- get text content from marked-up text -->
4602
4603<xsl:template match="text()" mode="get-text-content">
4604  <xsl:value-of select="."/>
4605</xsl:template>
4606
4607<xsl:template match="*" mode="get-text-content">
4608  <xsl:apply-templates mode="get-text-content"/>
4609</xsl:template>
4610
4611<xsl:template match="ed:del" mode="get-text-content">
4612</xsl:template>
4613
4614<!-- diag support -->
4615<xsl:template name="lineno">
4616  <xsl:if test="function-available('saxon:line-number')">
4617    <xsl:if test="saxon:line-number() &gt; 0">
4618      <xsl:text> (at line </xsl:text>
4619      <xsl:value-of select="saxon:line-number()"/>
4620      <xsl:text>)</xsl:text>
4621    </xsl:if>
4622  </xsl:if>
4623</xsl:template>
4624
4625</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.