source: rfc2629xslt/rfc2629.xslt @ 729

Last change on this file since 729 was 729, checked in by julian.reschke@…, 10 years ago

Bump up document dates, update to latest versions of rfc2629.xslt

  • Property svn:eol-style set to native
File size: 242.7 KB
Line 
1<!--
2    XSLT transformation from RFC2629 XML format to HTML
3
4    Copyright (c) 2006-2009, Julian Reschke (julian.reschke@greenbytes.de)
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions are met:
9
10    * Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    * Neither the name of Julian Reschke nor the names of its contributors
16      may be used to endorse or promote products derived from this software
17      without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33                version="1.0"
34               
35                xmlns:date="http://exslt.org/dates-and-times"
36                xmlns:ed="http://greenbytes.de/2002/rfcedit"
37                xmlns:exslt="http://exslt.org/common"
38                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
39                xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rcf2629.xslt"
40                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
41                xmlns:saxon="http://saxon.sf.net/"
42                xmlns:saxon-old="http://icl.com/saxon"
43                xmlns:x="http://purl.org/net/xml2rfc/ext"
44                xmlns:xhtml="http://www.w3.org/1999/xhtml"
45
46                exclude-result-prefixes="date ed exslt msxsl myns rdf saxon saxon-old x xhtml"
47                >
48
49<xsl:strip-space elements="back front list middle rfc section"/>               
50               
51<xsl:output method="html" encoding="iso-8859-1" version="4.0" doctype-public="-//W3C//DTD HTML 4.01//EN" indent="no"/>
52
53<!-- rfc comments PI -->
54
55<xsl:param name="xml2rfc-comments">
56  <xsl:call-template name="parse-pis">
57    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
58    <xsl:with-param name="attr" select="'comments'"/>
59    <xsl:with-param name="default" select="'no'"/>
60  </xsl:call-template>
61</xsl:param>
62
63<!-- rfc compact PI -->
64
65<xsl:param name="xml2rfc-compact">
66  <xsl:call-template name="parse-pis">
67    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
68    <xsl:with-param name="attr" select="'compact'"/>
69    <xsl:with-param name="default" select="$xml2rfc-rfcedstyle"/>
70  </xsl:call-template>
71</xsl:param>
72
73<!-- rfc footer PI -->
74
75<xsl:param name="xml2rfc-footer">
76  <xsl:call-template name="parse-pis">
77    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
78    <xsl:with-param name="attr" select="'footer'"/>
79  </xsl:call-template>
80</xsl:param>
81
82<!-- rfc header PI -->
83
84<xsl:param name="xml2rfc-header">
85  <xsl:call-template name="parse-pis">
86    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
87    <xsl:with-param name="attr" select="'header'"/>
88  </xsl:call-template>
89</xsl:param>
90
91<!-- rfc inline PI -->
92
93<xsl:param name="xml2rfc-inline">
94  <xsl:call-template name="parse-pis">
95    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
96    <xsl:with-param name="attr" select="'inline'"/>
97    <xsl:with-param name="default" select="'no'"/>
98  </xsl:call-template>
99</xsl:param>
100
101<!-- include a table of contents if a processing instruction <?rfc?>
102     exists with contents toc="yes". Can be overriden by an XSLT parameter -->
103
104<xsl:param name="xml2rfc-toc">
105  <xsl:call-template name="parse-pis">
106    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
107    <xsl:with-param name="attr" select="'toc'"/>
108    <xsl:with-param name="default" select="'no'"/>
109  </xsl:call-template>
110</xsl:param>
111
112<!-- optional tocdepth-->
113
114<xsl:param name="xml2rfc-tocdepth">
115  <xsl:call-template name="parse-pis">
116    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
117    <xsl:with-param name="attr" select="'tocdepth'"/>
118    <xsl:with-param name="default" select="'3'"/>
119  </xsl:call-template>
120</xsl:param>
121
122<xsl:variable name="parsedTocDepth">
123  <xsl:choose>
124    <xsl:when test="$xml2rfc-tocdepth='1'">1</xsl:when>
125    <xsl:when test="$xml2rfc-tocdepth='2'">2</xsl:when>
126    <xsl:when test="$xml2rfc-tocdepth='3'">3</xsl:when>
127    <xsl:when test="$xml2rfc-tocdepth='4'">4</xsl:when>
128    <xsl:when test="$xml2rfc-tocdepth='5'">5</xsl:when>
129    <xsl:otherwise>99</xsl:otherwise>
130  </xsl:choose>
131</xsl:variable>
132
133<!-- suppress top block if a processing instruction <?rfc?>
134     exists with contents tocblock="no". Can be overriden by an XSLT parameter -->
135
136<xsl:param name="xml2rfc-topblock">
137  <xsl:call-template name="parse-pis">
138    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
139    <xsl:with-param name="attr" select="'topblock'"/>
140    <xsl:with-param name="default" select="'yes'"/>
141  </xsl:call-template>
142</xsl:param>
143
144<!-- Format to the RFC Editor's taste -->
145
146<xsl:param name="xml2rfc-rfcedstyle">
147  <xsl:call-template name="parse-pis">
148    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
149    <xsl:with-param name="attr" select="'rfcedstyle'"/>
150    <xsl:with-param name="default" select="'no'"/>
151  </xsl:call-template>
152</xsl:param>
153
154<!-- the name of an automatically inserted references section -->
155
156<xsl:param name="xml2rfc-refparent">
157  <xsl:call-template name="parse-pis">
158    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
159    <xsl:with-param name="attr" select="'refparent'"/>
160    <xsl:with-param name="default" select="'References'"/>
161  </xsl:call-template>
162</xsl:param>
163
164<!-- use symbolic reference names instead of numeric ones unless a processing instruction <?rfc?>
165     exists with contents symrefs="no". Can be overriden by an XSLT parameter -->
166
167<xsl:param name="xml2rfc-symrefs">
168  <xsl:call-template name="parse-pis">
169    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
170    <xsl:with-param name="attr" select="'symrefs'"/>
171    <xsl:with-param name="default" select="'yes'"/>
172  </xsl:call-template>
173</xsl:param>
174
175<!-- sort references if a processing instruction <?rfc?>
176     exists with contents sortrefs="yes". Can be overriden by an XSLT parameter -->
177
178<xsl:param name="xml2rfc-sortrefs">
179  <xsl:call-template name="parse-pis">
180    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
181    <xsl:with-param name="attr" select="'sortrefs'"/>
182    <xsl:with-param name="default" select="'no'"/>
183  </xsl:call-template>
184</xsl:param>
185
186<!-- insert editing marks if a processing instruction <?rfc?>
187     exists with contents editing="yes". Can be overriden by an XSLT parameter -->
188
189<xsl:param name="xml2rfc-editing">
190  <xsl:call-template name="parse-pis">
191    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
192    <xsl:with-param name="attr" select="'editing'"/>
193    <xsl:with-param name="default" select="'no'"/>
194  </xsl:call-template>
195</xsl:param>
196
197<!-- make it a private paper -->
198
199<xsl:param name="xml2rfc-private">
200  <xsl:call-template name="parse-pis">
201    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
202    <xsl:with-param name="attr" select="'private'"/>
203  </xsl:call-template>
204</xsl:param>
205
206<!-- background image? -->
207
208<xsl:param name="xml2rfc-background">
209  <xsl:call-template name="parse-pis">
210    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
211    <xsl:with-param name="attr" select="'background'"/>
212  </xsl:call-template>
213</xsl:param>
214
215<!-- extension for XML parsing in artwork -->
216
217<xsl:param name="xml2rfc-ext-parse-xml-in-artwork">
218  <xsl:call-template name="parse-pis">
219    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
220    <xsl:with-param name="attr" select="'parse-xml-in-artwork'"/>
221    <xsl:with-param name="default" select="'no'"/>
222  </xsl:call-template>
223</xsl:param>
224
225<xsl:param name="xml2rfc-ext-trace-parse-xml">
226  <xsl:call-template name="parse-pis">
227    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
228    <xsl:with-param name="attr" select="'trace-parse-xml'"/>
229    <xsl:with-param name="default" select="'no'"/>
230  </xsl:call-template>
231</xsl:param>
232
233<!-- extension for excluding DCMI properties in meta tag (RFC2731) -->
234
235<xsl:param name="xml2rfc-ext-support-rfc2731">
236  <xsl:call-template name="parse-pis">
237    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
238    <xsl:with-param name="attr" select="'support-rfc2731'"/>
239    <xsl:with-param name="default" select="'yes'"/>
240  </xsl:call-template>
241</xsl:param>
242
243<!-- extension for allowing markup inside artwork -->
244
245<xsl:param name="xml2rfc-ext-allow-markup-in-artwork">
246  <xsl:call-template name="parse-pis">
247    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
248    <xsl:with-param name="attr" select="'allow-markup-in-artwork'"/>
249    <xsl:with-param name="default" select="'no'"/>
250  </xsl:call-template>
251</xsl:param>
252
253<!-- extension for including references into index -->
254
255<xsl:param name="xml2rfc-ext-include-references-in-index">
256  <xsl:call-template name="parse-pis">
257    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
258    <xsl:with-param name="attr" select="'include-references-in-index'"/>
259    <xsl:with-param name="default" select="'no'"/>
260  </xsl:call-template>
261</xsl:param>
262
263<!-- position of author's section -->
264
265<xsl:param name="xml2rfc-ext-authors-section">
266  <xsl:call-template name="parse-pis">
267    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
268    <xsl:with-param name="attr" select="'authors-section'"/>
269  </xsl:call-template>
270</xsl:param>
271
272<!-- justification? -->
273
274<xsl:param name="xml2rfc-ext-justification">
275  <xsl:call-template name="parse-pis">
276    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
277    <xsl:with-param name="attr" select="'justification'"/>
278    <xsl:with-param name="default" select="'no'"/>
279  </xsl:call-template>
280</xsl:param>
281
282<!-- switch for doublesided layout -->
283
284<xsl:param name="xml2rfc-ext-duplex">
285  <xsl:call-template name="parse-pis">
286    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
287    <xsl:with-param name="attr" select="'duplex'"/>
288    <xsl:with-param name="default" select="'no'"/>
289  </xsl:call-template>
290</xsl:param>
291
292<!-- experimental support for http://tools.ietf.org/html/draft-iab-streams-headers-boilerplates-08, work in progress -->
293
294<xsl:param name="xml2rfc-ext-hab">
295  <xsl:call-template name="parse-pis">
296    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
297    <xsl:with-param name="attr" select="'h-a-b'"/>
298    <xsl:with-param name="default" select="'no'"/>
299  </xsl:call-template>
300</xsl:param>
301<xsl:param name="xml2rfc-ext-consensus">
302  <xsl:call-template name="parse-pis">
303    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
304    <xsl:with-param name="attr" select="'consensus'"/>
305    <xsl:with-param name="default" select="'yes'"/>
306  </xsl:call-template>
307</xsl:param>
308
309<!-- trailing dots in section numbers -->
310
311<xsl:param name="xml2rfc-ext-sec-no-trailing-dots">
312  <xsl:call-template name="parse-pis">
313    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
314    <xsl:with-param name="attr" select="'sec-no-trailing-dots'"/>
315  </xsl:call-template>
316</xsl:param>
317
318<!-- choose whether or not to do mailto links --> 
319 
320<xsl:param name="xml2rfc-linkmailto">
321  <xsl:call-template name="parse-pis">
322    <xsl:with-param name="nodes" select="/processing-instruction('rfc-ext')"/>
323    <xsl:with-param name="attr" select="'linkmailto'"/>
324    <xsl:with-param name="default" select="'yes'"/>
325  </xsl:call-template>
326</xsl:param>
327
328<!-- iprnotified switch --> 
329 
330<xsl:param name="xml2rfc-iprnotified">
331  <xsl:call-template name="parse-pis">
332    <xsl:with-param name="nodes" select="/processing-instruction('rfc')"/>
333    <xsl:with-param name="attr" select="'iprnotified'"/>
334    <xsl:with-param name="default" select="'no'"/>
335  </xsl:call-template>
336</xsl:param>
337
338<!-- URL templates for RFCs and Internet Drafts. -->
339
340<!-- Reference the authorative ASCII versions
341<xsl:param name="rfcUrlPrefix" select="'http://www.ietf.org/rfc/rfc'" />
342<xsl:param name="rfcUrlPostfix" select="'.txt'" />
343-->
344<!-- Reference the marked up versions over on http://tools.ietf.org/html. -->
345<xsl:param name="rfcUrlPrefix" select="'http://tools.ietf.org/html/rfc'" />
346<xsl:param name="rfcUrlPostfix" select="''" />
347<xsl:param name="rfcUrlFragSection" select="'section-'" />
348<xsl:param name="rfcUrlFragAppendix" select="'appendix-'" />
349<xsl:param name="internetDraftUrlPrefix" select="'http://tools.ietf.org/html/'" />
350<xsl:param name="internetDraftUrlPostfix" select="''" />
351<xsl:param name="internetDraftUrlFrag" select="'section-'" />
352
353<!-- warning re: absent node-set ext. function -->
354<xsl:variable name="node-set-warning">
355  This stylesheet requires either an XSLT-1.0 processor with node-set()
356  extension function, or an XSLT-2.0 processor. Therefore, parts of the
357  document couldn't be displayed.
358</xsl:variable>
359
360<!-- character translation tables -->
361<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
362<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />       
363
364<!-- build help keys for indices -->
365<xsl:key name="index-first-letter"
366  match="iref|reference"
367    use="translate(substring(concat(@anchor,@item),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
368
369<xsl:key name="index-item"
370  match="iref"
371    use="@item" />
372
373<xsl:key name="index-item-subitem"
374  match="iref"
375    use="concat(@item,'..',@subitem)" />
376
377<xsl:key name="index-xref-by-sec"
378  match="xref[@x:sec]"
379    use="concat(@target,'..',@x:sec)" />
380
381<xsl:key name="index-xref-by-anchor"
382  match="xref[@x:rel]"
383    use="concat(@target,'..',@x:rel)" />
384
385<xsl:key name="anchor-item"
386  match="//*[@anchor]"
387    use="@anchor"/>
388
389<xsl:key name="xref-item"
390  match="//xref"
391    use="@target"/>
392
393<xsl:key name="extref-item"
394  match="//x:ref"
395    use="."/>
396
397<!-- prefix for automatically generated anchors -->
398<xsl:variable name="anchor-prefix" select="'rfc'" />
399
400<!-- IPR version switch -->
401<xsl:variable name="ipr-rfc3667" select="(
402  /rfc/@number &gt; 3708) or
403  not(
404    (/rfc/@ipr = 'full2026') or
405    (/rfc/@ipr = 'noDerivativeWorks2026') or
406    (/rfc/@ipr = 'noDerivativeWorksNow') or
407    (/rfc/@ipr = 'none') or
408    (/rfc/@ipr = '') or
409    not(/rfc/@ipr)
410  )" />
411
412<xsl:variable name="rfcno" select="/rfc/@number"/> 
413
414<xsl:variable name="submissionType">
415  <xsl:choose>
416    <xsl:when test="/rfc/@submissionType='IETF' or not(/rfc/@submissionType) or /rfc/submissionType=''">IETF</xsl:when>
417    <xsl:when test="/rfc/@submissionType='IAB' or /rfc/@submissionType='IRTF' or /rfc/@submissionType='independent'">
418      <xsl:value-of select="/rfc/@submissionType"/>
419    </xsl:when>
420    <xsl:otherwise>
421      <xsl:value-of select="concat('(UNSUPPORTED SUBMISSION TYPE: ',/rfc/@submissionType,')')"/>
422      <xsl:call-template name="error">
423        <xsl:with-param name="msg" select="concat('Unsupported value for /rfc/@submissionType: ', /rfc/@submissionType)"/>
424        <xsl:with-param name="inline" select="'no'"/>
425      </xsl:call-template>
426    </xsl:otherwise>
427  </xsl:choose>
428</xsl:variable>
429
430<xsl:variable name="ipr-rfc4748" select="(
431  $ipr-rfc3667 and
432    ( $rfcno &gt;= 4715 and ( $rfcno != 4718 and $rfcno != 4735 and $rfcno != 4749 ))
433    or
434    ( $rfcno=4578 or $rfcno=4582 or $rfcno=4583 or $rfcno=4628 or $rfcno=4629 or $rfcno=4639 or $rfcno=4651 or $rfcno=4682 or $rfcno=4684 or $rfcno=4695 or $rfcno=4696 )
435    or
436    ( not(/rfc/@number) and $pub-yearmonth >= 200611)
437  )" />
438
439<xsl:variable name="ipr-2007-08" select="(
440  $ipr-rfc4748 and
441    (
442      ($rfcno &gt; 5000
443        and $rfcno != 5020
444        and $rfcno != 5021
445        and $rfcno != 5034
446        and $rfcno != 5052
447        and $rfcno != 5065
448        and $rfcno != 5094) or
449      ($xml2rfc-ext-pub-year >= 2008) or
450      (not(/rfc/@number) and $pub-yearmonth >= 200709)
451    )
452  )" />
453
454<xsl:variable name="ipr-2008-11" select="(
455    /rfc/@number and $pub-yearmonth >= 200811
456  )
457  or
458  (
459    /rfc/@ipr = 'trust200811' or
460    /rfc/@ipr = 'noModificationTrust200811' or
461    /rfc/@ipr = 'noDerivativesTrust200902' or
462    /rfc/@ipr = 'trust200902' or
463    /rfc/@ipr = 'noModificationTrust200902' or
464    /rfc/@ipr = 'noDerivativesTrust200902' or
465    /rfc/@ipr = 'pre5378Trust200902'
466  )" />
467
468<xsl:variable name="ipr-2009-02" select="(
469    $ipr-2008-11 and $pub-yearmonth >= 200902
470  )" />
471
472<!-- this makes the Sep 2009 TLP text depend on the publication date to be >= 2009-11
473     for IDs, and around 2009-09 for RFCs-->
474<xsl:variable name="ipr-2009-09" select="(
475    ( not(/rfc/@number) and $pub-yearmonth >= 200911 )
476    or
477    (
478      /rfc/@number and $pub-yearmonth >= 200909 and
479      $rfcno!=5582 and $rfcno!=5621 and $rfcno!=5632 and $rfcno!=5645 and $rfcno!=5646 and $rfcno!=5681
480    )
481  )" />
482
483<!-- see http://mailman.rfc-editor.org/pipermail/rfc-interest/2009-June/001373.html -->
484<!-- for IDs, implement the change as 2009-11 -->
485<xsl:variable name="abstract-first" select="(
486    (/rfc/@number and $pub-yearmonth >= 200907)
487    or
488    (not(/rfc/@number) and $pub-yearmonth >= 200911)
489  )" />
490
491<!-- funding switch --> 
492<xsl:variable name="funding0" select="(
493  $rfcno &gt; 2499) or
494  (not(/rfc/@number) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 1999
495  )" />
496 
497<xsl:variable name="funding1" select="(
498  $rfcno &gt; 4320) or
499  (not(/rfc/@number) and /rfc/@docName and $xml2rfc-ext-pub-year &gt;= 2006
500  )" />
501
502<xsl:variable name="no-funding" select="$ipr-2007-08"/>
503
504<xsl:variable name="no-copylong" select="$ipr-2008-11"/>
505
506<!-- will document have an index -->
507<xsl:variable name="has-index" select="//iref or (//xref and $xml2rfc-ext-include-references-in-index='yes')" />
508         
509<!-- does the document contain edits? -->
510<xsl:variable name="has-edits" select="//ed:ins | //ed:del | //ed:replace" />
511
512<!-- Templates for the various elements of rfc2629.dtd -->
513             
514<xsl:template match="text()[not(ancestor::artwork)]">
515  <xsl:variable name="starts-with-ws" select="translate(substring(.,1,1),'&#9;&#10;&#13;&#32;','')"/>
516  <xsl:variable name="ends-with-ws" select="translate(substring(.,string-length(.),1),'&#9;&#10;&#13;&#32;','')"/>
517  <!--<xsl:message> Orig: "<xsl:value-of select="."/>"</xsl:message>
518  <xsl:message>Start: "<xsl:value-of select="$starts-with-ws"/>"</xsl:message>
519  <xsl:message>  End: "<xsl:value-of select="$ends-with-ws"/>"</xsl:message> -->
520  <xsl:if test="$starts-with-ws='' and preceding-sibling::node()">
521    <xsl:text> </xsl:text>
522  </xsl:if>
523  <xsl:value-of select="normalize-space(.)"/>
524  <xsl:if test="$ends-with-ws='' and following-sibling::node()">
525    <xsl:text> </xsl:text>
526  </xsl:if>
527</xsl:template>
528             
529             
530<xsl:template match="abstract">
531  <h1 id="{$anchor-prefix}.abstract"><a href="#{$anchor-prefix}.abstract">Abstract</a></h1>
532  <xsl:apply-templates />
533</xsl:template>
534
535<msxsl:script language="JScript" implements-prefix="myns">
536  function parseXml(str) {
537    try {
538      var doc = new ActiveXObject("MSXML2.DOMDocument");
539      doc.async = false;
540      if (doc.loadXML(str)) {
541        return "";
542      }
543      else {
544        return doc.parseError.reason + "\n" + doc.parseError.srcText + " (" + doc.parseError.line + "/" + doc.parseError.linepos + ")";
545      }
546    }
547    catch(e) {
548      return "";
549    }
550  }
551</msxsl:script>
552
553<xsl:template name="add-artwork-class">
554  <xsl:choose>
555    <xsl:when test="@type='abnf' or @type='abnf2045' or @type='abnf2616' or @type='application/xml-dtd' or @type='inline' or @type='application/relax-ng-compact-syntax'">
556      <xsl:attribute name="class">inline</xsl:attribute>
557    </xsl:when>
558    <xsl:when test="starts-with(@type,'message/http') and contains(@type,'msgtype=&quot;request&quot;')">
559      <xsl:attribute name="class">text2</xsl:attribute>
560    </xsl:when>
561    <xsl:when test="starts-with(@type,'message/http')">
562      <xsl:attribute name="class">text</xsl:attribute>
563    </xsl:when>
564    <xsl:when test="starts-with(@type,'drawing')">
565      <xsl:attribute name="class">drawing</xsl:attribute>
566    </xsl:when>
567    <xsl:when test="starts-with(@type,'text/plain') or @type='example' or @type='code'">
568      <xsl:attribute name="class">text</xsl:attribute>
569    </xsl:when>
570    <xsl:otherwise/>
571  </xsl:choose>
572</xsl:template>
573
574<xsl:template name="insert-begin-code">
575  <xsl:if test="@x:isCodeComponent='yes'">
576    <pre class="ccmarker cct"><span>&lt;CODE BEGINS></span></pre>
577  </xsl:if>
578</xsl:template>
579
580<xsl:template name="insert-end-code">
581  <xsl:if test="@x:isCodeComponent='yes'">
582    <pre class="ccmarker ccb"><span>&lt;CODE ENDS></span></pre>
583  </xsl:if>
584</xsl:template>
585
586<xsl:template match="artwork">
587  <xsl:if test="not(ancestor::ed:del) and $xml2rfc-ext-parse-xml-in-artwork='yes' and function-available('myns:parseXml')">
588    <xsl:if test="contains(.,'&lt;?xml')">
589      <xsl:variable name="body" select="substring-after(substring-after(.,'&lt;?xml'),'?>')" /> 
590      <xsl:if test="$body!='' and myns:parseXml($body)!=''">
591        <table style="background-color: red; border-width: thin; border-style: solid; border-color: black;">
592        <tr><td>
593        XML PARSE ERROR; parsed the body below:
594        <pre>
595        <xsl:value-of select="$body"/>
596        </pre>
597        resulting in:
598        <pre>
599        <xsl:value-of select="myns:parseXml($body)" />
600        </pre>
601        </td></tr></table>
602      </xsl:if>
603    </xsl:if>
604    <xsl:if test="@ed:parse-xml-after">
605      <xsl:if test="myns:parseXml(string(.))!=''">
606        <table style="background-color: red; border-width: thin; border-style: solid; border-color: black;">
607        <tr><td>
608        XML PARSE ERROR:
609        <pre><xsl:value-of select="myns:parseXml(string(.))" /></pre>
610        </td></tr></table>
611      </xsl:if>
612    </xsl:if>
613  </xsl:if>
614  <xsl:variable name="display">
615    <xsl:choose>
616      <xsl:when test="$xml2rfc-ext-allow-markup-in-artwork='yes'">
617        <xsl:apply-templates/>
618      </xsl:when>
619      <xsl:otherwise>
620        <xsl:value-of select="."/>
621      </xsl:otherwise>
622    </xsl:choose>
623  </xsl:variable> 
624  <xsl:choose>
625    <xsl:when test="@align='right'">
626      <div style="display:table; margin-left: auto; margin-right: 0pt;">
627        <xsl:call-template name="insert-begin-code"/>
628        <pre style="margin-left: 0em;">
629          <xsl:call-template name="add-artwork-class"/>
630          <xsl:call-template name="insertInsDelClass"/>
631          <xsl:copy-of select="$display"/>
632        </pre>         
633        <xsl:call-template name="insert-end-code"/>
634      </div>
635    </xsl:when>
636    <xsl:when test="@align='center'">
637      <div style="display:table; margin-left: auto; margin-right: auto;">
638        <xsl:call-template name="insert-begin-code"/>
639        <pre style="margin-left: 0em;">
640          <xsl:call-template name="add-artwork-class"/>
641          <xsl:call-template name="insertInsDelClass"/>
642          <xsl:copy-of select="$display"/>
643        </pre>         
644        <xsl:call-template name="insert-end-code"/>
645      </div>
646    </xsl:when>
647    <xsl:otherwise>
648      <xsl:call-template name="insert-begin-code"/>
649      <pre>
650        <xsl:call-template name="add-artwork-class"/>
651        <xsl:call-template name="insertInsDelClass"/>
652        <xsl:copy-of select="$display"/>
653      </pre>
654      <xsl:call-template name="insert-end-code"/>
655    </xsl:otherwise>
656  </xsl:choose>
657  <xsl:call-template name="check-artwork-width">
658    <xsl:with-param name="content"><xsl:apply-templates/></xsl:with-param>
659    <xsl:with-param name="indent"><xsl:value-of select="string-length(@x:indent-with)"/></xsl:with-param>
660  </xsl:call-template>
661</xsl:template>
662
663<!-- special case for first text node in artwork -->
664<xsl:template match="artwork/text()[1]">
665  <xsl:choose>
666    <xsl:when test="starts-with(.,'&#10;')">
667      <!-- reduce leading whitespace -->
668      <xsl:value-of select="substring(.,2)"/>
669    </xsl:when>
670    <xsl:otherwise>
671      <xsl:value-of select="."/>
672    </xsl:otherwise>
673  </xsl:choose>
674</xsl:template>
675
676
677<xsl:template name="check-artwork-width">
678  <xsl:param name="content"/>
679  <xsl:param name="indent"/>
680  <xsl:choose>
681    <xsl:when test="not(contains($content,'&#10;'))">
682      <xsl:if test="string-length($content) > 69 + $indent">
683        <xsl:call-template name="warning">
684          <xsl:with-param name="inline" select="'no'"/>
685          <xsl:with-param name="msg">artwork line too long: '<xsl:value-of select="$content"/>' (<xsl:value-of select="string-length($content)"/> characters)</xsl:with-param>
686        </xsl:call-template>
687      </xsl:if>
688    </xsl:when>
689    <xsl:otherwise>
690      <xsl:variable name="start" select="substring-before($content,'&#10;')"/> 
691      <xsl:variable name="end" select="substring-after($content,'&#10;')"/> 
692      <xsl:if test="string-length($start) > 69 + $indent">
693        <xsl:call-template name="warning">
694          <xsl:with-param name="inline" select="'no'"/>
695          <xsl:with-param name="msg">artwork line too long: '<xsl:value-of select="$start"/>' (<xsl:value-of select="string-length($start)"/> characters)</xsl:with-param>
696        </xsl:call-template>
697      </xsl:if>
698      <xsl:call-template name="check-artwork-width">
699        <xsl:with-param name="content" select="$end"/>
700      </xsl:call-template>
701    </xsl:otherwise>
702  </xsl:choose>
703</xsl:template>
704
705<xsl:template match="artwork[@src and starts-with(@type,'image/')]">
706  <p>
707    <xsl:choose>
708      <xsl:when test="@align='center'">
709        <xsl:attribute name="style">text-align: center</xsl:attribute>
710      </xsl:when>
711      <xsl:when test="@align='right'">
712        <xsl:attribute name="style">text-align: right</xsl:attribute>
713      </xsl:when>
714      <xsl:otherwise/>
715    </xsl:choose>
716    <xsl:choose>
717      <xsl:when test="@type='image/svg+xml'">
718        <object data="{@src}" type="image/svg+xml">
719          <xsl:choose>
720            <xsl:when test="@width!='' or @height!=''">
721              <xsl:copy-of select="@width|@height"/>
722            </xsl:when>
723            <xsl:otherwise xmlns:svg="http://www.w3.org/2000/svg">
724              <!-- try to find width and height from SVG -->
725              <xsl:variable name="svg" select="document(@src)"/>
726              <xsl:for-each select="$svg/svg:svg/@width|$svg/svg:svg/@height">
727                <!-- strip out the units, cross the fingers pixels are meant -->
728                <xsl:attribute name="{local-name()}">
729                  <xsl:value-of select="translate(.,concat($ucase,$lcase),'')"/>
730                </xsl:attribute>
731              </xsl:for-each>
732            </xsl:otherwise>
733          </xsl:choose>
734          <xsl:apply-templates/>
735        </object>
736      </xsl:when>
737      <xsl:otherwise>
738        <img src="{@src}" alt="{.}">
739          <xsl:if test="@width and @width!=''">
740            <xsl:copy-of select="@width"/>
741          </xsl:if>
742          <xsl:if test="@height and @height!=''">
743            <xsl:copy-of select="@height"/>
744          </xsl:if>
745        </img>
746      </xsl:otherwise>
747    </xsl:choose>
748  </p>
749</xsl:template>
750
751<xsl:template match="author">
752
753    <address class="vcard">
754      <span class="vcardline">
755        <span class="fn">
756          <xsl:value-of select="@fullname" />
757        </span>
758        <xsl:if test="@role">
759          (<xsl:value-of select="@role" />)
760        </xsl:if>
761        <!-- components of name (hidden from display -->
762        <span class="n hidden">
763          <span class="family-name"><xsl:value-of select="@surname"/></span>
764          <!-- given-name family-name -->
765          <xsl:if test="@surname=substring(@fullname,1 + string-length(@fullname) - string-length(@surname))">
766            <span class="given-name"><xsl:value-of select="normalize-space(substring(@fullname,1,string-length(@fullname) - string-length(@surname)))"/></span>
767          </xsl:if>
768          <!-- family-name given-name -->
769          <xsl:if test="starts-with(@fullname,@surname)">
770            <span class="given-name"><xsl:value-of select="normalize-space(substring-after(@fullname,@surname))"/></span>
771          </xsl:if>
772        </span>
773      </span>
774      <xsl:if test="normalize-space(organization) != ''">
775        <span class="org vcardline">
776          <xsl:value-of select="organization" />
777        </span>
778      </xsl:if>
779      <xsl:if test="address/postal">
780        <span class="adr">
781          <xsl:if test="address/postal/street!=''">
782            <xsl:for-each select="address/postal/street">
783              <span class="street-address vcardline">
784                <xsl:call-template name="extract-normalized">
785                  <xsl:with-param name="node" select="."/>
786                  <xsl:with-param name="name" select="'street'"/>
787                </xsl:call-template>
788              </span>
789            </xsl:for-each>
790          </xsl:if>
791          <xsl:if test="address/postal/city|address/postal/region|address/postal/code">
792            <span class="vcardline">
793              <xsl:if test="address/postal/city">
794                <span class="locality">
795                  <xsl:call-template name="extract-normalized">
796                    <xsl:with-param name="node" select="address/postal/city"/>
797                    <xsl:with-param name="name" select="'address/postal/city'"/>
798                  </xsl:call-template>
799                </span>
800                <xsl:text>, </xsl:text>
801              </xsl:if>
802              <xsl:if test="address/postal/region">
803                <span class="region">
804                  <xsl:call-template name="extract-normalized">
805                    <xsl:with-param name="node" select="address/postal/region"/>
806                    <xsl:with-param name="name" select="'address/postal/region'"/>
807                  </xsl:call-template>
808                </span>
809                <xsl:text>&#160;</xsl:text>
810              </xsl:if>
811              <xsl:if test="address/postal/code">
812                <span class="postal-code">
813                  <xsl:call-template name="extract-normalized">
814                    <xsl:with-param name="node" select="address/postal/code"/>
815                    <xsl:with-param name="name" select="'address/postal/code'"/>
816                  </xsl:call-template>
817                </span>
818              </xsl:if>
819            </span>
820          </xsl:if>
821          <xsl:if test="address/postal/country">
822            <span class="country-name vcardline">
823              <xsl:call-template name="extract-normalized">
824                <xsl:with-param name="node" select="address/postal/country"/>
825                <xsl:with-param name="name" select="'address/postal/country'"/>
826              </xsl:call-template>
827            </span>
828          </xsl:if>
829        </span>
830      </xsl:if>
831      <xsl:if test="address/phone">
832        <span class="vcardline tel">
833          <xsl:text>Phone: </xsl:text>
834          <a href="tel:{translate(address/phone,' ','')}"><span class="value"><xsl:value-of select="address/phone" /></span></a>
835        </span>
836      </xsl:if>
837      <xsl:if test="address/facsimile">
838        <span class="vcardline tel">
839          <span class="type">Fax</span><xsl:text>: </xsl:text>
840          <a href="fax:{translate(address/facsimile,' ','')}"><span class="value"><xsl:value-of select="address/facsimile" /></span></a>
841        </span>
842      </xsl:if>
843      <xsl:for-each select="address/email">
844        <xsl:variable name="email">
845          <xsl:call-template name="extract-email"/>
846        </xsl:variable>
847       
848        <span class="vcardline">
849          <xsl:choose>
850            <xsl:when test="$xml2rfc-rfcedstyle='yes'">Email: </xsl:when>
851            <xsl:otherwise>EMail: </xsl:otherwise>
852          </xsl:choose>
853          <a>
854            <xsl:if test="$xml2rfc-linkmailto!='no'">
855              <xsl:attribute name="href">mailto:<xsl:value-of select="$email" /></xsl:attribute>
856            </xsl:if>
857            <span class="email"><xsl:value-of select="$email" /></span>
858          </a>
859        </span>
860      </xsl:for-each>
861      <xsl:for-each select="address/uri">
862        <xsl:variable name="uri">
863          <xsl:call-template name="extract-uri"/>
864        </xsl:variable>
865
866        <span class="vcardline">
867          <xsl:text>URI: </xsl:text>
868          <a href="{$uri}" class="url"><xsl:value-of select="$uri" /></a>
869        </span>
870      </xsl:for-each>
871    </address>
872
873</xsl:template>
874
875<xsl:template match="back">
876
877  <!-- add editorial comments -->
878  <xsl:if test="//cref and $xml2rfc-comments='yes' and $xml2rfc-inline!='yes'">
879    <xsl:call-template name="insertComments" />
880  </xsl:if>
881 
882  <!-- next, add information about the document's authors -->
883  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
884    <xsl:call-template name="insertAuthors" />
885  </xsl:if>
886     
887  <!-- add all other top-level sections under <back> -->
888  <xsl:apply-templates select="*[not(self::references) and not(self::ed:replace and .//references)]" />
889
890  <!-- insert the index if index entries exist -->
891  <!-- note it always comes before the authors section -->
892  <xsl:if test="$has-index">
893    <xsl:call-template name="insertIndex" />
894  </xsl:if>
895
896  <!-- Authors section is the absolute last thing, except for copyright stuff -->
897  <xsl:if test="$xml2rfc-ext-authors-section='end'">
898    <xsl:call-template name="insertAuthors" />
899  </xsl:if>
900
901  <xsl:if test="$xml2rfc-private=''">
902    <!-- copyright statements -->
903    <xsl:variable name="copyright"><xsl:call-template name="insertCopyright" /></xsl:variable>
904 
905    <!-- emit it -->
906    <xsl:choose>
907      <xsl:when test="function-available('exslt:node-set')">
908        <xsl:apply-templates select="exslt:node-set($copyright)" />
909      </xsl:when>
910      <xsl:otherwise>
911        <xsl:call-template name="error">
912          <xsl:with-param name="msg" select="$node-set-warning"/>
913        </xsl:call-template>
914      </xsl:otherwise>
915    </xsl:choose>
916  </xsl:if>
917 
918</xsl:template>
919
920<xsl:template match="eref[node()]">
921  <a href="{@target}"><xsl:apply-templates /></a>
922</xsl:template>
923               
924<xsl:template match="eref[not(node())]">
925  <xsl:text>&lt;</xsl:text>
926  <a href="{@target}"><xsl:value-of select="@target" /></a>
927  <xsl:text>&gt;</xsl:text>
928</xsl:template>
929
930<xsl:template match="figure">
931  <xsl:if test="@anchor!=''">
932    <xsl:call-template name="check-anchor"/>
933    <div id="{@anchor}"/>
934  </xsl:if>
935  <xsl:variable name="anch">
936    <xsl:call-template name="get-figure-anchor"/>
937  </xsl:variable>
938  <div id="{$anch}" />
939  <xsl:apply-templates />
940  <xsl:if test="(@title!='' or @anchor!='') and not(@suppress-title='true')">
941    <xsl:variable name="n"><xsl:number level="any" count="figure[(@title!='' or @anchor!='') and not(@suppress-title='true')]" /></xsl:variable>
942    <p class="figure">Figure <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title" /></xsl:if></p>
943  </xsl:if>
944</xsl:template>
945
946<xsl:template match="front">
947 
948  <xsl:if test="$xml2rfc-topblock!='no'">
949    <!-- collect information for left column -->
950     
951    <xsl:variable name="leftColumn">
952      <xsl:call-template name="collectLeftHeaderColumn" />   
953    </xsl:variable>
954 
955    <!-- collect information for right column -->
956     
957    <xsl:variable name="rightColumn">
958      <xsl:call-template name="collectRightHeaderColumn" />   
959    </xsl:variable>
960     
961    <!-- insert the collected information -->
962    <table class="header">
963      <xsl:choose>
964        <xsl:when test="function-available('exslt:node-set')">
965          <xsl:call-template name="emitheader">
966            <xsl:with-param name="lc" select="exslt:node-set($leftColumn)" />   
967            <xsl:with-param name="rc" select="exslt:node-set($rightColumn)" />   
968          </xsl:call-template>
969        </xsl:when>   
970        <xsl:otherwise>
971          <xsl:call-template name="error">
972            <xsl:with-param name="msg" select="$node-set-warning"/>
973          </xsl:call-template>
974        </xsl:otherwise>
975      </xsl:choose>
976    </table>
977  </xsl:if>
978   
979  <p class="title">
980    <!-- main title -->
981
982    <xsl:apply-templates select="title"/>
983    <xsl:if test="/rfc/@docName">
984      <br/>
985      <span class="filename"><xsl:value-of select="/rfc/@docName"/></span>
986     
987      <xsl:if test="contains(/rfc/@docName,'.')">
988        <xsl:call-template name="warning">
989          <xsl:with-param name="msg">The @docName attribute should contain the base name, not the filename (thus no file extension).</xsl:with-param>
990        </xsl:call-template>
991      </xsl:if>
992    </xsl:if> 
993  </p>
994 
995  <!-- insert notice about update -->
996  <xsl:variable name="published-as" select="/*/x:link[@rel='Alternate' and starts-with(@title,'RFC')]"/>
997  <xsl:if test="$published-as">
998    <p style="color: green; text-align: center; font-size: 14pt; background-color: yellow;">
999      <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>.
1000    </p>
1001  </xsl:if>
1002   
1003  <!-- check for conforming ipr attribute -->
1004  <xsl:choose>
1005    <xsl:when test="not(/rfc/@ipr)" />
1006    <xsl:when test="/rfc/@ipr = 'full2026'" />
1007    <xsl:when test="/rfc/@ipr = 'noDerivativeWorks'" />
1008    <xsl:when test="/rfc/@ipr = 'noDerivativeWorksNow'" />
1009    <xsl:when test="/rfc/@ipr = 'none'" />
1010    <xsl:when test="/rfc/@ipr = 'full3667'" />
1011    <xsl:when test="/rfc/@ipr = 'noModification3667'" />
1012    <xsl:when test="/rfc/@ipr = 'noDerivatives3667'" />
1013    <xsl:when test="/rfc/@ipr = 'full3978'" />
1014    <xsl:when test="/rfc/@ipr = 'noModification3978'" />
1015    <xsl:when test="/rfc/@ipr = 'noDerivatives3978'" />
1016    <xsl:when test="/rfc/@ipr = 'trust200811'" />
1017    <xsl:when test="/rfc/@ipr = 'noModificationTrust200811'" />
1018    <xsl:when test="/rfc/@ipr = 'noDerivativesTrust200811'" />
1019    <xsl:when test="/rfc/@ipr = 'trust200902'" />
1020    <xsl:when test="/rfc/@ipr = 'noModificationTrust200902'" />
1021    <xsl:when test="/rfc/@ipr = 'noDerivativesTrust200902'" />
1022    <xsl:when test="/rfc/@ipr = 'pre5378Trust200902'" />
1023    <xsl:otherwise>
1024      <xsl:call-template name="error">
1025        <xsl:with-param name="msg" select="concat('Unknown value for /rfc/@ipr: ', /rfc/@ipr)"/>
1026      </xsl:call-template>
1027    </xsl:otherwise>       
1028  </xsl:choose>           
1029
1030  <xsl:if test="$xml2rfc-private='' and not($abstract-first)">
1031    <xsl:call-template name="emit-ietf-preamble"/>
1032  </xsl:if>
1033 
1034  <xsl:apply-templates select="x:boilerplate"/>
1035  <xsl:apply-templates select="abstract" />
1036  <xsl:apply-templates select="note" />
1037  <!-- show notes inside change tracking as well -->
1038  <xsl:apply-templates select="ed:replace[.//note]" />
1039   
1040  <xsl:if test="$xml2rfc-private='' and $abstract-first">
1041    <xsl:call-template name="emit-ietf-preamble"/>
1042  </xsl:if>
1043
1044  <xsl:if test="$xml2rfc-toc='yes'">
1045    <xsl:apply-templates select="/" mode="toc" />
1046    <xsl:call-template name="insertTocAppendix" />
1047  </xsl:if>
1048
1049</xsl:template>
1050
1051<xsl:template name="emit-ietf-preamble">
1052  <!-- Get status info formatted as per RFC2629-->
1053  <xsl:variable name="preamble">
1054    <xsl:call-template name="insertPreamble" />
1055  </xsl:variable>
1056 
1057  <!-- emit it -->
1058  <xsl:choose>
1059    <xsl:when test="function-available('exslt:node-set')">
1060      <xsl:apply-templates select="exslt:node-set($preamble)" />
1061    </xsl:when>
1062    <xsl:otherwise>
1063      <xsl:call-template name="error">
1064        <xsl:with-param name="msg" select="$node-set-warning"/>
1065      </xsl:call-template>
1066    </xsl:otherwise>
1067  </xsl:choose>
1068</xsl:template>
1069
1070<xsl:template match="iref">
1071  <xsl:variable name="anchor"><xsl:call-template name="compute-iref-anchor"/></xsl:variable>
1072  <xsl:choose>
1073    <xsl:when test="parent::figure">
1074      <div id="{$anchor}"/>
1075    </xsl:when>
1076    <xsl:when test="ancestor::t or ancestor::artwork or ancestor::preamble or ancestor::postamble">
1077      <span id="{$anchor}"/>
1078    </xsl:when>
1079    <xsl:otherwise>
1080      <div id="{$anchor}"/>
1081    </xsl:otherwise>
1082  </xsl:choose>
1083</xsl:template>
1084
1085<xsl:template name="compute-iref-anchor">
1086  <xsl:variable name="first" select="translate(substring(@item,1,1),$ucase,$lcase)"/>
1087  <xsl:variable name="nkey" select="translate($first,$lcase,'')"/>
1088  <xsl:choose>
1089    <xsl:when test="$nkey=''">
1090      <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)]"/>
1091    </xsl:when>
1092    <xsl:otherwise>
1093      <xsl:value-of select="$anchor-prefix"/>.iref.<xsl:number level="any" count="iref[translate(substring(@item,1,1),concat($lcase,$ucase),'')='']"/>
1094    </xsl:otherwise>
1095  </xsl:choose>
1096</xsl:template>
1097
1098<xsl:template name="compute-extref-anchor">
1099  <xsl:variable name="first" select="translate(substring(.,1,1),$ucase,$lcase)"/>
1100  <xsl:variable name="nkey" select="translate($first,$lcase,'')"/>
1101  <xsl:choose>
1102    <xsl:when test="$nkey=''">
1103      <xsl:value-of select="$anchor-prefix"/>.extref.<xsl:value-of select="$first"/>.<xsl:number level="any" count="x:ref[starts-with(translate(.,$ucase,$lcase),$first)]"/>
1104    </xsl:when>
1105    <xsl:otherwise>
1106      <xsl:value-of select="$anchor-prefix"/>.extref.<xsl:number level="any" count="x:ref[translate(substring(.,1,1),concat($lcase,$ucase),'')='']"/>
1107    </xsl:otherwise>
1108  </xsl:choose>
1109</xsl:template>
1110
1111<!-- list templates depend on the list style -->
1112
1113<xsl:template match="list[@style='empty' or not(@style)]">
1114  <ul class="empty">
1115    <xsl:call-template name="insertInsDelClass"/>
1116    <xsl:apply-templates />
1117  </ul>
1118</xsl:template>
1119
1120<xsl:template match="list[starts-with(@style,'format ')]">
1121  <dl>
1122    <xsl:call-template name="insertInsDelClass"/>
1123    <xsl:apply-templates />
1124  </dl>
1125</xsl:template>
1126
1127<xsl:template match="list[@style='hanging']">
1128  <dl>
1129    <xsl:call-template name="insertInsDelClass"/>
1130    <xsl:apply-templates />
1131  </dl>
1132</xsl:template>
1133
1134<xsl:template match="list[@style='numbers']">
1135  <ol>
1136    <xsl:call-template name="insertInsDelClass"/>
1137    <xsl:apply-templates />
1138  </ol>
1139</xsl:template>
1140
1141<!-- numbered list inside numbered list -->
1142<xsl:template match="list[@style='numbers']/t/list[@style='numbers']" priority="9">
1143  <ol style="list-style-type: lower-alpha">
1144    <xsl:call-template name="insertInsDelClass"/>
1145    <xsl:apply-templates />
1146  </ol>
1147</xsl:template>
1148
1149<xsl:template match="list[@style='letters']">
1150  <ol style="list-style-type: lower-alpha">
1151    <xsl:call-template name="insertInsDelClass"/>
1152    <xsl:apply-templates />
1153  </ol>
1154</xsl:template>
1155
1156<!-- nested lettered list uses uppercase -->
1157<xsl:template match="list//t//list[@style='letters']" priority="9">
1158  <ol style="list-style-type: upper-alpha">
1159    <xsl:call-template name="insertInsDelClass"/>
1160    <xsl:apply-templates />
1161  </ol>
1162</xsl:template>
1163   
1164<xsl:template match="list[@style='symbols']">
1165  <ul>
1166    <xsl:call-template name="insertInsDelClass"/>
1167    <xsl:apply-templates />
1168  </ul>
1169</xsl:template>
1170
1171
1172<!-- same for t(ext) elements -->
1173
1174<xsl:template match="list[@style='empty' or not(@style)]/t | list[@style='empty' or not(@style)]/ed:replace/ed:*/t">
1175  <!-- Inherited through CSS now <dd style="margin-top: .5em">-->
1176  <li>
1177    <xsl:call-template name="copy-anchor"/>
1178    <xsl:call-template name="insertInsDelClass"/>
1179    <xsl:apply-templates />
1180  </li>
1181</xsl:template>
1182
1183<xsl:template match="list[@style='numbers' or @style='symbols' or @style='letters']/x:lt">
1184  <li>
1185    <xsl:call-template name="copy-anchor"/>
1186    <xsl:apply-templates select="t" />
1187  </li>
1188</xsl:template>
1189
1190<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">
1191  <li>
1192    <xsl:call-template name="copy-anchor"/>
1193    <xsl:call-template name="insertInsDelClass"/>
1194    <xsl:for-each select="../..">
1195      <xsl:call-template name="insert-issue-pointer"/>
1196    </xsl:for-each>
1197    <xsl:apply-templates />
1198  </li>
1199</xsl:template>
1200
1201<xsl:template match="list[@style='hanging']/x:lt">
1202  <xsl:if test="@hangText!=''">
1203    <dt>
1204      <xsl:call-template name="copy-anchor"/>
1205      <xsl:call-template name="insertInsDelClass"/>
1206      <xsl:variable name="del-node" select="ancestor::ed:del"/>
1207      <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
1208      <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
1209      <xsl:for-each select="../..">
1210        <xsl:call-template name="insert-issue-pointer">
1211          <xsl:with-param name="deleted-anchor" select="$deleted"/>
1212        </xsl:call-template>
1213      </xsl:for-each>
1214      <xsl:value-of select="@hangText" />
1215    </dt>
1216  </xsl:if>
1217  <dd>
1218    <xsl:call-template name="insertInsDelClass"/>
1219    <!-- if hangIndent present, use 0.7 of the specified value (1em is the width of the "m" character -->
1220    <xsl:if test="../@hangIndent and ../@hangIndent!='0'">
1221      <xsl:attribute name="style">margin-left: <xsl:value-of select="../@hangIndent * 0.7"/>em</xsl:attribute>
1222    </xsl:if>
1223    <xsl:apply-templates select="t" />
1224  </dd>
1225</xsl:template>
1226
1227<xsl:template match="list[@style='hanging']/t | list[@style='hanging']/ed:replace/ed:*/t">
1228  <xsl:if test="@hangText!=''">
1229    <dt>
1230      <xsl:call-template name="copy-anchor"/>
1231      <xsl:call-template name="insertInsDelClass"/>
1232      <xsl:if test="count(preceding-sibling::t)=0">
1233        <xsl:variable name="del-node" select="ancestor::ed:del"/>
1234        <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
1235        <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
1236        <xsl:for-each select="../..">
1237          <xsl:call-template name="insert-issue-pointer">
1238            <xsl:with-param name="deleted-anchor" select="$deleted"/>
1239          </xsl:call-template>
1240        </xsl:for-each>
1241      </xsl:if>
1242      <xsl:value-of select="@hangText" />
1243    </dt>
1244  </xsl:if>
1245
1246  <xsl:variable name="dd-content">
1247    <xsl:apply-templates/>
1248  </xsl:variable>
1249
1250  <xsl:if test="$dd-content!=''">
1251    <dd>
1252      <xsl:call-template name="insertInsDelClass"/>
1253      <!-- if hangIndent present, use 0.7 of the specified value (1em is the width of the "m" character -->
1254      <xsl:if test="../@hangIndent and ../@hangIndent!='0'">
1255        <xsl:attribute name="style">margin-left: <xsl:value-of select="../@hangIndent * 0.7"/>em</xsl:attribute>
1256      </xsl:if>
1257      <xsl:apply-templates />
1258    </dd>
1259  </xsl:if>
1260</xsl:template>
1261
1262<xsl:template match="list[starts-with(@style,'format ') and (contains(@style,'%c') or contains(@style,'%d'))]/t">
1263  <xsl:variable name="list" select=".." />
1264  <xsl:variable name="format" select="substring-after(../@style,'format ')" />
1265  <xsl:variable name="pos">
1266    <xsl:choose>
1267      <xsl:when test="$list/@counter">
1268        <xsl:number level="any" count="list[@counter=$list/@counter or (not(@counter) and @style=concat('format ',$list/@counter))]/t" />
1269      </xsl:when>
1270      <xsl:otherwise>
1271        <xsl:number level="any" count="list[concat('format ',@counter)=$list/@style or (not(@counter) and @style=$list/@style)]/t" />
1272      </xsl:otherwise>
1273    </xsl:choose>
1274  </xsl:variable>
1275  <dt>
1276    <xsl:call-template name="copy-anchor"/>
1277    <xsl:choose>
1278      <xsl:when test="contains($format,'%c')">
1279        <xsl:value-of select="substring-before($format,'%c')"/><xsl:number value="$pos" format="a" /><xsl:value-of select="substring-after($format,'%c')"/>
1280      </xsl:when>
1281      <xsl:otherwise>
1282        <xsl:value-of select="substring-before($format,'%d')"/><xsl:number value="$pos" format="1" /><xsl:value-of select="substring-after($format,'%d')"/>
1283      </xsl:otherwise>
1284    </xsl:choose>
1285  </dt>
1286  <dd>
1287    <xsl:apply-templates />
1288  </dd>
1289</xsl:template>
1290
1291<xsl:template match="middle">
1292  <xsl:apply-templates />
1293  <xsl:apply-templates select="../back//references"/>
1294</xsl:template>
1295
1296<xsl:template match="note">
1297  <xsl:variable name="num"><xsl:number/></xsl:variable>
1298    <h1 id="{$anchor-prefix}.note.{$num}">
1299      <xsl:call-template name="insertInsDelClass"/>
1300      <a href="#{$anchor-prefix}.note.{$num}">
1301        <xsl:value-of select="@title" />
1302      </a>
1303    </h1>
1304  <xsl:apply-templates />
1305</xsl:template>
1306
1307<xsl:template match="postamble">
1308  <xsl:if test="normalize-space(.) != ''">
1309    <p>
1310      <xsl:call-template name="insertInsDelClass"/>
1311      <xsl:call-template name="editingMark" />
1312      <xsl:apply-templates />
1313    </p>
1314  </xsl:if>
1315</xsl:template>
1316
1317<xsl:template match="preamble">
1318  <xsl:if test="normalize-space(.) != ''">
1319    <p>
1320      <xsl:call-template name="copy-anchor"/>
1321      <xsl:call-template name="insertInsDelClass"/>
1322      <xsl:call-template name="editingMark" />
1323      <xsl:apply-templates />
1324    </p>
1325  </xsl:if>
1326</xsl:template>
1327
1328<xsl:template name="computed-auto-target">
1329  <xsl:param name="bib"/>
1330  <xsl:param name="ref"/>
1331
1332  <xsl:choose>
1333    <xsl:when test="$ref and $bib/x:source/@href and $bib/x:source/@basename and $ref/@x:rel">
1334      <xsl:value-of select="concat($bib/x:source/@basename,'.html',$ref/@x:rel)" />
1335    </xsl:when>
1336    <xsl:when test="$bib/seriesInfo/@name='RFC'">
1337      <xsl:variable name="sec">
1338        <xsl:choose>
1339          <xsl:when test="$ref and starts-with($ref/@x:rel,'#') and not($ref/@x:sec)">
1340            <xsl:variable name="extdoc" select="document($bib/x:source/@href)"/>
1341            <xsl:for-each select="$extdoc//*[@anchor=substring-after($ref/@x:rel,'#')]">
1342              <xsl:call-template name="get-section-number"/>
1343            </xsl:for-each>
1344          </xsl:when>
1345          <xsl:when test="$ref">
1346            <xsl:value-of select="$ref/@x:sec"/>
1347          </xsl:when>
1348          <xsl:otherwise/>
1349        </xsl:choose>
1350      </xsl:variable>
1351      <xsl:value-of select="concat($rfcUrlPrefix,$bib/seriesInfo[@name='RFC']/@value,$rfcUrlPostfix)" />
1352      <xsl:if test="$ref and $sec!='' and $rfcUrlFragSection and $rfcUrlFragAppendix">
1353        <xsl:choose>
1354          <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
1355            <xsl:value-of select="concat('#',$rfcUrlFragAppendix,$sec)"/>
1356          </xsl:when>
1357          <xsl:otherwise>
1358            <xsl:value-of select="concat('#',$rfcUrlFragSection,$sec)"/>
1359          </xsl:otherwise>
1360        </xsl:choose>
1361      </xsl:if>
1362    </xsl:when>
1363    <xsl:when test="$bib/seriesInfo/@name='Internet-Draft'">
1364      <xsl:value-of select="concat($internetDraftUrlPrefix,$bib/seriesInfo[@name='Internet-Draft']/@value,$internetDraftUrlPostfix)" />
1365      <xsl:if test="$ref and $ref/@x:sec and $internetDraftUrlFrag">
1366        <xsl:value-of select="concat('#',$internetDraftUrlFrag,$ref/@x:sec)"/>
1367      </xsl:if>
1368    </xsl:when>
1369    <xsl:otherwise />
1370  </xsl:choose> 
1371 
1372</xsl:template>
1373
1374<xsl:template name="computed-target">
1375  <xsl:param name="bib"/>
1376  <xsl:param name="ref"/>
1377
1378  <xsl:choose>
1379    <xsl:when test="$bib/@target">
1380      <xsl:if test="$ref and $ref/@x:sec and $ref/@x:rel">
1381        <xsl:value-of select="concat($bib/@target,$ref/@x:rel)"/>
1382      </xsl:if>
1383    </xsl:when>
1384    <xsl:otherwise>
1385      <xsl:call-template name="computed-auto-target">
1386        <xsl:with-param name="bib" select="$bib"/>
1387        <xsl:with-param name="ref" select="$ref"/>
1388      </xsl:call-template>
1389    </xsl:otherwise>
1390  </xsl:choose> 
1391 
1392</xsl:template>
1393
1394<xsl:template match="reference">
1395
1396  <!-- check for reference to reference -->
1397  <xsl:variable name="anchor" select="@anchor"/>
1398  <xsl:if test="not(ancestor::ed:del) and not(key('xref-item',$anchor))">
1399    <xsl:call-template name="warning">
1400      <xsl:with-param name="inline" select="'no'"/>
1401      <xsl:with-param name="msg">unused reference '<xsl:value-of select="@anchor"/>'</xsl:with-param>
1402    </xsl:call-template>
1403  </xsl:if>
1404
1405  <xsl:call-template name="check-anchor"/>
1406
1407  <xsl:variable name="target">
1408    <xsl:choose>
1409      <xsl:when test="@target"><xsl:value-of select="@target" /></xsl:when>
1410      <xsl:otherwise>
1411        <xsl:call-template name="computed-auto-target">
1412          <xsl:with-param name="bib" select="."/>
1413        </xsl:call-template>
1414      </xsl:otherwise>
1415    </xsl:choose>
1416  </xsl:variable>
1417 
1418  <tr>
1419    <td class="reference">
1420      <xsl:call-template name="insertInsDelClass"/>
1421      <xsl:variable name="del-node" select="ancestor::ed:del"/>
1422      <xsl:variable name="rep-node" select="ancestor::ed:replace"/>
1423      <xsl:variable name="deleted" select="$del-node and ($rep-node/ed:ins)"/>
1424      <xsl:for-each select="../..">
1425        <xsl:call-template name="insert-issue-pointer">
1426          <xsl:with-param name="deleted-anchor" select="$deleted"/>
1427        </xsl:call-template>
1428      </xsl:for-each>
1429      <b id="{@anchor}">
1430        <xsl:call-template name="referencename">
1431          <xsl:with-param name="node" select="." />
1432        </xsl:call-template>
1433      </b>
1434    </td>
1435   
1436    <td class="top">
1437      <xsl:call-template name="insertInsDelClass"/>
1438      <xsl:for-each select="front/author">
1439        <xsl:variable name="initials">
1440          <xsl:call-template name="format-initials"/>
1441        </xsl:variable>
1442     
1443        <xsl:choose>
1444          <xsl:when test="@surname and @surname!=''">
1445            <xsl:variable name="displayname">
1446              <!-- surname/initials is reversed for last author except when it's the only one -->
1447              <xsl:choose>
1448                <xsl:when test="position()=last() and position()!=1">
1449                  <xsl:value-of select="concat($initials,' ',@surname)" />
1450                </xsl:when>
1451                <xsl:otherwise>
1452                  <xsl:value-of select="concat(@surname,', ',$initials)" />
1453                </xsl:otherwise>
1454              </xsl:choose>
1455              <xsl:if test="@role='editor'">
1456                <xsl:text>, Ed.</xsl:text>
1457              </xsl:if>
1458            </xsl:variable>
1459            <xsl:choose>
1460              <xsl:when test="address/email">
1461                <a>
1462                  <xsl:if test="$xml2rfc-linkmailto!='no'">
1463                    <xsl:attribute name="href">mailto:<xsl:value-of select="address/email" /></xsl:attribute>
1464                  </xsl:if>
1465                  <xsl:if test="organization/text()">
1466                    <xsl:attribute name="title"><xsl:value-of select="organization/text()"/></xsl:attribute>
1467                  </xsl:if>
1468                  <xsl:value-of select="$displayname" />
1469                </a>
1470              </xsl:when>
1471              <xsl:otherwise>
1472                <xsl:value-of select="$displayname" />
1473              </xsl:otherwise>
1474            </xsl:choose>
1475           
1476            <xsl:choose>
1477              <xsl:when test="position()=last() - 1">
1478                <xsl:if test="last() &gt; 2">,</xsl:if>
1479                <xsl:text> and </xsl:text>
1480              </xsl:when>
1481              <xsl:otherwise>
1482                <xsl:text>, </xsl:text>
1483              </xsl:otherwise>
1484            </xsl:choose>
1485          </xsl:when>
1486          <xsl:when test="organization/text()">
1487            <xsl:choose>
1488              <xsl:when test="address/uri">
1489                <a href="{address/uri}"><xsl:value-of select="organization" /></a>
1490              </xsl:when>
1491              <xsl:otherwise>
1492                <xsl:value-of select="organization" />
1493              </xsl:otherwise>
1494            </xsl:choose>
1495           
1496            <xsl:choose>
1497              <xsl:when test="position()=last() - 1">
1498                <xsl:if test="last() &gt; 2">,</xsl:if>
1499                <xsl:text> and </xsl:text>
1500              </xsl:when>
1501              <xsl:otherwise>
1502                <xsl:text>, </xsl:text>
1503              </xsl:otherwise>
1504            </xsl:choose>
1505          </xsl:when>
1506          <xsl:otherwise />
1507        </xsl:choose>
1508      </xsl:for-each>
1509         
1510      <xsl:choose>
1511        <xsl:when test="string-length($target) &gt; 0">
1512          <xsl:text>&#8220;</xsl:text>
1513          <a href="{$target}"><xsl:value-of select="normalize-space(front/title)" /></a>
1514          <xsl:text>&#8221;</xsl:text>
1515        </xsl:when>
1516        <xsl:otherwise>
1517          <xsl:text>&#8220;</xsl:text>
1518          <xsl:value-of select="normalize-space(front/title)" />
1519          <xsl:text>&#8221;</xsl:text>
1520        </xsl:otherwise>
1521      </xsl:choose>
1522           
1523      <xsl:for-each select="seriesInfo">
1524        <xsl:text>, </xsl:text>
1525        <xsl:choose>
1526          <xsl:when test="not(@name) and not(@value) and ./text()"><xsl:value-of select="." /></xsl:when>
1527          <xsl:otherwise>
1528            <xsl:value-of select="@name" />
1529            <xsl:if test="@value!=''">&#0160;<xsl:value-of select="@value" /></xsl:if>
1530            <xsl:if test="translate(@name,$ucase,$lcase)='internet-draft'"> (work in progress)</xsl:if>
1531          </xsl:otherwise>
1532        </xsl:choose>
1533      </xsl:for-each>
1534     
1535      <xsl:if test="front/date/@year != ''">
1536        <xsl:if test="string(number(front/date/@year)) = 'NaN'">
1537          <xsl:call-template name="warning">
1538            <xsl:with-param name="inline" select="'no'"/>
1539            <xsl:with-param name="msg">date/@year should be a number: '<xsl:value-of select="front/date/@year"/>' in reference '<xsl:value-of select="@anchor"/>'</xsl:with-param>
1540          </xsl:call-template>
1541        </xsl:if>
1542        <xsl:text>, </xsl:text>
1543        <xsl:if test="front/date/@month!=''"><xsl:value-of select="front/date/@month" />&#0160;</xsl:if>
1544        <xsl:value-of select="front/date/@year" />
1545      </xsl:if>
1546     
1547      <xsl:if test="@target">
1548        <xsl:text>, &lt;</xsl:text>
1549        <a href="{@target}"><xsl:value-of select="@target"/></a>
1550        <xsl:text>&gt;</xsl:text>
1551      </xsl:if>
1552     
1553      <xsl:text>.</xsl:text>
1554
1555      <xsl:for-each select="annotation">
1556        <br />
1557        <xsl:apply-templates />
1558      </xsl:for-each>
1559
1560    </td>
1561  </tr>
1562 
1563 
1564</xsl:template>
1565
1566
1567<xsl:template match="references">
1568
1569  <xsl:variable name="name">
1570    <xsl:if test="ancestor::ed:del">
1571      <xsl:text>del-</xsl:text>
1572    </xsl:if>
1573    <xsl:number level="any"/>     
1574  </xsl:variable>
1575 
1576  <xsl:variable name="refseccount" select="count(/rfc/back/references)+count(/rfc/back/ed:replace/ed:ins/references)"/>
1577
1578  <!-- insert pseudo section when needed -->
1579  <xsl:if test="not(preceding::references) and $refseccount!=1">
1580    <xsl:call-template name="insert-conditional-hrule"/>
1581    <h1 id="{$anchor-prefix}.references">
1582      <xsl:call-template name="insert-conditional-pagebreak"/>
1583      <xsl:variable name="sectionNumber">
1584        <xsl:call-template name="get-references-section-number"/>
1585      </xsl:variable>
1586      <a id="{$anchor-prefix}.section.{$sectionNumber}" href="#{$anchor-prefix}.section.{$sectionNumber}">
1587        <xsl:call-template name="emit-section-number">
1588          <xsl:with-param name="no" select="$sectionNumber"/>
1589        </xsl:call-template>
1590      </a>
1591      <xsl:text> </xsl:text>
1592      <xsl:value-of select="$xml2rfc-refparent"/>
1593    </h1>
1594  </xsl:if>
1595 
1596  <xsl:variable name="elemtype">
1597    <xsl:choose>
1598      <xsl:when test="$refseccount!=1">h2</xsl:when>
1599      <xsl:otherwise>h1</xsl:otherwise>
1600    </xsl:choose>
1601  </xsl:variable>
1602 
1603  <xsl:variable name="title">
1604    <xsl:choose>
1605      <xsl:when test="not(@title) or @title=''"><xsl:value-of select="$xml2rfc-refparent"/></xsl:when>
1606      <xsl:otherwise><xsl:value-of select="@title"/></xsl:otherwise>
1607    </xsl:choose>
1608  </xsl:variable>
1609 
1610  <xsl:element name="{$elemtype}"> 
1611    <xsl:if test="$name='1'">
1612      <xsl:call-template name="insert-conditional-pagebreak"/>
1613    </xsl:if>
1614    <xsl:variable name="sectionNumber">
1615      <xsl:call-template name="get-section-number"/>
1616    </xsl:variable>
1617    <xsl:variable name="anchorpref">
1618      <xsl:choose>
1619        <xsl:when test="$elemtype='h1'"></xsl:when>
1620        <xsl:otherwise>.<xsl:value-of select="$name"/></xsl:otherwise>
1621      </xsl:choose>
1622    </xsl:variable>
1623    <xsl:attribute name="id"><xsl:value-of select="concat($anchor-prefix,'.references',$anchorpref)"/></xsl:attribute>
1624    <a href="#{$anchor-prefix}.section.{$sectionNumber}" id="{$anchor-prefix}.section.{$sectionNumber}">
1625      <xsl:call-template name="emit-section-number">
1626        <xsl:with-param name="no" select="$sectionNumber"/>
1627      </xsl:call-template>
1628    </a>
1629    <xsl:text> </xsl:text>
1630    <xsl:value-of select="$title"/>
1631  </xsl:element>
1632 
1633  <table>
1634    <xsl:choose>
1635      <xsl:when test="$xml2rfc-sortrefs='yes' and $xml2rfc-symrefs!='no'">
1636        <xsl:apply-templates>
1637          <xsl:sort select="@anchor|.//ed:ins//reference/@anchor" />
1638        </xsl:apply-templates>
1639      </xsl:when>
1640      <xsl:otherwise>
1641        <xsl:apply-templates />
1642      </xsl:otherwise>
1643    </xsl:choose>
1644  </table>
1645
1646</xsl:template>
1647
1648<xsl:template match="rfc">
1649 
1650  <xsl:variable name="ignored">
1651    <xsl:call-template name="parse-pis">
1652      <xsl:with-param name="nodes" select="//processing-instruction('rfc-ext')"/>
1653      <xsl:with-param name="attr" select="'SANITYCHECK'"/>
1654    </xsl:call-template>
1655    <xsl:call-template name="parse-pis">
1656      <xsl:with-param name="nodes" select="//processing-instruction('rfc')"/>
1657      <xsl:with-param name="attr" select="'SANITYCHECK'"/>
1658    </xsl:call-template>
1659  </xsl:variable>
1660
1661  <xsl:variable name="lang">
1662    <xsl:call-template name="get-lang" />
1663  </xsl:variable>
1664
1665  <html lang="{$lang}">
1666    <head>
1667      <xsl:attribute name="profile">
1668        <xsl:text>http://www.w3.org/2006/03/hcard</xsl:text>
1669        <xsl:if test="$xml2rfc-ext-support-rfc2731!='no'">
1670          <xsl:text> </xsl:text>
1671          <xsl:text>http://dublincore.org/documents/2008/08/04/dc-html/</xsl:text>
1672        </xsl:if>
1673      </xsl:attribute>
1674      <title>
1675        <xsl:apply-templates select="front/title" mode="get-text-content" />
1676      </title>
1677      <xsl:call-template name="insertCss" />
1678      <!-- <link rel="alternate stylesheet" type="text/css" media="screen" title="Plain (typewriter)" href="rfc2629tty.css" /> -->
1679           
1680      <!-- link elements -->
1681      <xsl:if test="$xml2rfc-toc='yes'">
1682        <link rel="Contents" href="#{$anchor-prefix}.toc" />
1683      </xsl:if>
1684      <link rel="Author" href="#{$anchor-prefix}.authors" />
1685      <xsl:if test="$xml2rfc-private=''">
1686        <link rel="Copyright" href="#{$anchor-prefix}.copyright" />
1687      </xsl:if>
1688      <xsl:if test="$has-index">
1689        <link rel="Index" href="#{$anchor-prefix}.index" />
1690      </xsl:if>
1691      <xsl:apply-templates select="/" mode="links" />
1692      <xsl:for-each select="x:link">
1693        <link><xsl:copy-of select="@*" /></link>
1694      </xsl:for-each>
1695      <xsl:if test="@number">
1696        <xsl:variable name="number">
1697          <xsl:choose>
1698            <xsl:when test="string-length(@number) &lt; 2">000<xsl:value-of select="@number"/></xsl:when>
1699            <xsl:when test="string-length(@number) &lt; 3">00<xsl:value-of select="@number"/></xsl:when>
1700            <xsl:when test="string-length(@number) &lt; 4">0<xsl:value-of select="@number"/></xsl:when>
1701            <xsl:otherwise><xsl:value-of select="@number"/></xsl:otherwise>
1702          </xsl:choose>
1703        </xsl:variable>
1704        <link rel="Alternate" title="Authorative ASCII Version" href="http://www.ietf.org/rfc/rfc{@number}.txt" />
1705        <link rel="Help" title="Additional Information on tools.ietf.org" href="http://tools.ietf.org/html/rfc{$number}" />
1706      </xsl:if>
1707
1708      <!-- generator -->
1709      <xsl:variable name="gen">
1710        <xsl:call-template name="get-generator" />
1711      </xsl:variable>
1712      <meta name="generator" content="{$gen}" />
1713     
1714      <!-- keywords -->
1715      <xsl:if test="front/keyword">
1716        <xsl:variable name="keyw">
1717          <xsl:call-template name="get-keywords" />
1718        </xsl:variable>
1719        <meta name="keywords" content="{$keyw}" />
1720      </xsl:if>
1721
1722      <xsl:if test="$xml2rfc-ext-support-rfc2731!='no'">
1723        <!-- Dublin Core Metadata -->
1724        <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
1725             
1726        <!-- DC creator, see RFC2731 -->
1727        <xsl:for-each select="front/author">
1728          <xsl:variable name="initials">
1729            <xsl:call-template name="format-initials"/>
1730          </xsl:variable>
1731          <meta name="DC.Creator" content="{concat(@surname,', ',$initials)}" />
1732        </xsl:for-each>
1733       
1734        <xsl:if test="$xml2rfc-private=''">
1735          <xsl:choose>
1736            <xsl:when test="@number">
1737              <meta name="DC.Identifier" content="urn:ietf:rfc:{@number}" />
1738            </xsl:when>
1739            <xsl:when test="@docName">
1740              <meta name="DC.Identifier" content="urn:ietf:id:{@docName}" />
1741            </xsl:when>
1742            <xsl:otherwise/>
1743          </xsl:choose>
1744          <meta name="DC.Date.Issued" scheme="ISO8601">
1745            <xsl:attribute name="content">
1746              <xsl:value-of select="concat($xml2rfc-ext-pub-year,'-',$pub-month-numeric)"/>
1747              <xsl:if test="$xml2rfc-ext-pub-day != '' and not(@number)">
1748                <xsl:value-of select="concat('-',format-number($xml2rfc-ext-pub-day,'00'))"/>
1749              </xsl:if>
1750            </xsl:attribute>
1751          </meta>
1752 
1753          <xsl:if test="@obsoletes!=''">
1754            <xsl:call-template name="rfclist-for-dcmeta">
1755              <xsl:with-param name="list" select="@obsoletes"/>
1756            </xsl:call-template>
1757          </xsl:if>
1758        </xsl:if>
1759 
1760        <xsl:if test="front/abstract">
1761          <meta name="DC.Description.Abstract" content="{normalize-space(front/abstract)}" />
1762        </xsl:if>     
1763
1764        <xsl:if test="@number">
1765          <meta name="DC.isPartOf" content="urn:issn:2070-1721" />
1766        </xsl:if>     
1767
1768      </xsl:if>
1769     
1770      <!-- this replicates dc.description.abstract, but is used by Google & friends -->
1771      <xsl:if test="front/abstract">
1772        <meta name="description" content="{normalize-space(front/abstract)}" />
1773      </xsl:if>
1774     
1775    </head>
1776    <body>
1777      <!-- insert diagnostics -->
1778      <xsl:call-template name="insert-diagnostics"/>
1779
1780      <xsl:apply-templates select="front" />
1781      <xsl:apply-templates select="middle" />
1782      <xsl:apply-templates select="back" />
1783    </body>
1784  </html>
1785</xsl:template>               
1786
1787
1788<xsl:template match="t">
1789  <xsl:if test="preceding-sibling::section or preceding-sibling::appendix">
1790    <xsl:call-template name="warning">
1791      <xsl:with-param name="msg">The paragraph below is misplaced; maybe a section is closed in the wrong place: </xsl:with-param>
1792      <xsl:with-param name="msg2"><xsl:value-of select="."/></xsl:with-param>
1793    </xsl:call-template>
1794  </xsl:if>
1795  <xsl:choose>
1796    <xsl:when test="@anchor">
1797      <div id="{@anchor}"><xsl:apply-templates mode="t-content" select="node()[1]" /></div>
1798    </xsl:when>
1799    <xsl:otherwise>
1800      <xsl:apply-templates mode="t-content" select="node()[1]" />
1801    </xsl:otherwise>
1802  </xsl:choose>
1803</xsl:template>
1804
1805<!-- for t-content, dispatch to default templates if it's block-level content -->
1806<xsl:template mode="t-content" match="list|figure|texttable">
1807  <!-- <xsl:comment>t-content block-level</xsl:comment>  -->
1808  <xsl:apply-templates select="." />
1809  <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content" />
1810</xsl:template>               
1811               
1812<!-- ... otherwise group into p elements -->
1813<xsl:template mode="t-content" match="*|node()">
1814  <xsl:variable name="p">
1815    <xsl:call-template name="get-paragraph-number" />
1816  </xsl:variable>
1817
1818  <!-- do not open a new p element if this is a whitespace-only text node and no siblings follow --> 
1819  <xsl:if test="not(self::text() and normalize-space(.)='' and not(following-sibling::node()))">
1820    <p>
1821      <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">
1822        <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$p"/></xsl:attribute>
1823      </xsl:if>
1824      <xsl:call-template name="insertInsDelClass"/>
1825      <xsl:call-template name="editingMark" />
1826      <xsl:apply-templates mode="t-content2" select="." />
1827    </p>
1828  </xsl:if>
1829  <xsl:apply-templates mode="t-content" select="following-sibling::*[self::list or self::figure or self::texttable][1]" />
1830</xsl:template>               
1831               
1832<xsl:template mode="t-content2" match="*">
1833  <xsl:apply-templates select="." />
1834  <xsl:if test="not(following-sibling::node()[1] [self::list or self::figure or self::texttable])">
1835    <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content2" />
1836  </xsl:if>
1837</xsl:template>       
1838
1839<xsl:template mode="t-content2" match="text()">
1840  <xsl:apply-templates select="." />
1841  <xsl:if test="not(following-sibling::node()[1] [self::list or self::figure or self::texttable])">
1842    <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content2" />
1843  </xsl:if>
1844</xsl:template>               
1845
1846<xsl:template mode="t-content2" match="comment()|processing-instruction()">
1847  <xsl:apply-templates select="." />
1848  <xsl:if test="not(following-sibling::node()[1] [self::list or self::figure or self::texttable])">
1849    <xsl:apply-templates select="following-sibling::node()[1]" mode="t-content2" />
1850  </xsl:if>
1851</xsl:template>               
1852
1853<xsl:template match="title">
1854  <xsl:if test="@abbrev and string-length(@abbrev) > 40">
1855    <xsl:call-template name="warning">
1856      <xsl:with-param name="inline" select="'no'"/>
1857      <xsl:with-param name="msg">title/@abbrev too long (max 40 characters)</xsl:with-param>
1858    </xsl:call-template>
1859  </xsl:if>
1860
1861  <xsl:if test="string-length(.) > 40 and (not(@abbrev) or @abbrev='')">
1862    <xsl:call-template name="warning">
1863      <xsl:with-param name="inline" select="'no'"/>
1864      <xsl:with-param name="msg">title too long, should supply title/@abbrev attribute with less than 40 characters</xsl:with-param>
1865    </xsl:call-template>
1866  </xsl:if>
1867
1868  <xsl:apply-templates />
1869</xsl:template>
1870
1871<xsl:template name="insertTitle">
1872  <xsl:choose>
1873    <xsl:when test="@ed:old-title">
1874      <del>
1875        <xsl:if test="ancestor-or-self::*[@ed:entered-by] and @ed:datetime">
1876          <xsl:attribute name="title"><xsl:value-of select="concat(@ed:datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
1877        </xsl:if>
1878        <xsl:value-of select="@ed:old-title"/>
1879      </del>
1880      <ins>
1881        <xsl:if test="ancestor-or-self::*[@ed:entered-by] and @ed:datetime">
1882          <xsl:attribute name="title"><xsl:value-of select="concat(@ed:datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
1883        </xsl:if>
1884        <xsl:value-of select="@title"/>
1885      </ins>
1886    </xsl:when>
1887    <xsl:otherwise>
1888      <xsl:value-of select="@title"/>
1889    </xsl:otherwise>
1890  </xsl:choose>
1891</xsl:template>
1892
1893<xsl:template match="section|appendix">
1894
1895  <xsl:if test="self::appendix">
1896    <xsl:call-template name="warning">
1897      <xsl:with-param name="inline" select="'no'"/>
1898      <xsl:with-param name="msg">The "appendix" element is deprecated, use "section" inside "back" instead.</xsl:with-param>
1899    </xsl:call-template>
1900  </xsl:if>
1901
1902  <xsl:variable name="sectionNumber">
1903    <xsl:choose>
1904      <xsl:when test="@myns:unnumbered"></xsl:when>
1905      <xsl:when test="ancestor::x:boilerplate"></xsl:when>
1906      <xsl:otherwise><xsl:call-template name="get-section-number" /></xsl:otherwise>
1907    </xsl:choose>
1908  </xsl:variable>
1909   
1910  <xsl:if test="not(ancestor::section) and not(ancestor::x:boilerplate) and not(@myns:notoclink)">
1911    <xsl:call-template name="insert-conditional-hrule"/>
1912  </xsl:if>
1913 
1914  <xsl:variable name="elemtype">
1915    <xsl:choose>
1916      <xsl:when test="count(ancestor::section) &lt;= 4">h<xsl:value-of select="1 + count(ancestor::section)"/></xsl:when>
1917      <xsl:otherwise>h6</xsl:otherwise>
1918    </xsl:choose>
1919  </xsl:variable>
1920 
1921  <!-- process irefs immediadetely following the section so that their anchor
1922  actually is the section heading -->
1923  <xsl:apply-templates select="iref[count(preceding-sibling::*[not(self::iref)])=0]"/>
1924
1925  <xsl:element name="{$elemtype}">
1926    <xsl:if test="$sectionNumber!=''">
1927      <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber"/></xsl:attribute>
1928    </xsl:if>
1929    <xsl:choose>
1930      <xsl:when test="$sectionNumber='1' or $sectionNumber='A'">
1931        <!-- pagebreak, this the first section -->
1932        <xsl:attribute name="class">np</xsl:attribute>
1933      </xsl:when>
1934      <xsl:when test="not(ancestor::section) and not(@myns:notoclink)">
1935        <xsl:call-template name="insert-conditional-pagebreak"/>
1936      </xsl:when>
1937      <xsl:otherwise/>
1938    </xsl:choose>
1939   
1940    <xsl:call-template name="insertInsDelClass" />
1941       
1942    <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
1943      <a href="#{$anchor-prefix}.section.{$sectionNumber}">
1944        <xsl:call-template name="emit-section-number">
1945          <xsl:with-param name="no" select="$sectionNumber"/>
1946        </xsl:call-template>
1947      </a>
1948      <xsl:text>&#0160;</xsl:text>
1949    </xsl:if>
1950   
1951    <!-- issue tracking? -->
1952    <xsl:if test="@ed:resolves">
1953      <xsl:call-template name="insert-issue-pointer"/>
1954    </xsl:if>
1955   
1956    <xsl:choose>
1957      <xsl:when test="@anchor">
1958        <xsl:call-template name="check-anchor"/>
1959        <a id="{@anchor}" href="#{@anchor}"><xsl:call-template name="insertTitle"/></a>
1960      </xsl:when>
1961      <xsl:otherwise>
1962        <xsl:call-template name="insertTitle"/>
1963      </xsl:otherwise>
1964    </xsl:choose>
1965  </xsl:element>
1966  <!-- continue with all child elements but the irefs processed above -->
1967  <xsl:apply-templates select="*[not(self::iref)]|iref[count(preceding-sibling::*[not(self::iref)])!=0]" />
1968</xsl:template>
1969
1970<xsl:template match="spanx[@style='emph' or not(@style)]">
1971  <em>
1972    <xsl:call-template name="copy-anchor"/>
1973    <xsl:apply-templates />
1974  </em>
1975</xsl:template>
1976
1977<xsl:template match="spanx[@style='verb']">
1978  <samp>
1979    <xsl:call-template name="copy-anchor"/>
1980    <xsl:apply-templates />
1981  </samp>
1982</xsl:template>
1983
1984<xsl:template match="spanx[@style='strong']">
1985  <strong>
1986    <xsl:call-template name="copy-anchor"/>
1987    <xsl:apply-templates />
1988  </strong>
1989</xsl:template>
1990
1991<xsl:template name="insert-blank-lines">
1992  <xsl:param name="no"/>
1993  <xsl:choose>
1994    <xsl:when test="$no &lt;= 0">
1995      <br/>
1996      <!-- done -->
1997    </xsl:when>
1998    <xsl:otherwise>
1999      <br/>
2000      <xsl:call-template name="insert-blank-lines">
2001        <xsl:with-param name="no" select="$no - 1"/>
2002      </xsl:call-template>
2003    </xsl:otherwise>
2004  </xsl:choose>
2005</xsl:template>
2006
2007<xsl:template match="vspace[not(@blankLines)]">
2008  <br />
2009</xsl:template>
2010
2011<xsl:template match="vspace">
2012  <xsl:call-template name="insert-blank-lines">
2013    <xsl:with-param name="no" select="@blankLines"/>
2014  </xsl:call-template>
2015</xsl:template>
2016
2017<!-- keep the root for the case when we process XSLT-inline markup -->
2018<xsl:variable name="src" select="/" />
2019
2020<xsl:template name="render-section-ref">
2021  <xsl:param name="from" />
2022  <xsl:param name="to" />
2023
2024  <xsl:variable name="refname">
2025    <xsl:for-each select="$to">
2026      <xsl:call-template name="get-section-type">
2027        <xsl:with-param name="prec" select="$from/preceding-sibling::node()[1]" />
2028      </xsl:call-template>
2029    </xsl:for-each>
2030  </xsl:variable>
2031  <xsl:variable name="refnum">
2032    <xsl:for-each select="$to">
2033      <xsl:call-template name="get-section-number" />
2034    </xsl:for-each>
2035  </xsl:variable>
2036  <xsl:attribute name="title">
2037    <xsl:value-of select="$to/@title" />
2038  </xsl:attribute>
2039  <xsl:choose>
2040    <xsl:when test="$from/@format='counter'">
2041      <xsl:value-of select="$refnum"/>
2042    </xsl:when>
2043    <xsl:when test="$from/@format='title'">
2044      <xsl:value-of select="$to/@title"/>
2045    </xsl:when>
2046    <xsl:otherwise>
2047      <xsl:value-of select="normalize-space(concat($refname,'&#160;',$refnum))"/>
2048    </xsl:otherwise>
2049  </xsl:choose>
2050</xsl:template>
2051
2052<xsl:template match="xref[node()]">
2053
2054  <xsl:variable name="target" select="@target" />
2055  <xsl:variable name="node" select="key('anchor-item',$target)" />
2056  <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>
2057
2058  <xsl:choose>
2059
2060    <!-- x:fmt='none': do not generate any links -->
2061    <xsl:when test="@x:fmt='none'">
2062      <xsl:choose>
2063        <xsl:when test="$node/self::reference">
2064          <cite title="{normalize-space($node/front/title)}">
2065            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
2066              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2067            </xsl:if>
2068            <!-- insert id when a backlink to this xref is needed in the index -->
2069            <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
2070              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2071            </xsl:if>
2072            <xsl:apply-templates/>
2073          </cite>
2074        </xsl:when>
2075        <xsl:otherwise>
2076          <xsl:apply-templates/>
2077        </xsl:otherwise>
2078      </xsl:choose>
2079    </xsl:when>
2080 
2081    <!-- Other x:fmt values than "none": unsupported -->
2082    <xsl:when test="@x:fmt and @x:fmt!='none'">
2083      <xsl:call-template name="error">
2084        <xsl:with-param name="msg" select="concat('unknown xref/@x:fmt extension: ',@x:fmt)"/>
2085      </xsl:call-template>
2086    </xsl:when>
2087   
2088    <!-- Section links -->
2089    <xsl:when test="$node/self::section or $node/self::appendix">
2090      <xsl:choose>
2091        <xsl:when test="@format='none'">
2092          <a href="#{@target}">
2093            <!-- insert id when a backlink to this xref is needed in the index -->
2094            <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
2095              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2096            </xsl:if>
2097            <xsl:apply-templates/>
2098          </a>
2099        </xsl:when>
2100        <xsl:otherwise>
2101          <xsl:apply-templates/>
2102          <xsl:text> (</xsl:text>
2103          <a href="#{@target}">
2104            <!-- insert id when a backlink to this xref is needed in the index -->
2105            <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
2106              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2107            </xsl:if>
2108            <xsl:call-template name="render-section-ref">
2109              <xsl:with-param name="from" select="."/>
2110              <xsl:with-param name="to" select="$node"/>
2111            </xsl:call-template>
2112          </a>
2113          <xsl:text>)</xsl:text>
2114        </xsl:otherwise>
2115      </xsl:choose>
2116    </xsl:when>
2117
2118    <xsl:otherwise>
2119      <a href="#{$target}">
2120        <xsl:if test="@format='none'">
2121          <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
2122            <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2123          </xsl:if>
2124        </xsl:if>
2125        <xsl:apply-templates />
2126      </a>
2127      <xsl:if test="not(@format='none')">
2128        <xsl:for-each select="$src/rfc/back/references//reference[@anchor=$target]">
2129          <xsl:text> </xsl:text>
2130          <cite title="{normalize-space(front/title)}">
2131            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
2132              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2133            </xsl:if>
2134            <xsl:call-template name="referencename">
2135               <xsl:with-param name="node" select="." />
2136            </xsl:call-template>
2137          </cite>
2138        </xsl:for-each>
2139      </xsl:if>
2140    </xsl:otherwise>
2141  </xsl:choose>
2142
2143</xsl:template>
2144               
2145<xsl:key name="iref-xanch" match="iref[@x:for-anchor]" use="@x:for-anchor"/>           
2146               
2147<xsl:template match="xref[not(node())]">
2148
2149  <xsl:variable name="xref" select="."/>
2150  <xsl:variable name="anchor"><xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="$xref/@target"/>.<xsl:number level="any" count="xref[@target=$xref/@target]"/></xsl:variable>
2151
2152  <!-- ensure we have the right context, this <xref> may be processed from within the boilerplate -->
2153  <xsl:for-each select="$src">
2154
2155    <xsl:variable name="node" select="key('anchor-item',$xref/@target)" />
2156    <xsl:if test="count($node)=0 and not($node/ancestor::ed:del)">
2157      <xsl:call-template name="error">
2158        <xsl:with-param name="msg" select="concat('Undefined target: ',$xref/@target)"/>
2159      </xsl:call-template>
2160    </xsl:if>
2161 
2162    <xsl:choose>
2163   
2164      <!-- Section links -->
2165      <xsl:when test="$node/self::section or $node/self::appendix">
2166        <a href="#{$xref/@target}">
2167          <!-- insert id when a backlink to this xref is needed in the index -->
2168          <xsl:if test="key('iref-xanch',$xref/@target) | key('iref-xanch','')[../@anchor=$xref/@target]">
2169            <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2170          </xsl:if>
2171          <xsl:call-template name="render-section-ref">
2172            <xsl:with-param name="from" select="$xref"/>
2173            <xsl:with-param name="to" select="$node"/>
2174          </xsl:call-template>
2175        </a>
2176      </xsl:when>
2177 
2178      <!-- Figure links -->
2179      <xsl:when test="$node/self::figure">
2180        <a href="#{$xref/@target}">
2181          <xsl:variable name="figcnt">
2182            <xsl:for-each select="$node">
2183              <xsl:number level="any" count="figure[(@title!='' or @anchor!='') and not(@suppress-title='true')]" />
2184            </xsl:for-each>
2185          </xsl:variable>
2186          <xsl:choose>
2187            <xsl:when test="$xref/@format='counter'">
2188              <xsl:value-of select="$figcnt" />
2189            </xsl:when>
2190            <xsl:when test="$xref/@format='title'">
2191              <xsl:value-of select="$node/@title" />
2192            </xsl:when>
2193            <xsl:otherwise>
2194              <xsl:value-of select="normalize-space(concat('Figure&#160;',$figcnt))"/>
2195            </xsl:otherwise>
2196          </xsl:choose>
2197        </a>
2198      </xsl:when>
2199     
2200      <!-- Table links -->
2201      <xsl:when test="$node/self::texttable">
2202        <a href="#{$xref/@target}">
2203          <xsl:variable name="tabcnt">
2204            <xsl:for-each select="$node">
2205              <xsl:number level="any" count="texttable[(@title!='' or @anchor!='') and not(@suppress-title='true')]" />
2206            </xsl:for-each>
2207          </xsl:variable>
2208          <xsl:choose>
2209            <xsl:when test="$xref/@format='counter'">
2210              <xsl:value-of select="$tabcnt" />
2211            </xsl:when>
2212            <xsl:when test="$xref/@format='title'">
2213              <xsl:value-of select="$node/@title" />
2214            </xsl:when>
2215            <xsl:otherwise>
2216              <xsl:value-of select="normalize-space(concat('Table&#160;',$tabcnt))"/>
2217            </xsl:otherwise>
2218          </xsl:choose>
2219        </a>
2220      </xsl:when>
2221     
2222      <!-- Paragraph links -->
2223      <xsl:when test="$node/self::t">
2224        <a href="#{$xref/@target}">
2225          <xsl:variable name="tcnt">
2226            <xsl:for-each select="$node">
2227              <xsl:call-template name="get-paragraph-number" />
2228            </xsl:for-each>
2229          </xsl:variable>
2230          <xsl:choose>
2231            <xsl:when test="$xref/@format='counter'">
2232              <xsl:value-of select="$tcnt" />
2233            </xsl:when>
2234            <xsl:when test="$xref/@format='title'">
2235              <xsl:value-of select="$node/@title" />
2236            </xsl:when>
2237            <xsl:otherwise>
2238              <xsl:value-of select="normalize-space(concat('Paragraph&#160;',substring-after($tcnt,'p.')))"/>
2239            </xsl:otherwise>
2240          </xsl:choose>
2241        </a>
2242      </xsl:when>
2243 
2244      <!-- Comment links -->
2245      <xsl:when test="$node/self::cref">
2246        <a href="#{$xref/@target}">
2247          <xsl:variable name="name">
2248            <xsl:for-each select="$node">
2249              <xsl:call-template name="get-comment-name" />
2250            </xsl:for-each>
2251          </xsl:variable>
2252          <xsl:choose>
2253            <xsl:when test="$xref/@format='counter'">
2254              <xsl:value-of select="$name" />
2255            </xsl:when>
2256            <xsl:when test="$xref/@format='title'">
2257              <xsl:value-of select="$node/@title" />
2258            </xsl:when>
2259            <xsl:otherwise>
2260              <xsl:value-of select="normalize-space(concat('Comment&#160;',$name))"/>
2261            </xsl:otherwise>
2262          </xsl:choose>
2263        </a>
2264      </xsl:when>
2265 
2266      <!-- Reference links -->
2267      <xsl:when test="$node/self::reference">
2268 
2269        <xsl:variable name="href">
2270          <xsl:call-template name="computed-target">
2271            <xsl:with-param name="bib" select="$node"/>
2272            <xsl:with-param name="ref" select="$xref"/>
2273          </xsl:call-template>
2274        </xsl:variable>
2275       
2276        <xsl:variable name="sec">
2277          <xsl:choose>
2278            <xsl:when test="starts-with($xref/@x:rel,'#') and not($xref/@x:sec) and $node/x:source/@href">
2279              <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
2280              <xsl:variable name="nodes" select="$extdoc//*[@anchor=substring-after($xref/@x:rel,'#')]"/>
2281              <xsl:if test="not($nodes)">
2282                <xsl:call-template name="error">
2283                  <xsl:with-param name="msg">Anchor '<xsl:value-of select="substring-after($xref/@x:rel,'#')"/>' not found in <xsl:value-of select="$node/x:source/@href"/>.</xsl:with-param>
2284                </xsl:call-template>
2285              </xsl:if>
2286              <xsl:for-each select="$nodes">
2287                <xsl:call-template name="get-section-number"/>
2288              </xsl:for-each>
2289            </xsl:when>
2290            <xsl:otherwise>
2291              <xsl:value-of select="$xref/@x:sec"/>
2292            </xsl:otherwise>
2293          </xsl:choose>
2294        </xsl:variable>
2295       
2296        <xsl:variable name="secterm">
2297          <xsl:choose>
2298            <!-- starts with letter? -->
2299            <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">Appendix</xsl:when>
2300            <xsl:otherwise>Section</xsl:otherwise>
2301          </xsl:choose>
2302        </xsl:variable>
2303 
2304        <xsl:variable name="fmt">
2305          <xsl:choose>
2306            <xsl:when test="$xref/@x:fmt!=''"><xsl:value-of select="$xref/@x:fmt"/></xsl:when>
2307            <xsl:when test="$xref/ancestor::artwork">,</xsl:when>
2308            <xsl:otherwise>of</xsl:otherwise>
2309          </xsl:choose>
2310        </xsl:variable>
2311 
2312        <xsl:variable name="title">
2313          <xsl:choose>
2314            <xsl:when test="starts-with($xref/@x:rel,'#') and not($xref/@x:sec) and $node/x:source/@href">
2315              <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
2316              <xsl:variable name="nodes" select="$extdoc//*[@anchor=substring-after($xref//@x:rel,'#')]"/>
2317              <xsl:if test="not($nodes)">
2318                <xsl:call-template name="error">
2319                  <xsl:with-param name="msg">Anchor '<xsl:value-of select="substring-after($xref//@x:rel,'#')"/>' not found in <xsl:value-of select="$node/x:source/@href"/>.</xsl:with-param>
2320                </xsl:call-template>
2321              </xsl:if>
2322              <xsl:for-each select="$nodes">
2323                <xsl:value-of select="@title"/>
2324              </xsl:for-each>
2325            </xsl:when>
2326            <xsl:otherwise />
2327          </xsl:choose>
2328        </xsl:variable>
2329 
2330        <!--
2331        Formats:
2332       
2333          ()      [XXXX] (Section SS)
2334          ,       [XXXX], Section SS
2335          of      Section SS of [XXXX]
2336          sec     Section SS
2337          number  SS
2338        -->
2339       
2340        <xsl:if test="$fmt and not($fmt='()' or $fmt=',' or $fmt='of' or $fmt='sec' or $fmt='anchor' or $fmt='number')">
2341          <xsl:call-template name="error">
2342            <xsl:with-param name="msg" select="concat('unknown xref/@x:fmt extension: ',$fmt)"/>
2343          </xsl:call-template>
2344        </xsl:if>
2345 
2346        <xsl:if test="$sec!=''">
2347               
2348          <xsl:choose>
2349            <xsl:when test="$fmt='of' or $fmt='sec'">
2350              <xsl:choose>
2351                <xsl:when test="$href!=''">
2352                  <a href="{$href}">
2353                    <xsl:if test="$title!=''">
2354                      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
2355                    </xsl:if>
2356                    <xsl:if test="$fmt='sec' and $xml2rfc-ext-include-references-in-index='yes'">
2357                      <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2358                    </xsl:if>
2359                    <xsl:value-of select="$secterm"/>
2360                    <xsl:text> </xsl:text>
2361                    <xsl:value-of select="$sec"/>
2362                  </a>
2363                </xsl:when>
2364                <xsl:otherwise><xsl:value-of select="$secterm"/><xsl:text> </xsl:text><xsl:value-of select="$sec"/></xsl:otherwise>
2365              </xsl:choose>
2366              <xsl:if test="$fmt='of'">
2367                <xsl:text> of </xsl:text>
2368              </xsl:if>
2369            </xsl:when>
2370            <xsl:when test="$fmt='number'">
2371              <xsl:choose>
2372                <xsl:when test="$href!=''">
2373                  <a href="{$href}">
2374                    <xsl:if test="$title!=''">
2375                      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
2376                    </xsl:if>
2377                    <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
2378                      <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2379                    </xsl:if>
2380                    <xsl:value-of select="$sec"/>
2381                  </a>
2382                </xsl:when>
2383                <xsl:otherwise><xsl:value-of select="$sec"/></xsl:otherwise>
2384              </xsl:choose>
2385            </xsl:when>
2386            <xsl:otherwise />
2387          </xsl:choose>
2388        </xsl:if>
2389 
2390        <xsl:if test="$sec='' or ($fmt!='sec' and $fmt!='number')">
2391          <a href="#{$xref/@target}">
2392            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
2393              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
2394            </xsl:if>
2395            <cite title="{normalize-space($node/front/title)}">
2396              <xsl:variable name="val">
2397                <xsl:call-template name="referencename">
2398                  <xsl:with-param name="node" select="$node" />
2399                </xsl:call-template>
2400              </xsl:variable>
2401              <xsl:choose>
2402                <xsl:when test="$fmt='anchor'">
2403                  <!-- remove brackets -->
2404                  <xsl:value-of select="substring($val,2,string-length($val)-2)"/>
2405                </xsl:when>
2406                <xsl:otherwise>
2407                  <xsl:value-of select="$val"/>
2408                </xsl:otherwise>
2409              </xsl:choose>
2410            </cite>
2411          </a>
2412        </xsl:if>
2413       
2414        <xsl:if test="$sec!=''">
2415          <xsl:choose>
2416            <xsl:when test="$fmt='()'">
2417              <xsl:text> (</xsl:text>
2418              <xsl:choose>
2419                <xsl:when test="$href!=''">
2420                  <a href="{$href}"><xsl:value-of select="$secterm"/><xsl:text> </xsl:text><xsl:value-of select="$sec"/></a>
2421                </xsl:when>
2422                <xsl:otherwise><xsl:value-of select="$secterm"/><xsl:text> </xsl:text><xsl:value-of select="$sec"/></xsl:otherwise>
2423              </xsl:choose>
2424              <xsl:text>)</xsl:text>
2425            </xsl:when>
2426            <xsl:when test="$fmt=','">
2427              <xsl:text>, </xsl:text>
2428              <xsl:choose>
2429                <xsl:when test="$href!=''">
2430                  <a href="{$href}">
2431                    <xsl:if test="$title!=''">
2432                      <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
2433                    </xsl:if>
2434                    <xsl:value-of select="$secterm"/>
2435                    <xsl:text> </xsl:text>
2436                    <xsl:value-of select="$sec"/>
2437                  </a>
2438                </xsl:when>
2439                <xsl:otherwise><xsl:value-of select="$secterm"/><xsl:text> </xsl:text><xsl:value-of select="$sec"/></xsl:otherwise>
2440              </xsl:choose>
2441            </xsl:when>
2442            <xsl:otherwise/>
2443          </xsl:choose>
2444        </xsl:if>
2445      </xsl:when>
2446     
2447      <xsl:otherwise>
2448        <xsl:call-template name="error">
2449          <xsl:with-param name="msg" select="concat('xref to unknown element: ',name($node))"/>
2450        </xsl:call-template>
2451      </xsl:otherwise>
2452    </xsl:choose>
2453  </xsl:for-each>
2454</xsl:template>
2455
2456
2457<!-- mark unmatched elements red -->
2458
2459<xsl:template match="*">
2460  <xsl:call-template name="error">
2461    <xsl:with-param name="inline" select="'no'"/>
2462    <xsl:with-param name="msg">no XSLT template for element '<xsl:value-of select="name()"/>'</xsl:with-param>
2463  </xsl:call-template>
2464  <tt class="error">&lt;<xsl:value-of select="name()" />&gt;</tt>
2465  <xsl:copy><xsl:apply-templates select="node()|@*" /></xsl:copy>
2466  <tt class="error">&lt;/<xsl:value-of select="name()" />&gt;</tt>
2467</xsl:template>
2468
2469<xsl:template match="/">
2470  <xsl:apply-templates select="*" />
2471</xsl:template>
2472
2473<!-- utility templates -->
2474
2475<xsl:template name="collectLeftHeaderColumn">
2476  <xsl:param name="mode" />
2477  <!-- default case -->
2478  <xsl:if test="$xml2rfc-private=''">
2479    <xsl:choose>
2480      <xsl:when test="$xml2rfc-ext-hab='yes' and $submissionType='independent'">
2481        <myns:item>Independent<!-- Stream--></myns:item>
2482      </xsl:when>
2483      <xsl:when test="$xml2rfc-ext-hab='yes' and $submissionType='IETF'">
2484        <myns:item>Internet Engineering Task Force</myns:item>
2485      </xsl:when>
2486      <xsl:when test="$xml2rfc-ext-hab='yes' and $submissionType='IRTF'">
2487        <myns:item>Internet Research Task Force</myns:item>
2488      </xsl:when>
2489      <xsl:when test="$xml2rfc-ext-hab='yes' and $submissionType='IAB'">
2490        <myns:item>Internet Architecture Board</myns:item>
2491      </xsl:when>
2492      <xsl:when test="/rfc/front/workgroup and (not(/rfc/@number) or /rfc/@number='')">
2493        <xsl:for-each select="/rfc/front/workgroup">
2494          <myns:item><xsl:value-of select="."/></myns:item>
2495        </xsl:for-each>
2496      </xsl:when>
2497      <xsl:otherwise>
2498        <myns:item>Network Working Group</myns:item>
2499      </xsl:otherwise>
2500    </xsl:choose>
2501    <myns:item>
2502       <xsl:choose>
2503        <xsl:when test="/rfc/@ipr and not(/rfc/@number)">Internet Draft</xsl:when>
2504        <xsl:otherwise>Request for Comments: <xsl:value-of select="/rfc/@number"/></xsl:otherwise>
2505      </xsl:choose>
2506    </myns:item>
2507    <xsl:if test="/rfc/@docName and $mode!='nroff'">
2508      <myns:item>
2509        &lt;<xsl:value-of select="/rfc/@docName" />&gt;
2510      </myns:item>
2511    </xsl:if>
2512    <xsl:if test="/rfc/@obsoletes and /rfc/@obsoletes!=''">
2513      <myns:item>
2514        <xsl:text>Obsoletes: </xsl:text>
2515        <xsl:call-template name="rfclist">
2516          <xsl:with-param name="list" select="normalize-space(/rfc/@obsoletes)" />
2517        </xsl:call-template>
2518        <xsl:if test="not(/rfc/@number)"> (if approved)</xsl:if>
2519      </myns:item>
2520    </xsl:if>
2521    <xsl:if test="/rfc/@seriesNo">
2522       <myns:item>
2523        <xsl:choose>
2524          <xsl:when test="/rfc/@category='bcp'">BCP: <xsl:value-of select="/rfc/@seriesNo" /></xsl:when>
2525          <xsl:when test="/rfc/@category='info'">FYI: <xsl:value-of select="/rfc/@seriesNo" /></xsl:when>
2526          <xsl:when test="/rfc/@category='std'">STD: <xsl:value-of select="/rfc/@seriesNo" /></xsl:when>
2527          <xsl:otherwise><xsl:value-of select="concat(/rfc/@category,': ',/rfc/@seriesNo)" /></xsl:otherwise>
2528        </xsl:choose>
2529      </myns:item>
2530    </xsl:if>
2531    <xsl:if test="/rfc/@updates and /rfc/@updates!=''">
2532      <myns:item>
2533        <xsl:text>Updates: </xsl:text>
2534          <xsl:call-template name="rfclist">
2535             <xsl:with-param name="list" select="normalize-space(/rfc/@updates)" />
2536          </xsl:call-template>
2537          <xsl:if test="not(/rfc/@number)"> (if approved)</xsl:if>
2538      </myns:item>
2539    </xsl:if>
2540    <xsl:if test="$mode!='nroff'">
2541      <myns:item>
2542        <xsl:choose>
2543          <xsl:when test="/rfc/@number">
2544            <xsl:text>Category: </xsl:text>
2545          </xsl:when>
2546          <xsl:otherwise>
2547            <xsl:text>Intended status: </xsl:text>
2548          </xsl:otherwise>
2549        </xsl:choose>
2550        <xsl:call-template name="get-category-long" />
2551      </myns:item>
2552    </xsl:if>
2553    <xsl:if test="/rfc/@ipr and not(/rfc/@number)">
2554       <myns:item>Expires: <xsl:call-template name="expirydate" /></myns:item>
2555    </xsl:if>
2556  </xsl:if>
2557   
2558  <!-- private case -->
2559  <xsl:if test="$xml2rfc-private!=''">
2560    <myns:item><xsl:value-of select="$xml2rfc-private" /></myns:item>
2561  </xsl:if>
2562</xsl:template>
2563
2564<xsl:template name="collectRightHeaderColumn">
2565  <xsl:for-each select="author">
2566    <xsl:variable name="initials">
2567      <xsl:call-template name="format-initials"/>
2568    </xsl:variable>
2569    <xsl:if test="@surname">
2570      <myns:item>
2571        <xsl:value-of select="concat($initials,' ',@surname)" />
2572        <xsl:if test="@role">
2573          <xsl:choose>
2574            <xsl:when test="@role='editor'">
2575              <xsl:text>, Editor</xsl:text>
2576            </xsl:when>
2577            <xsl:otherwise>
2578              <xsl:text>, </xsl:text><xsl:value-of select="@role" />
2579            </xsl:otherwise>
2580          </xsl:choose>
2581        </xsl:if>
2582      </myns:item>
2583    </xsl:if>
2584    <xsl:variable name="org">
2585      <xsl:choose>
2586        <xsl:when test="organization/@abbrev"><xsl:value-of select="organization/@abbrev" /></xsl:when>
2587        <xsl:otherwise><xsl:value-of select="organization" /></xsl:otherwise>
2588      </xsl:choose>
2589    </xsl:variable>
2590    <xsl:variable name="orgOfFollowing">
2591      <xsl:choose>
2592        <xsl:when test="following-sibling::*[1]/organization/@abbrev"><xsl:value-of select="following-sibling::*[1]/organization/@abbrev" /></xsl:when>
2593        <xsl:otherwise><xsl:value-of select="following-sibling::*/organization" /></xsl:otherwise>
2594      </xsl:choose>
2595    </xsl:variable>
2596    <xsl:if test="$org != $orgOfFollowing and $org != ''">
2597      <myns:item><xsl:value-of select="$org" /></myns:item>
2598    </xsl:if>
2599  </xsl:for-each>
2600  <myns:item>
2601    <xsl:if test="$xml2rfc-ext-pub-month!=''">
2602      <xsl:value-of select="$xml2rfc-ext-pub-month" />
2603      <xsl:if test="$xml2rfc-ext-pub-day!='' and /rfc/@ipr and not(/rfc/@number)">
2604        <xsl:text> </xsl:text>
2605        <xsl:value-of select="$xml2rfc-ext-pub-day" />
2606        <xsl:text>,</xsl:text>
2607      </xsl:if>
2608    </xsl:if>
2609    <xsl:value-of select="concat(' ',$xml2rfc-ext-pub-year)" />
2610  </myns:item>
2611</xsl:template>
2612
2613
2614<xsl:template name="emitheader">
2615  <xsl:param name="lc" />
2616  <xsl:param name="rc" />
2617
2618  <tbody>
2619    <xsl:for-each select="$lc/myns:item | $rc/myns:item">
2620      <xsl:variable name="pos" select="position()" />
2621      <xsl:if test="$pos &lt; count($lc/myns:item) + 1 or $pos &lt; count($rc/myns:item) + 1"> 
2622        <tr>
2623          <td class="left"><xsl:call-template name="copynodes"><xsl:with-param name="nodes" select="$lc/myns:item[$pos]/node()" /></xsl:call-template></td>
2624          <td class="right"><xsl:call-template name="copynodes"><xsl:with-param name="nodes" select="$rc/myns:item[$pos]/node()" /></xsl:call-template></td>
2625        </tr>
2626      </xsl:if>
2627    </xsl:for-each>
2628  </tbody>
2629</xsl:template>
2630
2631<!-- convenience template that avoids copying namespace nodes we don't want -->
2632<xsl:template name="copynodes">
2633  <xsl:param name="nodes" />
2634  <xsl:for-each select="$nodes">
2635    <xsl:choose>
2636      <xsl:when test="namespace-uri()='http://www.w3.org/1999/xhtml'">
2637        <xsl:element name="{name()}" namespace="{namespace-uri()}">
2638          <xsl:copy-of select="@*|node()" />
2639        </xsl:element>
2640      </xsl:when>
2641      <xsl:when test="self::*">
2642        <xsl:element name="{name()}">
2643          <xsl:copy-of select="@*|node()" />
2644        </xsl:element>
2645      </xsl:when>
2646      <!-- workaround for opera, remove when Opera > 9.0.x comes out -->
2647      <xsl:when test="self::text()">
2648        <xsl:value-of select="."/>
2649      </xsl:when>
2650      <xsl:otherwise>
2651        <xsl:copy-of select="." />
2652      </xsl:otherwise>
2653    </xsl:choose>
2654  </xsl:for-each>
2655</xsl:template>
2656
2657
2658<xsl:template name="expirydate">
2659  <xsl:choose>
2660    <xsl:when test="$xml2rfc-ext-pub-day >= 1">
2661      <xsl:call-template name="normalize-date">
2662        <xsl:with-param name="year" select="$xml2rfc-ext-pub-year"/>
2663        <xsl:with-param name="month" select="$pub-month-numeric"/>
2664        <xsl:with-param name="day" select="$xml2rfc-ext-pub-day + 185"/>
2665      </xsl:call-template>
2666    </xsl:when>
2667    <xsl:when test="$xml2rfc-ext-pub-month='January'">July <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2668    <xsl:when test="$xml2rfc-ext-pub-month='February'">August <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2669    <xsl:when test="$xml2rfc-ext-pub-month='March'">September <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2670    <xsl:when test="$xml2rfc-ext-pub-month='April'">October <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2671    <xsl:when test="$xml2rfc-ext-pub-month='May'">November <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2672    <xsl:when test="$xml2rfc-ext-pub-month='June'">December <xsl:value-of select="$xml2rfc-ext-pub-year" /></xsl:when>
2673    <xsl:when test="$xml2rfc-ext-pub-month='July'">January <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2674    <xsl:when test="$xml2rfc-ext-pub-month='August'">February <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2675    <xsl:when test="$xml2rfc-ext-pub-month='September'">March <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2676    <xsl:when test="$xml2rfc-ext-pub-month='October'">April <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2677    <xsl:when test="$xml2rfc-ext-pub-month='November'">May <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2678    <xsl:when test="$xml2rfc-ext-pub-month='December'">June <xsl:value-of select="$xml2rfc-ext-pub-year + 1" /></xsl:when>
2679      <xsl:otherwise>WRONG SYNTAX FOR MONTH</xsl:otherwise>
2680   </xsl:choose>
2681</xsl:template>
2682
2683<xsl:template name="normalize-date">
2684  <xsl:param name="year"/>
2685  <xsl:param name="month"/>
2686  <xsl:param name="day"/>
2687
2688  <xsl:variable name="isleap" select="(($year mod 4) = 0 and ($year mod 100 != 0)) or ($year mod 400) = 0" />
2689
2690  <!--<xsl:message>
2691    <xsl:value-of select="concat($year,' ',$month,' ',$day)"/>
2692  </xsl:message>-->
2693 
2694  <xsl:variable name="dim">
2695    <xsl:choose>
2696      <xsl:when test="$month=1 or $month=3 or $month=5 or $month=7 or $month=8 or $month=10 or $month=12">31</xsl:when>
2697      <xsl:when test="$month=2 and $isleap">29</xsl:when>
2698      <xsl:when test="$month=2 and not($isleap)">28</xsl:when>
2699      <xsl:otherwise>30</xsl:otherwise>
2700    </xsl:choose>
2701  </xsl:variable>
2702 
2703  <xsl:choose>
2704    <xsl:when test="$day > $dim and $month=12">
2705      <xsl:call-template name="normalize-date">
2706        <xsl:with-param name="year" select="$year + 1"/>
2707        <xsl:with-param name="month" select="1"/>
2708        <xsl:with-param name="day" select="$day - $dim"/>
2709      </xsl:call-template>
2710    </xsl:when>
2711    <xsl:when test="$day > $dim">
2712      <xsl:call-template name="normalize-date">
2713        <xsl:with-param name="year" select="$year"/>
2714        <xsl:with-param name="month" select="$month + 1"/>
2715        <xsl:with-param name="day" select="$day - $dim"/>
2716      </xsl:call-template>
2717    </xsl:when>
2718    <xsl:otherwise>
2719      <xsl:call-template name="get-month-as-name">
2720        <xsl:with-param name="month" select="$month"/>
2721      </xsl:call-template>
2722      <xsl:value-of select="concat(' ',$day,', ',$year)"/>
2723    </xsl:otherwise>
2724  </xsl:choose>
2725
2726</xsl:template>
2727 
2728<xsl:template name="get-month-as-num">
2729  <xsl:param name="month" />
2730  <xsl:choose>
2731    <xsl:when test="$month='January'">01</xsl:when>
2732    <xsl:when test="$month='February'">02</xsl:when>
2733    <xsl:when test="$month='March'">03</xsl:when>
2734    <xsl:when test="$month='April'">04</xsl:when>
2735    <xsl:when test="$month='May'">05</xsl:when>
2736    <xsl:when test="$month='June'">06</xsl:when>
2737    <xsl:when test="$month='July'">07</xsl:when>
2738    <xsl:when test="$month='August'">08</xsl:when>
2739    <xsl:when test="$month='September'">09</xsl:when>
2740    <xsl:when test="$month='October'">10</xsl:when>
2741    <xsl:when test="$month='November'">11</xsl:when>
2742    <xsl:when test="$month='December'">12</xsl:when>
2743    <xsl:otherwise>WRONG SYNTAX FOR MONTH</xsl:otherwise>
2744  </xsl:choose>
2745</xsl:template>
2746
2747<xsl:template name="get-month-as-name">
2748  <xsl:param name="month"/>
2749  <xsl:choose>
2750    <xsl:when test="$month=1">January</xsl:when>
2751    <xsl:when test="$month=2">February</xsl:when>
2752    <xsl:when test="$month=3">March</xsl:when>
2753    <xsl:when test="$month=4">April</xsl:when>
2754    <xsl:when test="$month=5">May</xsl:when>
2755    <xsl:when test="$month=6">June</xsl:when>
2756    <xsl:when test="$month=7">July</xsl:when>
2757    <xsl:when test="$month=8">August</xsl:when>
2758    <xsl:when test="$month=9">September</xsl:when>
2759    <xsl:when test="$month=10">October</xsl:when>
2760    <xsl:when test="$month=11">November</xsl:when>
2761    <xsl:when test="$month=12">December</xsl:when>
2762    <xsl:otherwise>WRONG SYNTAX FOR MONTH</xsl:otherwise>
2763   </xsl:choose>
2764</xsl:template>
2765
2766<!-- produce back section with author information -->
2767<xsl:template name="get-authors-section-title">
2768  <xsl:choose>
2769    <xsl:when test="count(/rfc/front/author)=1">Author's Address</xsl:when>
2770    <xsl:otherwise>Authors' Addresses</xsl:otherwise>
2771  </xsl:choose>
2772</xsl:template>
2773
2774<xsl:template name="get-authors-section-number">
2775  <xsl:if test="/*/x:assign-section-number[@builtin-target='authors']">
2776    <xsl:value-of select="/*/x:assign-section-number[@builtin-target='authors']/@number"/>
2777  </xsl:if>
2778</xsl:template>
2779
2780<xsl:template name="insertAuthors">
2781
2782  <xsl:variable name="number">
2783    <xsl:call-template name="get-authors-section-number"/>
2784  </xsl:variable>
2785   
2786  <xsl:if test="$number!='suppress'">
2787    <xsl:call-template name="insert-conditional-hrule"/>
2788   
2789    <div class="avoidbreak">
2790      <h1 id="{$anchor-prefix}.authors">
2791        <xsl:call-template name="insert-conditional-pagebreak"/>
2792        <xsl:if test="$number != ''">
2793          <a href="#{$anchor-prefix}.section.{$number}" id="{$anchor-prefix}.section.{$number}"><xsl:value-of select="$number"/>.</a>
2794          <xsl:text> </xsl:text>
2795        </xsl:if>
2796        <a href="#{$anchor-prefix}.authors"><xsl:call-template name="get-authors-section-title"/></a>
2797      </h1>
2798   
2799      <xsl:apply-templates select="/rfc/front/author" />
2800    </div>
2801  </xsl:if>
2802</xsl:template>
2803
2804
2805
2806<!-- insert copyright statement -->
2807
2808<xsl:template name="insertCopyright" myns:namespaceless-elements="xml2rfc">
2809
2810  <xsl:if test="not($no-copylong)">
2811    <section title="Full Copyright Statement" anchor="{$anchor-prefix}.copyright" myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2812      <xsl:choose>
2813        <xsl:when test="$ipr-rfc3667">
2814          <t>
2815            <xsl:choose>
2816              <xsl:when test="$ipr-rfc4748">
2817                Copyright &#169; The IETF Trust (<xsl:value-of select="$xml2rfc-ext-pub-year" />).
2818              </xsl:when>
2819              <xsl:otherwise>
2820                Copyright &#169; The Internet Society (<xsl:value-of select="$xml2rfc-ext-pub-year" />).
2821              </xsl:otherwise>
2822            </xsl:choose>
2823          </t>
2824          <t>
2825            This document is subject to the rights, licenses and restrictions
2826            contained in BCP 78<xsl:if test="$submissionType='independent'"> and at <eref target="http://www.rfc-editor.org/copyright.html"/></xsl:if>, and except as set forth therein, the authors
2827            retain all their rights.
2828          </t>
2829          <t>
2830            This document and the information contained herein are provided
2831            on an &#8220;AS IS&#8221; basis and THE CONTRIBUTOR,
2832            THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY),
2833            THE INTERNET SOCIETY<xsl:if test="$ipr-rfc4748">, THE IETF TRUST</xsl:if>
2834            AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES,
2835            EXPRESS OR IMPLIED,
2836            INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
2837            INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
2838            WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
2839          </t>
2840        </xsl:when>
2841        <xsl:otherwise>
2842          <!-- <http://tools.ietf.org/html/rfc2026#section-10.4> -->
2843          <t>
2844            Copyright &#169; The Internet Society (<xsl:value-of select="$xml2rfc-ext-pub-year" />). All Rights Reserved.
2845          </t>
2846          <t>
2847            This document and translations of it may be copied and furnished to
2848            others, and derivative works that comment on or otherwise explain it
2849            or assist in its implementation may be prepared, copied, published and
2850            distributed, in whole or in part, without restriction of any kind,
2851            provided that the above copyright notice and this paragraph are
2852            included on all such copies and derivative works. However, this
2853            document itself may not be modified in any way, such as by removing
2854            the copyright notice or references to the Internet Society or other
2855            Internet organizations, except as needed for the purpose of
2856            developing Internet standards in which case the procedures for
2857            copyrights defined in the Internet Standards process must be
2858            followed, or as required to translate it into languages other than
2859            English.
2860          </t>
2861          <t>
2862            The limited permissions granted above are perpetual and will not be
2863            revoked by the Internet Society or its successors or assignees.
2864          </t>
2865          <t>
2866            This document and the information contained herein is provided on an
2867            &#8220;AS IS&#8221; basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
2868            TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
2869            BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
2870            HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
2871            MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
2872          </t>
2873        </xsl:otherwise>
2874      </xsl:choose>
2875    </section>
2876   
2877    <section title="Intellectual Property" anchor="{$anchor-prefix}.ipr" myns:unnumbered="unnumbered">
2878      <xsl:choose>
2879        <xsl:when test="$ipr-rfc3667">
2880          <t>
2881            The IETF takes no position regarding the validity or scope of any
2882            Intellectual Property Rights or other rights that might be claimed to
2883            pertain to the implementation or use of the technology described in
2884            this document or the extent to which any license under such rights
2885            might or might not be available; nor does it represent that it has
2886            made any independent effort to identify any such rights.  Information
2887            on the procedures with respect to rights in RFC documents
2888            can be found in BCP 78 and BCP 79.
2889          </t>       
2890          <t>
2891            Copies of IPR disclosures made to the IETF Secretariat and any
2892            assurances of licenses to be made available, or the result of an
2893            attempt made to obtain a general license or permission for the use
2894            of such proprietary rights by implementers or users of this
2895            specification can be obtained from the IETF on-line IPR repository
2896            at <eref target="http://www.ietf.org/ipr"/>.
2897          </t>       
2898          <t>
2899            The IETF invites any interested party to bring to its attention any
2900            copyrights, patents or patent applications, or other proprietary
2901            rights that may cover technology that may be required to implement
2902            this standard. Please address the information to the IETF at
2903            <eref target="mailto:ietf-ipr@ietf.org">ietf-ipr@ietf.org</eref>.
2904          </t>       
2905        </xsl:when>
2906        <xsl:otherwise>
2907          <t>
2908            The IETF takes no position regarding the validity or scope of
2909            any intellectual property or other rights that might be claimed
2910            to  pertain to the implementation or use of the technology
2911            described in this document or the extent to which any license
2912            under such rights might or might not be available; neither does
2913            it represent that it has made any effort to identify any such
2914            rights. Information on the IETF's procedures with respect to
2915            rights in standards-track and standards-related documentation
2916            can be found in BCP-11. Copies of claims of rights made
2917            available for publication and any assurances of licenses to
2918            be made available, or the result of an attempt made
2919            to obtain a general license or permission for the use of such
2920            proprietary rights by implementors or users of this
2921            specification can be obtained from the IETF Secretariat.
2922          </t>
2923          <t>
2924            The IETF invites any interested party to bring to its
2925            attention any copyrights, patents or patent applications, or
2926            other proprietary rights which may cover technology that may be
2927            required to practice this standard. Please address the
2928            information to the IETF Executive Director.
2929          </t>
2930          <xsl:if test="$xml2rfc-iprnotified='yes'">
2931            <t>
2932              The IETF has been notified of intellectual property rights
2933              claimed in regard to some or all of the specification contained
2934              in this document. For more information consult the online list
2935              of claimed rights.
2936            </t>
2937          </xsl:if>
2938        </xsl:otherwise>
2939      </xsl:choose>
2940    </section>
2941   
2942    <xsl:choose>
2943      <xsl:when test="$no-funding"/>
2944      <xsl:when test="$funding1 and /rfc/@number">
2945        <section myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2946          <xsl:attribute name="title">
2947            <xsl:choose>
2948              <xsl:when test="$xml2rfc-rfcedstyle='yes'">Acknowledgement</xsl:when>
2949              <xsl:otherwise>Acknowledgment</xsl:otherwise>
2950            </xsl:choose>
2951          </xsl:attribute>
2952          <t>
2953            Funding for the RFC Editor function is provided by the IETF
2954            Administrative Support Activity (IASA).
2955          </t>
2956        </section>
2957      </xsl:when>
2958      <xsl:when test="$funding0 and /rfc/@number">
2959        <section myns:unnumbered="unnumbered" myns:notoclink="notoclink">
2960          <xsl:attribute name="title">
2961            <xsl:choose>
2962              <xsl:when test="$xml2rfc-rfcedstyle='yes'">Acknowledgement</xsl:when>
2963              <xsl:otherwise>Acknowledgment</xsl:otherwise>
2964            </xsl:choose>
2965          </xsl:attribute>
2966          <t>
2967            Funding for the RFC Editor function is currently provided by
2968            the Internet Society.
2969          </t>
2970        </section>
2971      </xsl:when>
2972      <xsl:otherwise/>
2973    </xsl:choose>
2974  </xsl:if>
2975
2976</xsl:template>
2977
2978
2979<!-- insert CSS style info -->
2980
2981<xsl:template name="insertCss">
2982<style type="text/css" title="Xml2Rfc (sans serif)">
2983a {
2984  text-decoration: none;
2985}
2986a.smpl {
2987  color: black;
2988}
2989a:hover {
2990  text-decoration: underline;
2991}
2992a:active {
2993  text-decoration: underline;
2994}
2995address {
2996  margin-top: 1em;
2997  margin-left: 2em;
2998  font-style: normal;
2999}<xsl:if test="//x:blockquote">
3000blockquote {
3001  border-style: solid;
3002  border-color: gray;
3003  border-width: 0 0 0 .25em;
3004  font-style: italic;
3005  padding-left: 0.5em;
3006}</xsl:if>
3007body {<xsl:if test="$xml2rfc-background!=''">
3008  background: url(<xsl:value-of select="$xml2rfc-background" />) #ffffff left top;</xsl:if>
3009  color: black;
3010  font-family: verdana, helvetica, arial, sans-serif;
3011  font-size: 10pt;
3012}<xsl:if test="//xhtml:p">
3013br.p {
3014  line-height: 150%;
3015}</xsl:if>
3016cite {
3017  font-style: normal;
3018}<xsl:if test="//x:note">
3019div.note {
3020  margin-left: 2em;
3021}</xsl:if>
3022dd {
3023  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
3024  text-align: justify;</xsl:if>
3025}
3026dl {
3027  margin-left: 2em;
3028}
3029<!-- spacing between two entries in definition lists -->
3030ul.empty {
3031  list-style-type: none;
3032}
3033ul.empty li {
3034  margin-top: .5em;
3035}
3036dl p {
3037  margin-left: 0em;
3038}
3039dt {
3040  margin-top: .5em;
3041}
3042h1 {
3043  font-size: 14pt;
3044  line-height: 21pt;
3045  page-break-after: avoid;
3046}
3047h1.np {
3048  page-break-before: always;
3049}
3050h1 a {
3051  color: #333333;
3052}
3053h2 {
3054  font-size: 12pt;
3055  line-height: 15pt;
3056  page-break-after: avoid;
3057}
3058h3, h4, h5, h6 {
3059  font-size: 10pt;
3060  page-break-after: avoid;
3061}
3062h2 a, h3 a, h4 a, h5 a, h6 a {
3063  color: black;
3064}
3065img {
3066  margin-left: 3em;
3067}
3068li {
3069  margin-left: 2em;
3070  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
3071  text-align: justify;</xsl:if>
3072}
3073ol {
3074  margin-left: 2em;
3075  margin-right: 2em;
3076}
3077ol p {
3078  margin-left: 0em;
3079}<xsl:if test="//xhtml:q">
3080q {
3081  font-style: italic;
3082}</xsl:if>
3083p {
3084  margin-left: 2em;
3085  margin-right: 2em;<xsl:if test="$xml2rfc-ext-justification='always'">
3086  text-align: justify;</xsl:if>
3087}
3088pre {
3089  margin-left: 3em;
3090  background-color: lightyellow;
3091  padding: .25em;
3092}<xsl:if test="//artwork[@x:isCodeComponent='yes']"><!-- support "<CODE BEGINS>" and "<CODE ENDS>" markers-->
3093pre.ccmarker {
3094  background-color: white;
3095  color: gray;
3096}
3097pre.ccmarker > span {
3098  font-size: small;
3099}
3100pre.cct {
3101  margin-bottom: -1em;
3102}
3103pre.ccb {
3104  margin-top: -1em;
3105}</xsl:if>
3106pre.text2 {
3107  border-style: dotted;
3108  border-width: 1px;
3109  background-color: #f0f0f0;
3110  width: 69em;
3111}
3112pre.inline {
3113  background-color: white;
3114  padding: 0em;
3115}
3116pre.text {
3117  border-style: dotted;
3118  border-width: 1px;
3119  background-color: #f8f8f8;
3120  width: 69em;
3121}
3122pre.drawing {
3123  border-style: solid;
3124  border-width: 1px;
3125  background-color: #f8f8f8;
3126  padding: 2em;
3127}<xsl:if test="//x:q">
3128q {
3129  font-style: italic;
3130}</xsl:if>
3131<xsl:if test="//x:sup">
3132sup {
3133  font-size: 60%;
3134}</xsl:if>
3135table {
3136  margin-left: 2em;
3137}<xsl:if test="//texttable">
3138table.tt {
3139  vertical-align: top;
3140}
3141table.full {
3142  border-style: outset;
3143  border-width: 1px;
3144}
3145table.headers {
3146  border-style: outset;
3147  border-width: 1px;
3148}
3149table.tt td {
3150  vertical-align: top;
3151}
3152table.full td {
3153  border-style: inset;
3154  border-width: 1px;
3155}
3156table.tt th {
3157  vertical-align: top;
3158}
3159table.full th {
3160  border-style: inset;
3161  border-width: 1px;
3162}
3163table.headers th {
3164  border-style: none none inset none;
3165  border-width: 1px;
3166}
3167table.left {
3168  margin-right: auto;
3169}
3170table.right {
3171  margin-left: auto;
3172}
3173table.center {
3174  margin-left: auto;
3175  margin-right: auto;
3176}
3177caption {
3178  caption-side: bottom;
3179  font-weight: bold;
3180  font-size: 9pt;
3181  margin-top: .5em;
3182}
3183</xsl:if>
3184table.header {
3185  border-spacing: 1px;
3186  width: 95%;
3187  font-size: 10pt;
3188  color: white;
3189}
3190td.top {
3191  vertical-align: top;
3192}
3193td.topnowrap {
3194  vertical-align: top;
3195  white-space: nowrap;
3196}
3197table.header td {
3198  background-color: gray;
3199  width: 50%;
3200}<xsl:if test="/rfc/@obsoletes | /rfc/@updates">
3201table.header a {
3202  color: white;
3203}</xsl:if>
3204td.reference {
3205  vertical-align: top;
3206  white-space: nowrap;
3207  padding-right: 1em;
3208}
3209thead {
3210  display:table-header-group;
3211}
3212ul.toc {
3213  list-style: none;
3214  margin-left: 1.5em;
3215  margin-right: 0em;
3216  padding-left: 0em;
3217}
3218li.tocline0 {
3219  line-height: 150%;
3220  font-weight: bold;
3221  font-size: 10pt;
3222  margin-left: 0em;
3223  margin-right: 0em;
3224}
3225li.tocline1 {
3226  line-height: normal;
3227  font-weight: normal;
3228  font-size: 9pt;
3229  margin-left: 0em;
3230  margin-right: 0em;
3231}
3232li.tocline2 {
3233  font-size: 0pt;
3234}
3235ul p {
3236  margin-left: 0em;
3237}
3238<xsl:if test="$has-index">ul.ind {
3239  list-style: none;
3240  margin-left: 1.5em;
3241  margin-right: 0em;
3242  padding-left: 0em;
3243  page-break-before: avoid;
3244}
3245li.indline0 {
3246  font-weight: bold;
3247  line-height: 200%;
3248  margin-left: 0em;
3249  margin-right: 0em;
3250}
3251li.indline1 {
3252  font-weight: normal;
3253  line-height: 150%;
3254  margin-left: 0em;
3255  margin-right: 0em;
3256}
3257.avoidbreak {
3258  page-break-inside: avoid;
3259}
3260</xsl:if><xsl:if test="//x:bcp14">.bcp14 {
3261  font-style: normal;
3262  text-transform: lowercase;
3263  font-variant: small-caps;
3264}</xsl:if><xsl:if test="//x:blockquote">
3265blockquote > * .bcp14 {
3266  font-style: italic;
3267}</xsl:if>
3268.comment {
3269  background-color: yellow;
3270}<xsl:if test="$xml2rfc-editing='yes'">
3271.editingmark {
3272  background-color: khaki;
3273}</xsl:if>
3274.center {
3275  text-align: center;
3276}
3277.error {
3278  color: red;
3279  font-style: italic;
3280  font-weight: bold;
3281}
3282.figure {
3283  font-weight: bold;
3284  text-align: center;
3285  font-size: 9pt;
3286}
3287.filename {
3288  color: #333333;
3289  font-weight: bold;
3290  font-size: 12pt;
3291  line-height: 21pt;
3292  text-align: center;
3293}
3294.fn {
3295  font-weight: bold;
3296}
3297.hidden {
3298  display: none;
3299}
3300.left {
3301  text-align: left;
3302}
3303.right {
3304  text-align: right;
3305}
3306.title {
3307  color: #990000;
3308  font-size: 18pt;
3309  line-height: 18pt;
3310  font-weight: bold;
3311  text-align: center;
3312  margin-top: 36pt;
3313}
3314.vcardline {
3315  display: block;
3316}
3317.warning {
3318  font-size: 14pt;
3319  background-color: yellow;
3320}
3321<xsl:if test="$has-edits">del {
3322  color: red;
3323  text-decoration: line-through;
3324}
3325.del {
3326  color: red;
3327  text-decoration: line-through;
3328}
3329ins {
3330  color: green;
3331  text-decoration: underline;
3332}
3333.ins {
3334  color: green;
3335  text-decoration: underline;
3336}
3337div.issuepointer {
3338  float: left;
3339}</xsl:if><xsl:if test="//ed:issue">
3340table.openissue {
3341  background-color: khaki;
3342  border-width: thin;
3343  border-style: solid;
3344  border-color: black;
3345}
3346table.closedissue {
3347  background-color: white;
3348  border-width: thin;
3349  border-style: solid;
3350  border-color: gray;
3351  color: gray;
3352}
3353thead th {
3354  text-align: left;
3355}
3356.bg-issue {
3357  border: solid;
3358  border-width: 1px;
3359  font-size: 7pt;
3360}
3361.closed-issue {
3362  border: solid;
3363  border-width: thin;
3364  background-color: lime;
3365  font-size: smaller;
3366  font-weight: bold;
3367}
3368.open-issue {
3369  border: solid;
3370  border-width: thin;
3371  background-color: red;
3372  font-size: smaller;
3373  font-weight: bold;
3374}
3375.editor-issue {
3376  border: solid;
3377  border-width: thin;
3378  background-color: yellow;
3379  font-size: smaller;
3380  font-weight: bold;
3381}</xsl:if>
3382
3383@media print {
3384  .noprint {
3385    display: none;
3386  }
3387 
3388  a {
3389    color: black;
3390    text-decoration: none;
3391  }
3392
3393  table.header {
3394    width: 90%;
3395  }
3396
3397  td.header {
3398    width: 50%;
3399    color: black;
3400    background-color: white;
3401    vertical-align: top;
3402    font-size: 12pt;
3403  }
3404
3405  ul.toc a::after {
3406    content: leader('.') target-counter(attr(href), page);
3407  }
3408 
3409  a.iref {
3410    content: target-counter(attr(href), page);
3411  }
3412 
3413  .print2col {
3414    column-count: 2;
3415    -moz-column-count: 2;<!-- for Firefox -->
3416    column-fill: auto;<!-- for PrinceXML -->
3417  }
3418<xsl:if test="$xml2rfc-ext-justification='print'">
3419  dd {
3420    text-align: justify;
3421  }
3422  li {
3423    text-align: justify;
3424  }
3425  p {
3426    text-align: justify;
3427  }
3428</xsl:if>}
3429<xsl:choose><xsl:when test="$xml2rfc-ext-duplex='yes'">
3430@page:right {
3431  @top-left {
3432       content: "<xsl:call-template name="get-header-left"/>";
3433  }
3434  @top-right {
3435       content: "<xsl:call-template name="get-header-right"/>";
3436  }
3437  @top-center {
3438       content: "<xsl:call-template name="get-header-center"/>";
3439  }
3440  @bottom-left {
3441       content: "<xsl:call-template name="get-author-summary"/>";
3442  }
3443  @bottom-center {
3444       content: "<xsl:call-template name="get-category-long"/>";
3445  }
3446  @bottom-right {
3447       content: "[Page " counter(page) "]";
3448  }
3449}
3450@page:left {
3451  @top-left {
3452       content: "<xsl:call-template name="get-header-right"/>";
3453  }
3454  @top-right {
3455       content: "<xsl:call-template name="get-header-left"/>";
3456  }
3457  @top-center {
3458       content: "<xsl:call-template name="get-header-center"/>";
3459  }
3460  @bottom-left {
3461       content: "[Page " counter(page) "]";
3462  }
3463  @bottom-center {
3464       content: "<xsl:call-template name="get-category-long"/>";
3465  }
3466  @bottom-right {
3467       content: "<xsl:call-template name="get-author-summary"/>";
3468  }
3469}
3470</xsl:when><xsl:otherwise>
3471@page {
3472  @top-left {
3473       content: "<xsl:call-template name="get-header-left"/>";
3474  }
3475  @top-right {
3476       content: "<xsl:call-template name="get-header-right"/>";
3477  }
3478  @top-center {
3479       content: "<xsl:call-template name="get-header-center"/>";
3480  }
3481  @bottom-left {
3482       content: "<xsl:call-template name="get-author-summary"/>";
3483  }
3484  @bottom-center {
3485       content: "<xsl:call-template name="get-category-long"/>";
3486  }
3487  @bottom-right {
3488       content: "[Page " counter(page) "]";
3489  }
3490}
3491</xsl:otherwise></xsl:choose>
3492@page:first {
3493    @top-left {
3494      content: normal;
3495    }
3496    @top-right {
3497      content: normal;
3498    }
3499    @top-center {
3500      content: normal;
3501    }
3502}
3503</style>
3504</xsl:template>
3505
3506
3507<!-- generate the index section -->
3508
3509<xsl:template name="insertSingleIref">
3510  <xsl:choose>
3511    <xsl:when test="@ed:xref">
3512      <!-- special index generator mode -->
3513      <xsl:text>[</xsl:text>
3514      <a href="#{@ed:xref}"><xsl:value-of select="@ed:xref"/></a>
3515      <xsl:text>, </xsl:text>
3516      <a>
3517        <xsl:variable name="htmluri" select="//reference[@anchor=current()/@ed:xref]/format[@type='HTML']/@target"/>
3518        <xsl:if test="$htmluri">
3519          <xsl:attribute name="href"><xsl:value-of select="concat($htmluri,'#',@ed:frag)"/></xsl:attribute>
3520        </xsl:if>       
3521        <xsl:choose>
3522          <xsl:when test="@primary='true'"><b><xsl:value-of select="@ed:label" /></b></xsl:when>
3523          <xsl:otherwise><xsl:value-of select="@ed:label" /></xsl:otherwise>
3524        </xsl:choose>
3525      </a>
3526      <xsl:text>]</xsl:text>
3527      <xsl:if test="position()!=last()">, </xsl:if>
3528    </xsl:when>
3529    <xsl:otherwise>
3530      <xsl:variable name="_n">
3531        <xsl:call-template name="get-section-number" />
3532      </xsl:variable>
3533      <xsl:variable name="n">
3534        <xsl:choose>
3535          <xsl:when test="$_n!=''">
3536            <xsl:value-of select="$_n"/>
3537          </xsl:when>
3538          <xsl:otherwise>&#167;</xsl:otherwise>
3539        </xsl:choose>
3540      </xsl:variable>
3541      <xsl:variable name="backlink">
3542        <xsl:choose>
3543          <xsl:when test="self::xref">
3544            <xsl:variable name="target" select="@target"/>
3545            <xsl:text>#</xsl:text>
3546            <xsl:value-of select="$anchor-prefix"/>
3547            <xsl:text>.xref.</xsl:text>
3548            <xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/>
3549          </xsl:when>
3550          <xsl:when test="self::iref">
3551            <xsl:text>#</xsl:text>
3552            <xsl:call-template name="compute-iref-anchor"/>
3553          </xsl:when>
3554          <xsl:when test="self::x:ref">
3555            <xsl:text>#</xsl:text>
3556            <xsl:call-template name="compute-extref-anchor"/>
3557          </xsl:when>
3558          <xsl:otherwise>
3559            <xsl:message>Unsupported element type for insertSingleIref</xsl:message>
3560          </xsl:otherwise>
3561        </xsl:choose>
3562      </xsl:variable>
3563      <a class="iref" href="{$backlink}">
3564        <xsl:call-template name="insertInsDelClass"/>
3565        <xsl:choose>
3566          <xsl:when test="@primary='true'"><b><xsl:value-of select="$n"/></b></xsl:when>
3567          <xsl:otherwise><xsl:value-of select="$n"/></xsl:otherwise>
3568        </xsl:choose>
3569      </a>
3570      <xsl:if test="position()!=last()">, </xsl:if>
3571    </xsl:otherwise>
3572  </xsl:choose>
3573</xsl:template>
3574
3575<xsl:template name="insertSingleXref">
3576  <xsl:variable name="_n">
3577    <xsl:call-template name="get-section-number" />
3578  </xsl:variable>
3579  <xsl:variable name="n">
3580    <xsl:choose>
3581      <xsl:when test="$_n!=''">
3582        <xsl:value-of select="$_n"/>
3583      </xsl:when>
3584      <xsl:otherwise>&#167;</xsl:otherwise>
3585    </xsl:choose>
3586  </xsl:variable>
3587  <xsl:choose>
3588    <xsl:when test="self::reference">
3589      <a class="iref" href="#{@anchor}">
3590        <xsl:call-template name="insertInsDelClass"/>
3591        <b><xsl:value-of select="$n"/></b>
3592      </a>
3593    </xsl:when>
3594    <xsl:otherwise>
3595      <xsl:variable name="target" select="@target"/>
3596      <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>
3597      <a class="iref" href="{$backlink}">
3598        <xsl:call-template name="insertInsDelClass"/>
3599        <xsl:value-of select="$n"/>
3600      </a>
3601    </xsl:otherwise>
3602  </xsl:choose>
3603  <xsl:if test="position()!=last()">, </xsl:if>
3604</xsl:template>
3605
3606<xsl:template name="insertIndex">
3607
3608  <xsl:call-template name="insert-conditional-hrule"/>
3609
3610  <h1 id="{$anchor-prefix}.index">
3611    <xsl:call-template name="insert-conditional-pagebreak"/>
3612    <a href="#{$anchor-prefix}.index">Index</a>
3613  </h1>
3614 
3615  <!-- generate navigation links to index subsections -->
3616  <p class="noprint">
3617    <xsl:variable name="irefs" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
3618    <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)))]"/>
3619 
3620    <xsl:for-each select="$irefs | $xrefs">
3621   
3622      <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)" />
3623         
3624      <xsl:variable name="letter" select="translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase)"/>
3625
3626      <!-- character? -->
3627      <xsl:if test="translate($letter,concat($lcase,$ucase,'0123456789'),'')=''">
3628     
3629        <xsl:variable name="showit">
3630          <xsl:choose>
3631            <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
3632              <xsl:if test="$irefs[starts-with(translate(@item,$lcase,$ucase),$letter)]">
3633                <xsl:text>yes</xsl:text>
3634              </xsl:if>
3635            </xsl:when>
3636            <xsl:otherwise>
3637              <xsl:text>yes</xsl:text>
3638            </xsl:otherwise>
3639          </xsl:choose>
3640        </xsl:variable>
3641       
3642        <xsl:if test="$showit='yes'">
3643          <a href="#{$anchor-prefix}.index.{$letter}">
3644            <xsl:value-of select="$letter" />
3645          </a>
3646          <xsl:text> </xsl:text>
3647        </xsl:if>
3648     
3649      </xsl:if>
3650
3651    </xsl:for-each>
3652  </p>
3653
3654  <!-- for each index subsection -->
3655  <div class="print2col">
3656  <ul class="ind">
3657    <xsl:variable name="irefs2" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
3658    <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)))]"/>
3659 
3660    <xsl:for-each select="$irefs2 | $xrefs2">
3661      <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)" />
3662      <xsl:variable name="letter" select="translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase)"/>
3663           
3664      <xsl:variable name="showit">
3665        <xsl:choose>
3666          <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
3667            <xsl:if test="$irefs2[starts-with(translate(@item,$lcase,$ucase),$letter)]">
3668              <xsl:text>yes</xsl:text>
3669            </xsl:if>
3670          </xsl:when>
3671          <xsl:otherwise>
3672            <xsl:text>yes</xsl:text>
3673          </xsl:otherwise>
3674        </xsl:choose>
3675      </xsl:variable>
3676
3677      <xsl:if test="$showit='yes'">
3678        <li class="indline0">
3679         
3680          <!-- make letters and digits stand out -->
3681          <xsl:choose>
3682            <xsl:when test="translate($letter,concat($lcase,$ucase,'0123456789'),'')=''">
3683              <a id="{$anchor-prefix}.index.{$letter}" href="#{$anchor-prefix}.index.{$letter}">
3684                <b><xsl:value-of select="$letter" /></b>
3685              </a>
3686            </xsl:when>
3687            <xsl:otherwise>
3688              <b><xsl:value-of select="$letter" /></b>
3689            </xsl:otherwise>
3690          </xsl:choose>
3691       
3692          <ul class="ind"> 
3693            <xsl:for-each select="key('index-first-letter',translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase))">
3694       
3695              <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)" />
3696             
3697                <xsl:choose>
3698                  <xsl:when test="self::reference">
3699                    <xsl:if test="$xml2rfc-ext-include-references-in-index='yes' and not(starts-with(@anchor,'deleted-'))">
3700                      <li class="indline1">
3701                        <em>
3702                          <xsl:value-of select="@anchor"/>
3703                        </em>
3704                        <xsl:text>&#160;&#160;</xsl:text>
3705                       
3706                        <xsl:variable name="rs" select="key('xref-item',current()/@anchor) | . | key('anchor-item',concat('deleted-',current()/@anchor))"/>
3707                       
3708                        <xsl:for-each select="$rs">
3709                          <xsl:call-template name="insertSingleXref" />
3710                        </xsl:for-each>
3711
3712                        <xsl:variable name="rs2" select="$rs[@x:sec]"/>
3713
3714                        <xsl:if test="$rs2">
3715                          <ul class="ind"> 
3716                            <xsl:for-each select="$rs2">
3717                              <xsl:sort select="substring-before(concat(@x:sec,'.'),'.')" data-type="number"/>
3718                              <xsl:sort select="substring(@x:sec,2+string-length(substring-before(@x:sec,'.')))" data-type="number"/>
3719                              <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-sec',concat(@target,'..',@x:sec)))">
3720                                <li class="indline1">
3721                                  <em>
3722                                    <xsl:choose>
3723                                      <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
3724                                        <xsl:text>Appendix </xsl:text>
3725                                      </xsl:when>
3726                                      <xsl:otherwise>
3727                                        <xsl:text>Section </xsl:text>
3728                                      </xsl:otherwise>
3729                                    </xsl:choose>
3730                                    <xsl:value-of select="@x:sec"/>
3731                                  </em>
3732                                  <xsl:text>&#160;&#160;</xsl:text>
3733                                  <xsl:for-each select="key('index-xref-by-sec',concat(@target,'..',@x:sec))">
3734                                    <xsl:call-template name="insertSingleXref" />
3735                                  </xsl:for-each>
3736                                </li>
3737                              </xsl:if>
3738                            </xsl:for-each>
3739                          </ul>
3740                        </xsl:if>
3741
3742                        <xsl:if test="current()/x:source/@href">
3743                          <xsl:variable name="rs3" select="$rs[not(@x:sec) and @x:rel]"/>
3744                          <xsl:variable name="doc" select="document(current()/x:source/@href)"/>
3745                          <xsl:if test="$rs3">
3746                            <ul class="ind"> 
3747                              <xsl:for-each select="$rs3">
3748                                <xsl:sort select="count($doc//*[@anchor and following::*/@anchor=substring-after(current()/@x:rel,'#')])" order="ascending" data-type="number"/>
3749                                <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-anchor',concat(@target,'..',@x:rel)))">
3750                                  <li class="indline1">
3751                                    <em>
3752                                      <xsl:variable name="sec">
3753                                        <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
3754                                          <xsl:call-template name="get-section-number"/>
3755                                        </xsl:for-each>
3756                                      </xsl:variable>
3757                                      <xsl:choose>
3758                                        <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
3759                                          <xsl:text>Appendix </xsl:text>
3760                                        </xsl:when>
3761                                        <xsl:otherwise>
3762                                          <xsl:text>Section </xsl:text>
3763                                        </xsl:otherwise>
3764                                      </xsl:choose>
3765                                      <xsl:value-of select="$sec"/>
3766                                    </em>
3767                                    <xsl:text>&#160;&#160;</xsl:text>
3768                                    <xsl:for-each select="key('index-xref-by-anchor',concat(@target,'..',@x:rel))">
3769                                      <xsl:call-template name="insertSingleXref" />
3770                                    </xsl:for-each>
3771                                  </li>
3772                                </xsl:if>
3773                              </xsl:for-each>
3774                            </ul>
3775                          </xsl:if>
3776                        </xsl:if>
3777                      </li>
3778                    </xsl:if>
3779                  </xsl:when>
3780                  <xsl:otherwise>
3781                    <!-- regular iref -->
3782                    <xsl:if test="generate-id(.) = generate-id(key('index-item',concat(@item,@anchor)))">
3783                      <xsl:variable name="item" select="@item"/>
3784                      <xsl:variable name="in-artwork" select="key('index-item',$item)[@primary='true' and ancestor::artwork]"/>
3785                         
3786                      <li class="indline1">
3787                        <xsl:choose>
3788                          <xsl:when test="$in-artwork">
3789                            <tt><xsl:value-of select="@item" /></tt>
3790                          </xsl:when>
3791                          <xsl:otherwise>
3792                            <xsl:value-of select="@item" />
3793                          </xsl:otherwise>
3794                        </xsl:choose>
3795                        <xsl:text>&#160;&#160;</xsl:text>
3796                       
3797                        <xsl:variable name="irefs3" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
3798                        <xsl:variable name="xrefs3" select="key('xref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs3/@x:for-anchor)"/>
3799                        <xsl:variable name="extrefs3" select="key('extref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs3/@x:for-anchor)"/>
3800
3801                        <xsl:for-each select="$irefs3|$xrefs3|$extrefs3">
3802                          <!-- <xsl:sort select="translate(@item,$lcase,$ucase)" />  -->
3803                          <xsl:call-template name="insertSingleIref" />
3804                        </xsl:for-each>
3805         
3806                        <xsl:variable name="s2" select="key('index-item',@item)[@subitem and @subitem!='']"/>
3807                        <xsl:if test="$s2">
3808                          <ul class="ind"> 
3809                            <xsl:for-each select="$s2">
3810                              <xsl:sort select="translate(@subitem,$lcase,$ucase)" />
3811                             
3812                              <xsl:if test="generate-id(.) = generate-id(key('index-item-subitem',concat(@item,'..',@subitem)))">
3813                 
3814                                <xsl:variable name="in-artwork2" select="key('index-item-subitem',concat(@item,'..',@subitem))[@primary='true' and ancestor::artwork]" />
3815                 
3816                                <li class="indline1">
3817             
3818                                  <xsl:choose>
3819                                    <xsl:when test="$in-artwork2">
3820                                      <tt><xsl:value-of select="@subitem" /></tt>
3821                                    </xsl:when>
3822                                    <xsl:otherwise>
3823                                      <xsl:value-of select="@subitem" />
3824                                    </xsl:otherwise>
3825                                  </xsl:choose>
3826                                  <xsl:text>&#160;&#160;</xsl:text>
3827                                   
3828                                  <xsl:variable name="irefs4" select="key('index-item-subitem',concat(@item,'..',@subitem))"/>
3829                                  <xsl:variable name="xrefs4" select="key('xref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs4/@x:for-anchor)"/>
3830                                  <xsl:variable name="extrefs4" select="key('extref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs4/@x:for-anchor)"/>
3831
3832                                  <xsl:for-each select="$irefs4|$xrefs4|$extrefs4">
3833                                    <!--<xsl:sort select="translate(@item,$lcase,$ucase)" />-->                   
3834                                    <xsl:call-template name="insertSingleIref" />
3835                                  </xsl:for-each>
3836               
3837                                </li>
3838                              </xsl:if>
3839                            </xsl:for-each>
3840                          </ul>
3841                        </xsl:if>
3842                      </li>
3843                    </xsl:if>
3844                  </xsl:otherwise>
3845                </xsl:choose>
3846             
3847                     
3848            </xsl:for-each>           
3849          </ul>
3850        </li>
3851      </xsl:if>
3852     
3853    </xsl:for-each>
3854  </ul>
3855  </div>
3856 
3857</xsl:template>
3858
3859<xsl:template name="insertPreamble" myns:namespaceless-elements="xml2rfc">
3860
3861  <xsl:variable name="escapeclause">
3862    This document may contain material from IETF Documents or IETF Contributions published or
3863    made publicly available before November 10, 2008. The person(s) controlling the copyright in
3864    some of this material may not have granted the IETF Trust the right to allow modifications of such
3865    material outside the IETF Standards Process. Without obtaining an adequate license from the
3866    person(s) controlling the copyright in such materials, this document may not be modified outside
3867    the IETF Standards Process, and derivative works of it may not be created outside the IETF
3868    Standards Process, except to format it for publication as an RFC or to translate it into languages
3869    other than English.
3870  </xsl:variable>
3871
3872  <section myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.status">
3873  <xsl:attribute name="title">
3874    <xsl:choose>
3875      <xsl:when test="$xml2rfc-rfcedstyle='yes'">Status of This Memo</xsl:when>
3876      <xsl:otherwise>Status of this Memo</xsl:otherwise>
3877    </xsl:choose>
3878  </xsl:attribute>
3879
3880  <xsl:choose>
3881    <xsl:when test="/rfc/@ipr and not(/rfc/@number)">
3882      <t>
3883        <xsl:choose>
3884         
3885          <!-- RFC2026 -->
3886          <xsl:when test="/rfc/@ipr = 'full2026'">
3887            This document is an Internet-Draft and is
3888            in full conformance with all provisions of Section 10 of RFC2026.   
3889          </xsl:when>
3890          <xsl:when test="/rfc/@ipr = 'noDerivativeWorks2026'">
3891            This document is an Internet-Draft and is
3892            in full conformance with all provisions of Section 10 of RFC2026
3893            except that the right to produce derivative works is not granted.   
3894          </xsl:when>
3895          <xsl:when test="/rfc/@ipr = 'noDerivativeWorksNow'">
3896            This document is an Internet-Draft and is
3897            in full conformance with all provisions of Section 10 of RFC2026
3898            except that the right to produce derivative works is not granted.
3899            (If this document becomes part of an IETF working group activity,
3900            then it will be brought into full compliance with Section 10 of RFC2026.) 
3901          </xsl:when>
3902          <xsl:when test="/rfc/@ipr = 'none'">
3903            This document is an Internet-Draft and is
3904            NOT offered in accordance with Section 10 of RFC2026,
3905            and the author does not provide the IETF with any rights other
3906            than to publish as an Internet-Draft.
3907          </xsl:when>
3908         
3909          <!-- RFC3667 -->
3910          <xsl:when test="/rfc/@ipr = 'full3667'">
3911            This document is an Internet-Draft and is subject to all provisions
3912            of section 3 of RFC 3667.  By submitting this Internet-Draft, each
3913            author represents that any applicable patent or other IPR claims of
3914            which he or she is aware have been or will be disclosed, and any of
3915            which he or she become aware will be disclosed, in accordance with
3916            RFC 3668.
3917          </xsl:when>
3918          <xsl:when test="/rfc/@ipr = 'noModification3667'">
3919            This document is an Internet-Draft and is subject to all provisions
3920            of section 3 of RFC 3667.  By submitting this Internet-Draft, each
3921            author represents that any applicable patent or other IPR claims of
3922            which he or she is aware have been or will be disclosed, and any of
3923            which he or she become aware will be disclosed, in accordance with
3924            RFC 3668.  This document may not be modified, and derivative works of
3925            it may not be created, except to publish it as an RFC and to
3926            translate it into languages other than English<xsl:if test="/rfc/@iprExtract">,
3927            other than to extract <xref target="{/rfc/@iprExtract}"/> as-is
3928            for separate use</xsl:if>.
3929          </xsl:when>
3930          <xsl:when test="/rfc/@ipr = 'noDerivatives3667'">
3931            This document is an Internet-Draft and is subject to all provisions
3932            of section 3 of RFC 3667 except for the right to produce derivative
3933            works.  By submitting this Internet-Draft, each author represents
3934            that any applicable patent or other IPR claims of which he or she
3935            is aware have been or will be disclosed, and any of which he or she
3936            become aware will be disclosed, in accordance with RFC 3668.  This
3937            document may not be modified, and derivative works of it may
3938            not be created<xsl:if test="/rfc/@iprExtract">, other than to extract
3939            <xref target="{/rfc/@iprExtract}"/> as-is for separate use</xsl:if>.
3940          </xsl:when>
3941         
3942          <!-- RFC3978 -->
3943          <xsl:when test="/rfc/@ipr = 'full3978'">
3944            By submitting this Internet-Draft, each
3945            author represents that any applicable patent or other IPR claims of
3946            which he or she is aware have been or will be disclosed, and any of
3947            which he or she becomes aware will be disclosed, in accordance with
3948            Section 6 of BCP 79.
3949          </xsl:when>
3950          <xsl:when test="/rfc/@ipr = 'noModification3978'">
3951            By submitting this Internet-Draft, each
3952            author represents that any applicable patent or other IPR claims of
3953            which he or she is aware have been or will be disclosed, and any of
3954            which he or she becomes aware will be disclosed, in accordance with
3955            Section 6 of BCP 79.  This document may not be modified, and derivative works of
3956            it may not be created, except to publish it as an RFC and to
3957            translate it into languages other than English<xsl:if test="/rfc/@iprExtract">,
3958            other than to extract <xref target="{/rfc/@iprExtract}"/> as-is
3959            for separate use</xsl:if>.
3960          </xsl:when>
3961          <xsl:when test="/rfc/@ipr = 'noDerivatives3978'">
3962            By submitting this Internet-Draft, each author represents
3963            that any applicable patent or other IPR claims of which he or she
3964            is aware have been or will be disclosed, and any of which he or she
3965            becomes aware will be disclosed, in accordance with Section 6 of BCP 79.  This
3966            document may not be modified, and derivative works of it may
3967            not be created<xsl:if test="/rfc/@iprExtract">, other than to extract
3968            <xref target="{/rfc/@iprExtract}"/> as-is for separate use</xsl:if>.
3969          </xsl:when>
3970 
3971          <!-- as of Nov 2008, Feb 2009 and Sep 2009 -->
3972          <xsl:when test="/rfc/@ipr = 'trust200811'
3973                          or /rfc/@ipr = 'noModificationTrust200811'
3974                          or /rfc/@ipr = 'noDerivativesTrust200811'
3975                          or /rfc/@ipr = 'trust200902'
3976                          or /rfc/@ipr = 'noModificationTrust200902'
3977                          or /rfc/@ipr = 'noDerivativesTrust200902'
3978                          or /rfc/@ipr = 'pre5378Trust200902'">
3979            This Internet-Draft is submitted to IETF in full conformance with
3980            the provisions of BCP 78 and BCP 79.
3981          </xsl:when>
3982          <xsl:otherwise>
3983            CONFORMANCE UNDEFINED.
3984          </xsl:otherwise>
3985        </xsl:choose>
3986       
3987        <!-- restrictions -->
3988        <xsl:choose>
3989          <xsl:when test="/rfc/@ipr = 'noModificationTrust200811'">
3990            This document may not be modified, and derivative works of it may
3991            not be created, except to format it for publication as an RFC and
3992            to translate it into languages other than English.
3993          </xsl:when>
3994          <xsl:when test="/rfc/@ipr = 'noDerivativesTrust200811'">
3995            This document may not be modified, and derivative works of it may
3996            not be created, and it may not be published except as an Internet-Draft.
3997          </xsl:when>
3998          <xsl:when test="/rfc/@ipr = 'noModificationTrust200902'">
3999            This document may not be modified, and derivative works of it may
4000            not be created, except to format it for publication as an RFC or
4001            to translate it into languages other than English.
4002          </xsl:when>
4003          <xsl:when test="/rfc/@ipr = 'noDerivativesTrust200902'">
4004            This document may not be modified, and derivative works of it may
4005            not be created, and it may not be published except as an Internet-Draft.
4006          </xsl:when>
4007          <!-- escape clause moved to Copyright Notice as of 2009-11 -->
4008          <xsl:when test="/rfc/@ipr = 'pre5378Trust200902' and $pub-yearmonth &lt; 200911">
4009            <xsl:value-of select="$escapeclause"/>
4010          </xsl:when>
4011
4012          <xsl:otherwise />
4013        </xsl:choose>
4014      </t>
4015      <t>
4016        Internet-Drafts are working documents of the Internet Engineering
4017        Task Force (IETF), its areas, and its working groups.
4018        Note that other groups may also distribute working documents as
4019        Internet-Drafts.
4020      </t>
4021      <t>
4022        Internet-Drafts are draft documents valid for a maximum of six months
4023        and may be updated, replaced, or obsoleted by other documents at any time.
4024        It is inappropriate to use Internet-Drafts as reference material or to cite
4025        them other than as &#8220;work in progress&#8221;.
4026      </t>
4027      <t>
4028        The list of current Internet-Drafts can be accessed at
4029        <eref target='http://www.ietf.org/ietf/1id-abstracts.txt'/>.
4030      </t>
4031      <t>
4032        The list of Internet-Draft Shadow Directories can be accessed at
4033        <eref target='http://www.ietf.org/shadow.html'/>.
4034      </t>
4035      <t>
4036        This Internet-Draft will expire in <xsl:call-template name="expirydate" />.
4037      </t>
4038    </xsl:when>
4039
4040    <xsl:when test="/rfc/@category='bcp' and $xml2rfc-ext-hab='yes'">
4041      <t>
4042        This memo documents an Internet Best Current Practice.
4043      </t>
4044    </xsl:when>
4045    <xsl:when test="/rfc/@category='bcp'">
4046      <t>
4047        This document specifies an Internet Best Current Practices for the Internet
4048        Community, and requests discussion and suggestions for improvements.
4049        Distribution of this memo is unlimited.
4050      </t>
4051    </xsl:when>
4052    <xsl:when test="/rfc/@category='exp' and $xml2rfc-ext-hab='yes'">
4053      <t>
4054        This document is not an Internet Standards Track specification; it is
4055        published for examination, experimental implementation, and evaluation.
4056      </t>
4057    </xsl:when>
4058    <xsl:when test="/rfc/@category='exp'">
4059      <t>
4060        This memo defines an Experimental Protocol for the Internet community.
4061        It does not specify an Internet standard of any kind.
4062        Discussion and suggestions for improvement are requested.
4063        Distribution of this memo is unlimited.
4064      </t>
4065    </xsl:when>
4066    <xsl:when test="/rfc/@category='historic' and $xml2rfc-ext-hab='yes'">
4067      <t>
4068        This document is not an Internet Standards Track specification; it is
4069        published for the historical record.
4070      </t>
4071    </xsl:when>
4072    <xsl:when test="/rfc/@category='historic'">
4073      <t>
4074        This memo describes a historic protocol for the Internet community.
4075        It does not specify an Internet standard of any kind.
4076        Distribution of this memo is unlimited.
4077      </t>
4078    </xsl:when>
4079    <xsl:when test="/rfc/@category='std' and $xml2rfc-ext-hab='yes'">
4080      <t>
4081        This is an Internet Standards Track document.
4082      </t>
4083    </xsl:when>
4084    <xsl:when test="/rfc/@category='std'">
4085      <t>
4086        This document specifies an Internet standards track protocol for the Internet
4087        community, and requests discussion and suggestions for improvements.
4088        Please refer to the current edition of the &#8220;Internet Official Protocol
4089        Standards&#8221; (STD 1) for the standardization state and status of this
4090        protocol. Distribution of this memo is unlimited.
4091      </t>
4092    </xsl:when>
4093    <xsl:when test="(/rfc/@category='info' or not(/rfc/@category)) and $xml2rfc-ext-hab='yes'">
4094      <t>
4095        This document is not an Internet Standards Track specification; it is
4096        published for informational purposes.
4097      </t>
4098    </xsl:when>
4099    <xsl:when test="/rfc/@category='info' or not(/rfc/@category)">
4100      <t>
4101        This memo provides information for the Internet community.
4102        It does not specify an Internet standard of any kind.
4103        Distribution of this memo is unlimited.
4104      </t>
4105    </xsl:when>
4106    <xsl:otherwise>
4107      <t>
4108        UNSUPPORTED CATEGORY.
4109      </t>
4110      <xsl:call-template name="error">
4111        <xsl:with-param name="msg" select="concat('Unsupported value for /rfc/@category: ', /rfc/@category)"/>
4112        <xsl:with-param name="inline" select="'no'"/>
4113      </xsl:call-template>
4114    </xsl:otherwise>
4115  </xsl:choose>
4116   
4117  <!-- 2nd and 3rd paragraph -->
4118  <xsl:if test="$xml2rfc-ext-hab='yes'">
4119    <t>
4120      <xsl:if test="/rfc/@category='exp'">
4121        This document defines an Experimental Protocol for the Internet
4122        community.
4123      </xsl:if>
4124      <xsl:if test="/rfc/@category='historic'">
4125        This document defines a Historic Document for the Internet community.
4126      </xsl:if>
4127      <xsl:choose>
4128        <xsl:when test="$submissionType='IETF'">
4129          This document is a product of the Internet Engineering Task Force
4130          (IETF).
4131          <xsl:choose>
4132            <xsl:when test="$xml2rfc-ext-consensus='yes'">
4133              It represents the consensus of the IETF community.  It has
4134              received public review and has been approved for publication by
4135              the Internet Engineering Steering Group (IESG).
4136            </xsl:when>
4137            <xsl:otherwise>
4138              It has been approved for publication by the Internet Engineering
4139              Steering Group (IESG).
4140            </xsl:otherwise>
4141          </xsl:choose>
4142        </xsl:when>
4143        <xsl:when test="$submissionType='IAB'">
4144          This document is a product of the Internet Architecture Board (IAB),
4145          and represents information that the IAB has deemed valuable to
4146          provide for permanent record.
4147        </xsl:when>
4148        <xsl:when test="$submissionType='IRTF'">
4149          <xsl:variable name="wg">
4150            <xsl:choose>
4151              <xsl:when test="/rfc/front/workgroup">
4152                <xsl:value-of select="/rfc/front/workgroup"/>
4153              </xsl:when>
4154              <xsl:otherwise>
4155                WORKGROUP INFO MISSING
4156                <xsl:call-template name="error">
4157                  <xsl:with-param name="msg" select="concat('Missing value for /rfc/front/workgroup: ', /rfc/front/workgroup)"/>
4158                  <xsl:with-param name="inline" select="'no'"/>
4159                </xsl:call-template>
4160              </xsl:otherwise>
4161            </xsl:choose>
4162          </xsl:variable>
4163         
4164          This document is a product of the Internet Research Task Force (IRTF).
4165          The IRTF publishes the results of Internet-related research and
4166          development activities.  These results might not be suitable for
4167          deployment.
4168          <xsl:choose>
4169            <xsl:when test="$xml2rfc-ext-consensus='yes'">
4170              This RFC represents the consensus of the
4171              <xsl:value-of select="$wg"/> Research Group of the Internet
4172              Research Task Force (IRTF).
4173            </xsl:when>
4174            <xsl:otherwise>
4175              This RFC represents the individual opinion(s) of one or more
4176              members of the <xsl:value-of select="$wg"/> Research Group of the
4177              Internet Research Task Force (IRTF).
4178            </xsl:otherwise>
4179          </xsl:choose>
4180        </xsl:when>
4181        <xsl:when test="$submissionType='independent'">
4182          This is a contribution to the RFC Series, independently of any other
4183          RFC stream.  The RFC Editor has chosen to publish this document at
4184          its discretion and makes no statement about its value for
4185          implementation or deployment.
4186        </xsl:when>
4187        <xsl:otherwise>
4188          <!-- will contain error message already -->
4189          <xsl:value-of select="$submissionType"/>
4190        </xsl:otherwise>
4191      </xsl:choose>
4192      <xsl:choose>
4193        <xsl:when test="$submissionType='IETF'">
4194          <xsl:choose>
4195            <xsl:when test="/rfc/@category='bcp'">
4196              Further information on BCPs is available in Section 2 of RFC XXXX.
4197            </xsl:when>
4198            <xsl:when test="/rfc/@category='std'">
4199              Further information on Internet Standards is available in Section
4200              2 of RFC XXXX.
4201            </xsl:when>
4202            <xsl:otherwise>
4203              Not all documents approved by the IESG are candidate for any
4204              level of Internet Standards; see Section 2 of RFC XXXX.
4205            </xsl:otherwise>
4206          </xsl:choose>
4207        </xsl:when>
4208        <xsl:otherwise>
4209          <xsl:variable name="approver">
4210            <xsl:choose>
4211              <xsl:when test="/rfc/@submissionType='IAB'">IAB</xsl:when>
4212              <xsl:when test="/rfc/@submissionType='IRTF'">IRSG</xsl:when>
4213              <xsl:otherwise>RFC Editor</xsl:otherwise>
4214            </xsl:choose>
4215          </xsl:variable>
4216       
4217          Documents approved for publication by the
4218          <xsl:value-of select="$approver"/> are not a candidate for any level
4219          of Internet Standard; see Section 2 of RFC XXXX.
4220        </xsl:otherwise>
4221      </xsl:choose>
4222    </t>
4223    <t>
4224      Information about the current status of this document, any errata, and
4225      how to provide feedback on it may be obtained at
4226      <eref target="http://www.rfc-editor.org/info/rfc{/rfc/@number}">http://www.rfc-editor.org/info/rfc<xsl:value-of select="/rfc/@number"/></eref>.
4227    </t>
4228  </xsl:if>
4229   
4230  </section>
4231 
4232  <xsl:choose>
4233    <xsl:when test="$ipr-2008-11">
4234      <section title="Copyright Notice" myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.copyrightnotice">
4235        <t>
4236          Copyright &#169; <xsl:value-of select="$xml2rfc-ext-pub-year" /> IETF Trust and the persons identified
4237          as the document authors.  All rights reserved.
4238        </t>
4239        <xsl:choose>
4240          <xsl:when test="$ipr-2009-09">
4241            <t>
4242              This document is subject to BCP 78 and the IETF Trust's Legal
4243              Provisions Relating to IETF Documents (<eref target="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</eref>)
4244              in effect on the date of publication of this document. Please
4245              review these documents carefully, as they describe your rights
4246              and restrictions with respect to this document. Code Components
4247              extracted from this document must include Simplified BSD License
4248              text as described in Section 4.e of the Trust Legal Provisions
4249              and are provided without warranty as described in the BSD License.
4250            </t>
4251          </xsl:when>
4252          <xsl:when test="$ipr-2009-02">
4253            <t>
4254              This document is subject to BCP 78 and the IETF Trust's Legal
4255              Provisions Relating to IETF Documents in effect on the date of
4256              publication of this document
4257              (<eref target="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</eref>).
4258              Please review these documents carefully, as they describe your rights and restrictions with
4259              respect to this document.
4260            </t>
4261          </xsl:when>
4262          <xsl:otherwise>
4263            <t>
4264              This document is subject to BCP 78 and the IETF Trust's Legal
4265              Provisions Relating to IETF Documents
4266              (<eref target="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</eref>) in effect on the date of
4267              publication of this document.  Please review these documents
4268              carefully, as they describe your rights and restrictions with respect
4269              to this document.
4270            </t>
4271          </xsl:otherwise>
4272        </xsl:choose>
4273       
4274        <!-- special case: RFC5378 escape applies to RFCs as well -->
4275        <!-- for IDs historically in Status Of This Memo, over here starting 2009-11 -->
4276        <xsl:if test="(/rfc/@number or $pub-yearmonth >= 200911) and /rfc/@ipr = 'pre5378Trust200902'">
4277          <t>
4278            <xsl:value-of select="$escapeclause"/>
4279          </t>
4280        </xsl:if>
4281       
4282      </section>
4283    </xsl:when>
4284    <xsl:when test="$ipr-2007-08">
4285      <!-- no copyright notice -->
4286    </xsl:when>
4287    <xsl:when test="$ipr-rfc4748">
4288      <section title="Copyright Notice" myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.copyrightnotice">
4289        <t>
4290          Copyright &#169; The IETF Trust (<xsl:value-of select="$xml2rfc-ext-pub-year" />).  All Rights Reserved.
4291        </t>
4292      </section>
4293    </xsl:when>
4294    <xsl:otherwise>
4295      <section title="Copyright Notice" myns:unnumbered="unnumbered" myns:notoclink="notoclink" anchor="{$anchor-prefix}.copyrightnotice">
4296        <t>
4297          Copyright &#169; The Internet Society (<xsl:value-of select="$xml2rfc-ext-pub-year" />).  All Rights Reserved.
4298        </t>
4299      </section>
4300    </xsl:otherwise>
4301  </xsl:choose>
4302 
4303</xsl:template>
4304
4305<!-- TOC generation -->
4306
4307<xsl:template match="/" mode="toc">
4308  <hr class="noprint"/>
4309
4310  <h1 class="np" id="{$anchor-prefix}.toc"> <!-- this pagebreak occurs always -->
4311    <a href="#{$anchor-prefix}.toc">Table of Contents</a>
4312  </h1>
4313
4314  <ul class="toc">
4315    <xsl:apply-templates mode="toc" />
4316  </ul>
4317</xsl:template>
4318
4319<xsl:template name="insert-toc-line">
4320  <xsl:param name="number" />
4321  <xsl:param name="target" />
4322  <xsl:param name="title" />
4323  <xsl:param name="tocparam" />
4324  <xsl:param name="oldtitle" />
4325  <xsl:param name="waschanged" />
4326
4327  <!-- handle tocdepth parameter -->
4328  <xsl:choose>
4329    <xsl:when test="($tocparam='' or $tocparam='default') and string-length(translate($number,'.ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890&#167;','.')) &gt;= $parsedTocDepth">
4330      <!-- dropped entry because excluded -->
4331      <xsl:attribute name="class">tocline2</xsl:attribute>
4332    </xsl:when>
4333    <xsl:when test="$tocparam='exclude'">
4334      <!-- dropped entry because excluded -->
4335      <xsl:attribute name="class">tocline2</xsl:attribute>
4336    </xsl:when>
4337    <xsl:otherwise>
4338      <xsl:choose>
4339        <xsl:when test="starts-with($number,'del-')">
4340          <del>
4341            <xsl:value-of select="$number" />
4342            <a href="#{$target}"><xsl:value-of select="$title"/></a>
4343          </del>
4344        </xsl:when>
4345        <xsl:otherwise>
4346          <xsl:choose>
4347            <xsl:when test="not(contains($number,'.'))">
4348              <xsl:attribute name="class">tocline0</xsl:attribute>
4349            </xsl:when>
4350            <xsl:otherwise>
4351              <xsl:attribute name="class">tocline1</xsl:attribute>
4352            </xsl:otherwise>
4353          </xsl:choose>
4354          <xsl:if test="$number != '' and not(contains($number,'unnumbered-'))">
4355            <xsl:call-template name="emit-section-number">
4356              <xsl:with-param name="no" select="$number"/>
4357            </xsl:call-template>
4358            <xsl:text>&#160;&#160;&#160;</xsl:text>
4359          </xsl:if>
4360          <a href="#{$target}">
4361            <xsl:choose>
4362              <xsl:when test="$waschanged!=''">
4363                <ins><xsl:value-of select="$title"/></ins>
4364                <del><xsl:value-of select="$oldtitle"/></del>
4365              </xsl:when>
4366              <xsl:otherwise>
4367                <xsl:value-of select="$title"/>
4368              </xsl:otherwise>
4369            </xsl:choose>
4370          </a>
4371        </xsl:otherwise>
4372      </xsl:choose>
4373    </xsl:otherwise>
4374  </xsl:choose>
4375</xsl:template>
4376
4377<xsl:template match="back" mode="toc">
4378
4379  <xsl:if test="//cref and $xml2rfc-comments='yes' and $xml2rfc-inline!='yes'">
4380    <li>
4381      <xsl:call-template name="insert-toc-line">
4382        <xsl:with-param name="target" select="concat($anchor-prefix,'.comments')"/>
4383        <xsl:with-param name="title" select="'Editorial Comments'"/>
4384      </xsl:call-template>
4385    </li>
4386  </xsl:if>
4387
4388  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
4389    <xsl:apply-templates select="/rfc/front" mode="toc" />
4390  </xsl:if>
4391  <xsl:apply-templates select="*[not(self::references)]" mode="toc" />
4392
4393  <!-- insert the index if index entries exist -->
4394  <xsl:if test="$has-index">
4395    <li>
4396      <xsl:call-template name="insert-toc-line">
4397        <xsl:with-param name="target" select="concat($anchor-prefix,'.index')"/>
4398        <xsl:with-param name="title" select="'Index'"/>
4399      </xsl:call-template>
4400    </li>
4401  </xsl:if>
4402
4403  <xsl:if test="$xml2rfc-ext-authors-section='end'">
4404    <xsl:apply-templates select="/rfc/front" mode="toc" />
4405  </xsl:if>
4406
4407  <!-- copyright statements -->
4408  <xsl:if test="$xml2rfc-private='' and not($no-copylong)">
4409    <li>
4410      <xsl:call-template name="insert-toc-line">
4411        <xsl:with-param name="target" select="concat($anchor-prefix,'.ipr')"/>
4412        <xsl:with-param name="title" select="'Intellectual Property and Copyright Statements'"/>
4413      </xsl:call-template>
4414    </li>
4415  </xsl:if>
4416 
4417</xsl:template>
4418
4419<xsl:template match="front" mode="toc">
4420 
4421  <xsl:variable name="authors-title">
4422    <xsl:call-template name="get-authors-section-title"/>
4423  </xsl:variable>
4424  <xsl:variable name="authors-number">
4425    <xsl:call-template name="get-authors-section-number"/>
4426  </xsl:variable>
4427
4428  <xsl:if test="$authors-number!='suppress'">
4429    <li>
4430      <xsl:call-template name="insert-toc-line">
4431        <xsl:with-param name="target" select="concat($anchor-prefix,'.authors')"/>
4432        <xsl:with-param name="title" select="$authors-title"/>
4433        <xsl:with-param name="number" select="$authors-number"/>
4434      </xsl:call-template>
4435    </li>
4436  </xsl:if>
4437
4438</xsl:template>
4439
4440<xsl:template name="references-toc">
4441
4442  <!-- distinguish two cases: (a) single references element (process
4443  as toplevel section; (b) multiple references sections (add one toplevel
4444  container with subsection) -->
4445
4446  <xsl:variable name="refsecs" select="/rfc/back/references|/rfc/back/ed:replace/ed:ins/references"/>
4447   
4448  <xsl:choose>
4449    <xsl:when test="count($refsecs) = 0">
4450      <!-- nop -->
4451    </xsl:when>
4452    <xsl:when test="count($refsecs) = 1">
4453      <xsl:for-each select="$refsecs">
4454        <xsl:variable name="title">
4455          <xsl:choose>
4456            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
4457            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
4458          </xsl:choose>
4459        </xsl:variable>
4460     
4461        <li>
4462          <xsl:call-template name="insert-toc-line">
4463            <xsl:with-param name="number">
4464              <xsl:call-template name="get-references-section-number"/>
4465            </xsl:with-param>
4466            <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
4467            <xsl:with-param name="title" select="$title"/>
4468          </xsl:call-template>
4469        </li>
4470      </xsl:for-each>
4471    </xsl:when>
4472    <xsl:otherwise>
4473      <li>
4474        <!-- insert pseudo container -->   
4475        <xsl:call-template name="insert-toc-line">
4476          <xsl:with-param name="number">
4477            <xsl:call-template name="get-references-section-number"/>
4478          </xsl:with-param>
4479          <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
4480          <xsl:with-param name="title" select="$xml2rfc-refparent"/>
4481        </xsl:call-template>
4482 
4483        <ul class="toc">
4484          <!-- ...with subsections... -->   
4485          <xsl:for-each select="$refsecs">
4486            <xsl:variable name="title">
4487              <xsl:choose>
4488                <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
4489                <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
4490              </xsl:choose>
4491            </xsl:variable>
4492         
4493            <xsl:variable name="sectionNumber">
4494              <xsl:call-template name="get-section-number" />
4495            </xsl:variable>
4496   
4497            <xsl:variable name="num">
4498              <xsl:number level="any"/>
4499            </xsl:variable>
4500   
4501            <li>
4502              <xsl:call-template name="insert-toc-line">
4503                <xsl:with-param name="number" select="$sectionNumber"/>
4504                <xsl:with-param name="target" select="concat($anchor-prefix,'.references','.',$num)"/>
4505                <xsl:with-param name="title" select="$title"/>
4506              </xsl:call-template>
4507            </li>
4508          </xsl:for-each>
4509        </ul>
4510      </li>
4511    </xsl:otherwise>
4512  </xsl:choose>
4513</xsl:template>
4514
4515<xsl:template match="section|appendix" mode="toc">
4516  <xsl:variable name="sectionNumber">
4517    <xsl:call-template name="get-section-number" />
4518  </xsl:variable>
4519
4520  <xsl:variable name="target">
4521    <xsl:choose>
4522      <xsl:when test="@anchor"><xsl:value-of select="@anchor" /></xsl:when>
4523       <xsl:otherwise><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber" /></xsl:otherwise>
4524    </xsl:choose>
4525  </xsl:variable>
4526
4527  <!-- obtain content, just to check whether we need to recurse at all -->
4528  <xsl:variable name="content">
4529    <li>
4530      <xsl:call-template name="insert-toc-line">
4531        <xsl:with-param name="number" select="$sectionNumber"/>
4532        <xsl:with-param name="target" select="$target"/>
4533        <xsl:with-param name="title" select="@title"/>
4534        <xsl:with-param name="tocparam" select="@toc"/>
4535        <xsl:with-param name="oldtitle" select="@ed:old-title"/>
4536        <xsl:with-param name="waschanged" select="@ed:resolves"/>
4537      </xsl:call-template>
4538   
4539      <ul class="toc">
4540        <xsl:apply-templates mode="toc" />
4541      </ul>
4542    </li>
4543  </xsl:variable>
4544 
4545  <xsl:if test="$content!=''">
4546    <li>
4547      <xsl:call-template name="insert-toc-line">
4548        <xsl:with-param name="number" select="$sectionNumber"/>
4549        <xsl:with-param name="target" select="$target"/>
4550        <xsl:with-param name="title" select="@title"/>
4551        <xsl:with-param name="tocparam" select="@toc"/>
4552        <xsl:with-param name="oldtitle" select="@ed:old-title"/>
4553        <xsl:with-param name="waschanged" select="@ed:resolves"/>
4554      </xsl:call-template>
4555   
4556      <!-- obtain nested content, just to check whether we need to recurse at all -->
4557      <xsl:variable name="nested-content">
4558        <ul class="toc">
4559          <xsl:apply-templates mode="toc" />
4560        </ul>
4561      </xsl:variable>
4562     
4563      <!-- only recurse if we need to (do not produce useless list container) -->     
4564      <xsl:if test="$nested-content!=''">
4565        <ul class="toc">
4566          <xsl:apply-templates mode="toc" />
4567        </ul>
4568      </xsl:if>
4569    </li>
4570  </xsl:if>
4571</xsl:template>
4572
4573<xsl:template match="middle" mode="toc">
4574  <xsl:apply-templates mode="toc" />
4575  <xsl:call-template name="references-toc" />
4576</xsl:template>
4577
4578<xsl:template match="rfc" mode="toc">
4579  <xsl:apply-templates select="middle|back" mode="toc" />
4580</xsl:template>
4581
4582<xsl:template match="ed:del|ed:ins|ed:replace" mode="toc">
4583  <xsl:apply-templates mode="toc" />
4584</xsl:template>
4585
4586<xsl:template match="*|text()" mode="toc" />
4587
4588
4589<xsl:template name="insertTocAppendix">
4590 
4591  <xsl:if test="//figure[@title!='' or @anchor!='']">
4592    <ul class="toc">
4593      <xsl:for-each select="//figure[@title!='' or @anchor!='']">
4594        <xsl:variable name="title">Figure <xsl:value-of select="position()"/><xsl:if test="@title">: <xsl:value-of select="@title"/></xsl:if>
4595        </xsl:variable>
4596        <li>
4597          <xsl:call-template name="insert-toc-line">
4598            <xsl:with-param name="target" select="concat($anchor-prefix,'.figure.',position())" />
4599            <xsl:with-param name="title" select="$title" />
4600          </xsl:call-template>
4601        </li>
4602      </xsl:for-each>
4603    </ul>
4604  </xsl:if>
4605 
4606  <!-- experimental -->
4607  <xsl:if test="//ed:issue">
4608    <xsl:call-template name="insertIssuesList" />
4609  </xsl:if>
4610
4611</xsl:template>
4612
4613<xsl:template name="referencename">
4614  <xsl:param name="node" />
4615 
4616  <xsl:for-each select="$node">
4617    <xsl:choose>
4618      <xsl:when test="$xml2rfc-symrefs!='no' and ancestor::ed:del">
4619        <xsl:variable name="unprefixed" select="substring-after(@anchor,'deleted-')"/>
4620        <xsl:choose>
4621          <xsl:when test="$unprefixed!=''">
4622            <xsl:value-of select="concat('[',$unprefixed,']')"/>
4623          </xsl:when>
4624          <xsl:otherwise>
4625            <xsl:if test="count(//reference[@anchor=current()/@anchor])!=1">
4626              <xsl:message>Deleted duplicate anchors should have the prefix "deleted-": <xsl:value-of select="@anchor"/></xsl:message>
4627            </xsl:if>
4628            <xsl:value-of select="concat('[',@anchor,']')"/>
4629          </xsl:otherwise>
4630        </xsl:choose>
4631      </xsl:when>
4632      <xsl:when test="$xml2rfc-symrefs!='no'">[<xsl:value-of select="@anchor" />]</xsl:when>
4633      <xsl:when test="ancestor::ed:del">
4634        <xsl:text>[del]</xsl:text>
4635      </xsl:when>
4636      <xsl:otherwise>[<xsl:number level="any" count="reference[not(ancestor::ed:del)]"/>]</xsl:otherwise>
4637    </xsl:choose>
4638  </xsl:for-each> 
4639</xsl:template>
4640
4641
4642
4643<xsl:template name="replace-substring">
4644
4645  <xsl:param name="string" />
4646  <xsl:param name="replace" />
4647  <xsl:param name="by" />
4648
4649  <xsl:choose>
4650    <xsl:when test="contains($string,$replace)">
4651      <xsl:value-of select="concat(substring-before($string, $replace),$by)" />
4652      <xsl:call-template name="replace-substring">
4653        <xsl:with-param name="string" select="substring-after($string,$replace)" />
4654        <xsl:with-param name="replace" select="$replace" />
4655        <xsl:with-param name="by" select="$by" />
4656      </xsl:call-template>
4657    </xsl:when>
4658    <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
4659  </xsl:choose>
4660
4661</xsl:template>
4662
4663<xsl:template name="rfc-or-id-link">
4664  <xsl:param name="name" />
4665  <xsl:call-template name="check-front-matter-ref">
4666    <xsl:with-param name="name" select="$name"/>
4667  </xsl:call-template>
4668  <a>
4669    <xsl:attribute name="href">
4670      <xsl:choose>
4671        <xsl:when test="starts-with($name,'draft-')">
4672          <xsl:value-of select="concat($internetDraftUrlPrefix,$name,$internetDraftUrlPostfix)"/>
4673        </xsl:when>
4674        <xsl:otherwise>
4675          <xsl:value-of select="concat($rfcUrlPrefix,$name,$rfcUrlPostfix)"/>
4676        </xsl:otherwise>
4677      </xsl:choose>
4678    </xsl:attribute>
4679    <xsl:value-of select="$name" />
4680  </a>
4681</xsl:template>
4682
4683<xsl:template name="rfclist">
4684  <xsl:param name="list" />
4685  <xsl:choose>
4686    <xsl:when test="contains($list,',')">
4687      <xsl:variable name="rfcNo" select="substring-before($list,',')" />
4688      <xsl:call-template name="rfc-or-id-link">
4689        <xsl:with-param name="name" select="$rfcNo"/>
4690      </xsl:call-template>
4691      <xsl:text>, </xsl:text>
4692      <xsl:call-template name="rfclist">
4693        <xsl:with-param name="list" select="normalize-space(substring-after($list,','))" />
4694      </xsl:call-template>
4695    </xsl:when>
4696    <xsl:otherwise>
4697      <xsl:variable name="rfcNo" select="$list" />
4698      <xsl:call-template name="rfc-or-id-link">
4699        <xsl:with-param name="name" select="$rfcNo"/>
4700      </xsl:call-template>
4701    </xsl:otherwise>
4702  </xsl:choose>
4703</xsl:template>
4704
4705<xsl:template name="check-front-matter-ref">
4706  <xsl:param name="name"/>
4707  <xsl:choose>
4708    <xsl:when test="starts-with($name,'draft-')">
4709      <xsl:if test="not(//references//reference/seriesInfo[@name='Internet-Draft' and @value=$name])">
4710        <xsl:call-template name="warning">
4711          <xsl:with-param name="inline" select="'no'"/>
4712          <xsl:with-param name="msg" select="concat('front matter mentions I-D ',$name,' for which there is no reference element')"/>
4713        </xsl:call-template>
4714      </xsl:if>
4715    </xsl:when>
4716    <xsl:otherwise>
4717      <xsl:if test="not(//references//reference/seriesInfo[@name='RFC' and @value=$name])">
4718        <xsl:call-template name="warning">
4719          <xsl:with-param name="inline" select="'no'"/>
4720          <xsl:with-param name="msg" select="concat('front matter mentions RFC ',$name,' for which there is no reference element')"/>
4721        </xsl:call-template>
4722      </xsl:if>
4723    </xsl:otherwise>
4724  </xsl:choose>
4725</xsl:template>
4726
4727<xsl:template name="check-anchor">
4728  <xsl:if test="@anchor and @anchor!=''">
4729    <!-- check validity of anchor name -->
4730    <xsl:variable name="test">
4731      <xsl:element name="{@anchor}"/>
4732    </xsl:variable>
4733    <xsl:if test="count(exslt:node-set($test)//*) = 0">
4734      <xsl:call-template name="error">
4735        <xsl:with-param name="msg" select="concat('&quot;',@anchor,'&quot; is not a valid XML name')"/>
4736      </xsl:call-template>
4737    </xsl:if>
4738  </xsl:if>
4739</xsl:template>
4740
4741<xsl:template name="copy-anchor">
4742  <xsl:call-template name="check-anchor"/>
4743  <xsl:if test="@anchor and @anchor!=''">
4744    <xsl:attribute name="id"><xsl:value-of select="@anchor"/></xsl:attribute>
4745  </xsl:if>
4746</xsl:template>
4747
4748<xsl:template name="rfclist-for-dcmeta">
4749  <xsl:param name="list" />
4750  <xsl:choose>
4751    <xsl:when test="contains($list,',')">
4752      <xsl:variable name="rfcNo" select="substring-before($list,',')" />
4753      <meta name="DC.Relation.Replaces" content="urn:ietf:rfc:{$rfcNo}" />
4754      <xsl:call-template name="rfclist-for-dcmeta">
4755        <xsl:with-param name="list" select="normalize-space(substring-after($list,','))" />
4756      </xsl:call-template>
4757    </xsl:when>
4758    <xsl:otherwise>
4759      <xsl:variable name="rfcNo" select="$list" />
4760      <meta name="DC.Relation.Replaces" content="urn:ietf:rfc:{$rfcNo}" />
4761    </xsl:otherwise>
4762  </xsl:choose>
4763</xsl:template>
4764
4765<xsl:template name="get-paragraph-number">
4766  <!-- get section number of ancestor section element, then add t or figure number -->
4767  <xsl:if test="ancestor::section and not(ancestor::section[@myns:unnumbered='unnumbered']) and not(ancestor::x:blockquote) and not(ancestor::x:note)">
4768    <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|x:note" />
4769  </xsl:if>
4770</xsl:template>
4771
4772<xsl:template name="editingMark">
4773  <xsl:if test="$xml2rfc-editing='yes' and ancestor::rfc">
4774    <sup class="editingmark"><span><xsl:number level="any" count="postamble|preamble|t"/></span>&#0160;</sup>
4775  </xsl:if>
4776</xsl:template>
4777
4778<!-- internal ref support -->
4779<xsl:key name="anchor-item-alias" match="//*[@anchor and (x:anchor-alias/@value or ed:replace/ed:ins/x:anchor-alias)]" use="x:anchor-alias/@value | ed:replace/ed:ins/x:anchor-alias/@value"/>
4780
4781<xsl:template match="x:ref">
4782  <xsl:variable name="val" select="."/>
4783<!--  <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)]"/> -->
4784  <xsl:variable name="target" select="key('anchor-item',$val) | key('anchor-item-alias',$val)"/>
4785  <xsl:variable name="irefs" select="//iref[@x:for-anchor=$val]"/>
4786  <xsl:choose>
4787    <xsl:when test="$target">
4788      <a href="#{$target/@anchor}" class="smpl">
4789        <xsl:call-template name="copy-anchor"/>
4790        <!-- to be indexed? -->
4791        <xsl:if test="$irefs">
4792          <xsl:attribute name="id"><xsl:call-template name="compute-extref-anchor"/></xsl:attribute>
4793        </xsl:if>
4794        <xsl:value-of select="."/>
4795      </a>
4796    </xsl:when>
4797    <xsl:otherwise>
4798      <xsl:call-template name="warning">
4799        <xsl:with-param name="inline" select="'no'"/>
4800        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:with-param>
4801      </xsl:call-template>
4802      <xsl:value-of select="."/>
4803    </xsl:otherwise>
4804  </xsl:choose>
4805</xsl:template>
4806
4807<!-- Nothing to do here -->
4808<xsl:template match="x:anchor-alias" />
4809
4810<!-- Quotes -->
4811<xsl:template match="x:q">
4812  <q>
4813    <xsl:copy-of select="@cite"/>
4814    <xsl:apply-templates/>
4815  </q>
4816</xsl:template>
4817
4818<!-- Notes -->
4819<xsl:template match="x:note">
4820  <div class="note">
4821    <xsl:apply-templates/>
4822  </div>
4823</xsl:template>
4824
4825<xsl:template match="x:bcp14">
4826  <!-- check valid BCP14 keywords, then emphasize them -->
4827  <xsl:variable name="c" select="normalize-space(.)"/>
4828  <xsl:choose>
4829    <xsl:when test="$c='MUST' or $c='REQUIRED' or $c='SHALL'">
4830      <em class="bcp14"><xsl:value-of select="."/></em>
4831    </xsl:when>
4832    <xsl:when test="$c='MUST NOT' or $c='SHALL NOT'">
4833      <em class="bcp14"><xsl:value-of select="."/></em>
4834    </xsl:when>
4835    <xsl:when test="$c='SHOULD' or $c='RECOMMENDED'">
4836      <em class="bcp14"><xsl:value-of select="."/></em>
4837    </xsl:when>
4838    <xsl:when test="$c='SHOULD NOT' or $c='NOT RECOMMENDED'">
4839      <em class="bcp14"><xsl:value-of select="."/></em>
4840    </xsl:when>
4841    <xsl:when test="$c='MAY' or $c='OPTIONAL'">
4842      <em class="bcp14"><xsl:value-of select="."/></em>
4843    </xsl:when>
4844    <xsl:otherwise>
4845      <xsl:value-of select="."/>
4846      <xsl:message>ERROR: unknown BCP14 keyword: <xsl:value-of select="."/></xsl:message>
4847    </xsl:otherwise>
4848  </xsl:choose>
4849</xsl:template>
4850
4851<xsl:template match="x:blockquote">
4852  <xsl:variable name="p">
4853    <xsl:call-template name="get-paragraph-number" />
4854  </xsl:variable>
4855
4856  <blockquote>
4857    <xsl:if test="string-length($p) &gt; 0 and not(ancestor::ed:del) and not(ancestor::ed:ins)">
4858      <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$p"/></xsl:attribute>
4859    </xsl:if>
4860    <xsl:call-template name="insertInsDelClass"/>
4861    <xsl:call-template name="editingMark" />
4862    <xsl:copy-of select="@cite"/>
4863    <xsl:apply-templates/>
4864  </blockquote>
4865</xsl:template>
4866
4867<!-- Definitions -->
4868<xsl:template match="x:dfn">
4869  <dfn>
4870    <xsl:call-template name="copy-anchor"/>
4871    <xsl:apply-templates/>
4872  </dfn>
4873</xsl:template>
4874
4875<!-- headings -->
4876<xsl:template match="x:h">
4877  <b>
4878    <xsl:call-template name="copy-anchor"/>
4879    <xsl:apply-templates/>
4880  </b>
4881</xsl:template>
4882
4883<!-- superscripts -->
4884<xsl:template match="x:sup">
4885  <sup>
4886    <xsl:apply-templates/>
4887  </sup>
4888</xsl:template>
4889
4890<!-- bold -->
4891<xsl:template match="x:highlight">
4892  <b>
4893    <xsl:call-template name="copy-anchor"/>
4894    <xsl:apply-templates/>
4895  </b>
4896</xsl:template>
4897
4898<!-- measuring lengths -->
4899<xsl:template match="x:length-of">
4900  <xsl:variable name="target" select="//*[@anchor=current()/@target]"/>
4901  <xsl:if test="count($target)!=1">
4902    <xsl:call-template name="error">
4903      <xsl:with-param name="msg" select="concat('@target ',@target,' defined ',count($target),' times.')"/>
4904    </xsl:call-template>
4905  </xsl:if>
4906  <xsl:variable name="content">
4907    <xsl:apply-templates select="$target"/>
4908  </xsl:variable>
4909  <xsl:variable name="lineends" select="string-length($content) - string-length(translate($content,'&#10;',''))"/>
4910  <xsl:variable name="indents">
4911    <xsl:choose>
4912      <xsl:when test="@indented">
4913        <xsl:value-of select="number(@indented) * $lineends"/>
4914      </xsl:when>
4915      <xsl:otherwise>0</xsl:otherwise>
4916    </xsl:choose>
4917  </xsl:variable>
4918  <xsl:value-of select="string-length($content) + $lineends - $indents"/>
4919</xsl:template>
4920
4921<!-- Nop -->
4922<xsl:template match="x:span">
4923  <span>
4924    <xsl:call-template name="copy-anchor"/>
4925    <xsl:apply-templates/>
4926  </span>
4927</xsl:template>
4928
4929<xsl:template match="x:parse-xml">
4930  <xsl:apply-templates/>
4931
4932  <xsl:if test="function-available('exslt:node-set')">
4933    <xsl:variable name="cleaned">
4934      <xsl:apply-templates mode="cleanup-edits"/>
4935    </xsl:variable>
4936    <xsl:if test="$xml2rfc-ext-trace-parse-xml='yes'">
4937      <xsl:call-template name="trace">
4938        <xsl:with-param name="msg" select="concat('Parsing XML: ', $cleaned)"/>
4939      </xsl:call-template>
4940    </xsl:if>
4941    <xsl:choose>
4942      <xsl:when test="function-available('myns:parseXml')">
4943        <xsl:if test="myns:parseXml(concat($cleaned,''))!=''">
4944          <xsl:call-template name="error">
4945            <xsl:with-param name="msg" select="concat('Parse error in XML: ', myns:parseXml(concat($cleaned,'')))"/>
4946          </xsl:call-template>
4947        </xsl:if>
4948      </xsl:when>
4949      <xsl:when test="function-available('saxon:parse')">
4950        <xsl:variable name="parsed" select="saxon:parse(concat($cleaned,''))"/>
4951        <xsl:if test="$parsed='foo'">
4952          <xsl:comment>should not get here</xsl:comment>
4953        </xsl:if>
4954      </xsl:when>
4955      <xsl:otherwise></xsl:otherwise>
4956    </xsl:choose>
4957  </xsl:if>
4958</xsl:template>
4959
4960<!-- inlined RDF support -->
4961<xsl:template match="rdf:Description">
4962  <!-- ignore -->
4963</xsl:template>
4964
4965<!-- cleanup for ins/del -->
4966
4967<xsl:template match="comment()|@*" mode="cleanup-edits"><xsl:copy/></xsl:template>
4968
4969<xsl:template match="text()" mode="cleanup-edits"><xsl:copy/></xsl:template>
4970
4971<xsl:template match="/" mode="cleanup-edits">
4972  <xsl:copy><xsl:apply-templates select="node()" mode="cleanup-edits" /></xsl:copy>
4973</xsl:template>
4974
4975<xsl:template match="ed:del" mode="cleanup-edits"/>
4976
4977<xsl:template match="ed:replace" mode="cleanup-edits">
4978  <xsl:apply-templates mode="cleanup-edits"/>
4979</xsl:template>
4980
4981<xsl:template match="ed:ins" mode="cleanup-edits">
4982  <xsl:apply-templates mode="cleanup-edits"/>
4983</xsl:template>
4984
4985
4986<!-- ABNF support -->
4987<xsl:template name="to-abnf-char-sequence">
4988  <xsl:param name="chars"/>
4989 
4990  <xsl:variable name="c" select="substring($chars,1,1)"/>
4991  <xsl:variable name="r" select="substring($chars,2)"/>
4992   
4993  <xsl:choose>
4994    <xsl:when test="$c='-'">2D</xsl:when>
4995    <xsl:when test="$c='/'">2F</xsl:when>
4996    <xsl:when test="$c='0'">30</xsl:when>
4997    <xsl:when test="$c='1'">31</xsl:when>
4998    <xsl:when test="$c='2'">32</xsl:when>
4999    <xsl:when test="$c='3'">33</xsl:when>
5000    <xsl:when test="$c='4'">34</xsl:when>
5001    <xsl:when test="$c='5'">35</xsl:when>
5002    <xsl:when test="$c='6'">36</xsl:when>
5003    <xsl:when test="$c='7'">37</xsl:when>
5004    <xsl:when test="$c='8'">38</xsl:when>
5005    <xsl:when test="$c='9'">39</xsl:when>
5006    <xsl:when test="$c='A'">41</xsl:when>
5007    <xsl:when test="$c='B'">42</xsl:when>
5008    <xsl:when test="$c='C'">43</xsl:when>
5009    <xsl:when test="$c='D'">44</xsl:when>
5010    <xsl:when test="$c='E'">45</xsl:when>
5011    <xsl:when test="$c='F'">46</xsl:when>
5012    <xsl:when test="$c='G'">47</xsl:when>
5013    <xsl:when test="$c='H'">48</xsl:when>
5014    <xsl:when test="$c='I'">49</xsl:when>
5015    <xsl:when test="$c='J'">4A</xsl:when>
5016    <xsl:when test="$c='K'">4B</xsl:when>
5017    <xsl:when test="$c='L'">4C</xsl:when>
5018    <xsl:when test="$c='M'">4D</xsl:when>
5019    <xsl:when test="$c='N'">4E</xsl:when>
5020    <xsl:when test="$c='O'">4F</xsl:when>
5021    <xsl:when test="$c='P'">50</xsl:when>
5022    <xsl:when test="$c='Q'">51</xsl:when>
5023    <xsl:when test="$c='R'">52</xsl:when>
5024    <xsl:when test="$c='S'">53</xsl:when>
5025    <xsl:when test="$c='T'">54</xsl:when>
5026    <xsl:when test="$c='U'">55</xsl:when>
5027    <xsl:when test="$c='V'">56</xsl:when>
5028    <xsl:when test="$c='W'">57</xsl:when>
5029    <xsl:when test="$c='X'">58</xsl:when>
5030    <xsl:when test="$c='Y'">59</xsl:when>
5031    <xsl:when test="$c='Z'">5A</xsl:when>
5032    <xsl:when test="$c='a'">61</xsl:when>
5033    <xsl:when test="$c='b'">62</xsl:when>
5034    <xsl:when test="$c='c'">63</xsl:when>
5035    <xsl:when test="$c='d'">64</xsl:when>
5036    <xsl:when test="$c='e'">65</xsl:when>
5037    <xsl:when test="$c='f'">66</xsl:when>
5038    <xsl:when test="$c='g'">67</xsl:when>
5039    <xsl:when test="$c='h'">68</xsl:when>
5040    <xsl:when test="$c='i'">69</xsl:when>
5041    <xsl:when test="$c='j'">6A</xsl:when>
5042    <xsl:when test="$c='k'">6B</xsl:when>
5043    <xsl:when test="$c='l'">6C</xsl:when>
5044    <xsl:when test="$c='m'">6D</xsl:when>
5045    <xsl:when test="$c='n'">6E</xsl:when>
5046    <xsl:when test="$c='o'">6F</xsl:when>
5047    <xsl:when test="$c='p'">70</xsl:when>
5048    <xsl:when test="$c='q'">71</xsl:when>
5049    <xsl:when test="$c='r'">72</xsl:when>
5050    <xsl:when test="$c='s'">73</xsl:when>
5051    <xsl:when test="$c='t'">74</xsl:when>
5052    <xsl:when test="$c='u'">75</xsl:when>
5053    <xsl:when test="$c='v'">76</xsl:when>
5054    <xsl:when test="$c='w'">77</xsl:when>
5055    <xsl:when test="$c='x'">78</xsl:when>
5056    <xsl:when test="$c='y'">79</xsl:when>
5057    <xsl:when test="$c='z'">7A</xsl:when>
5058    <xsl:otherwise>
5059      <xsl:text>??</xsl:text>
5060      <xsl:call-template name="error">
5061        <xsl:with-param name="msg" select="concat('unexpected character in ABNF char sequence: ',substring($chars,1,1))" />
5062      </xsl:call-template>
5063    </xsl:otherwise>
5064  </xsl:choose>
5065
5066  <xsl:if test="$r!=''">
5067    <xsl:text>.</xsl:text>
5068    <xsl:call-template name="to-abnf-char-sequence">
5069      <xsl:with-param name="chars" select="$r"/>
5070    </xsl:call-template>
5071  </xsl:if>
5072 
5073</xsl:template>
5074
5075<xsl:template match="x:abnf-char-sequence">
5076  <xsl:choose>
5077    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
5078      <xsl:call-template name="error">
5079        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
5080      </xsl:call-template>
5081    </xsl:when>
5082    <xsl:otherwise>
5083      <xsl:text>%x</xsl:text>
5084      <xsl:call-template name="to-abnf-char-sequence">
5085        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
5086      </xsl:call-template>
5087    </xsl:otherwise>
5088  </xsl:choose>
5089</xsl:template>
5090
5091<!-- box drawing -->
5092
5093<!-- nop for alignment -->
5094<xsl:template match="x:x"/>
5095
5096<!-- box (top) -->
5097<xsl:template match="x:bt">
5098  <xsl:text>&#x250c;</xsl:text>
5099  <xsl:value-of select="translate(substring(.,2,string-length(.)-2),'-','&#x2500;')"/>
5100  <xsl:text>&#x2510;</xsl:text>
5101</xsl:template>
5102
5103<!-- box (center) -->
5104<xsl:template match="x:bc">
5105  <xsl:variable name="first" select="substring(.,1)"/>
5106  <xsl:variable name="content" select="substring(.,2,string-length(.)-2)"/>
5107  <xsl:variable name="is-delimiter" select="translate($content,'-','')=''"/>
5108 
5109  <xsl:choose>
5110    <xsl:when test="$is-delimiter">
5111      <xsl:text>&#x251c;</xsl:text>
5112      <xsl:value-of select="translate($content,'-','&#x2500;')"/>
5113      <xsl:text>&#x2524;</xsl:text>
5114    </xsl:when>
5115    <xsl:when test="*">
5116      <xsl:for-each select="node()">
5117        <xsl:choose>
5118          <xsl:when test="position()=1">
5119            <xsl:text>&#x2502;</xsl:text>
5120            <xsl:value-of select="substring(.,2)"/>
5121          </xsl:when>
5122          <xsl:when test="position()=last()">
5123            <xsl:value-of select="substring(.,1,string-length(.)-1)"/>
5124            <xsl:text>&#x2502;</xsl:text>
5125          </xsl:when>
5126          <xsl:otherwise>
5127            <xsl:apply-templates select="."/>
5128          </xsl:otherwise>
5129        </xsl:choose>
5130      </xsl:for-each>
5131    </xsl:when>
5132    <xsl:otherwise>
5133      <xsl:text>&#x2502;</xsl:text>
5134      <xsl:value-of select="$content"/>
5135      <xsl:text>&#x2502;</xsl:text>
5136    </xsl:otherwise>
5137  </xsl:choose>
5138 
5139</xsl:template>
5140
5141<!-- box (bottom) -->
5142<xsl:template match="x:bb">
5143  <xsl:text>&#x2514;</xsl:text>
5144  <xsl:value-of select="translate(substring(.,2,string-length(.)-2),'-','&#x2500;')"/>
5145  <xsl:text>&#x2518;</xsl:text>
5146</xsl:template>
5147
5148<!-- author handling extensions -->
5149<xsl:template match="x:include-author">
5150  <xsl:for-each select="/*/front/author[@anchor=current()/@target]">
5151    <xsl:apply-templates select="."/>
5152  </xsl:for-each>
5153</xsl:template>
5154
5155<!-- boilerplate -->
5156<xsl:template match="x:boilerplate">
5157  <xsl:apply-templates/>
5158</xsl:template>
5159
5160<!-- experimental annotation support -->
5161
5162<xsl:template match="ed:issueref">
5163  <xsl:choose>
5164    <xsl:when test=".=//ed:issue/@name">
5165      <a href="#{$anchor-prefix}.issue.{.}">
5166        <xsl:apply-templates/>
5167      </a>
5168    </xsl:when>
5169    <xsl:otherwise>
5170      <xsl:call-template name="warning">
5171        <xsl:with-param name="msg">Dangling ed:issueref: <xsl:value-of select="."/></xsl:with-param>
5172      </xsl:call-template>
5173      <xsl:apply-templates/>
5174    </xsl:otherwise>
5175  </xsl:choose>
5176</xsl:template>
5177
5178<xsl:template match="ed:issue">
5179  <xsl:variable name="class">
5180    <xsl:choose>
5181      <xsl:when test="@status='closed'">closedissue</xsl:when>
5182      <xsl:otherwise>openissue</xsl:otherwise>
5183    </xsl:choose>
5184  </xsl:variable>
5185 
5186  <table class="{$class}">
5187    <tr>
5188      <td colspan="3">
5189        <a id="{$anchor-prefix}.issue.{@name}">
5190          <xsl:choose>
5191            <xsl:when test="@status='closed'">
5192              <xsl:attribute name="class">closed-issue</xsl:attribute>
5193            </xsl:when>
5194            <xsl:when test="@status='editor'">
5195              <xsl:attribute name="class">editor-issue</xsl:attribute>
5196            </xsl:when>
5197            <xsl:otherwise>
5198              <xsl:attribute name="class">open-issue</xsl:attribute>
5199            </xsl:otherwise>
5200          </xsl:choose>
5201          <xsl:text>&#160;I&#160;</xsl:text>
5202        </a>
5203        <xsl:text>&#160;</xsl:text>
5204        <xsl:choose>
5205          <xsl:when test="@href">
5206            <em><a href="{@href}"><xsl:value-of select="@name" /></a></em>
5207          </xsl:when>
5208          <xsl:when test="@alternate-href">
5209            <em>[<a href="{@alternate-href}">alternate link</a>]</em>
5210          </xsl:when>
5211          <xsl:otherwise>
5212            <em><xsl:value-of select="@name" /></em>
5213          </xsl:otherwise>
5214        </xsl:choose>
5215        &#0160;
5216        (type: <xsl:value-of select="@type"/>, status: <xsl:value-of select="@status"/>)
5217      </td>
5218    </tr>
5219
5220    <xsl:apply-templates select="ed:item"/>
5221    <xsl:apply-templates select="ed:resolution"/>
5222
5223    <xsl:variable name="changes" select="//*[@ed:resolves=current()/@name or ed:resolves=current()/@name]" />
5224    <xsl:if test="$changes">
5225      <tr>
5226        <td class="top" colspan="3">
5227          Associated changes in this document:
5228          <xsl:variable name="issue" select="@name"/>
5229          <xsl:for-each select="$changes">
5230            <a href="#{$anchor-prefix}.change.{$issue}.{position()}">
5231              <xsl:variable name="label">
5232                <xsl:call-template name="get-section-number"/>
5233              </xsl:variable>
5234              <xsl:choose>
5235                <xsl:when test="$label!=''"><xsl:value-of select="$label"/></xsl:when>
5236                <xsl:otherwise>&lt;<xsl:value-of select="concat('#',$anchor-prefix,'.change.',$issue,'.',position())"/>&gt;</xsl:otherwise>
5237              </xsl:choose>
5238            </a>
5239            <xsl:if test="position()!=last()">, </xsl:if>
5240          </xsl:for-each>
5241          <xsl:text>.</xsl:text>
5242        </td>
5243      </tr>
5244    </xsl:if>
5245  </table>
5246   
5247</xsl:template>
5248
5249<xsl:template match="ed:item">
5250  <tr>
5251    <td class="top">
5252      <xsl:if test="@entered-by">
5253        <a href="mailto:{@entered-by}?subject={/rfc/@docName},%20{../@name}">
5254          <i><xsl:value-of select="@entered-by"/></i>
5255        </a>
5256      </xsl:if>
5257    </td>
5258    <td class="topnowrap">
5259      <xsl:value-of select="@date"/>
5260    </td>
5261    <td class="top">
5262      <xsl:apply-templates select="node()" mode="issuehtml"/>
5263    </td>
5264  </tr>
5265</xsl:template>
5266
5267<xsl:template match="ed:resolution">
5268  <tr>
5269    <td class="top">
5270      <xsl:if test="@entered-by">
5271        <a href="mailto:{@entered-by}?subject={/rfc/@docName},%20{../@name}"><i><xsl:value-of select="@entered-by"/></i></a>
5272      </xsl:if>
5273    </td>
5274    <td class="topnowrap">
5275      <xsl:value-of select="@datetime"/>
5276    </td>
5277    <td class="top">
5278      <em>Resolution:</em>
5279      <xsl:apply-templates select="node()" mode="issuehtml"/>
5280    </td>
5281  </tr>
5282</xsl:template>
5283
5284<xsl:template match="ed:annotation">
5285  <em>
5286    <xsl:apply-templates/>
5287  </em>
5288</xsl:template>
5289
5290<!-- special templates for handling XHTML in issues -->
5291<xsl:template match="text()" mode="issuehtml">
5292  <xsl:value-of select="."/>
5293</xsl:template>
5294
5295<xsl:template match="*|@*" mode="issuehtml">
5296  <xsl:message terminate="yes">Unexpected node in issue HTML: <xsl:value-of select="name(.)"/></xsl:message>
5297</xsl:template>
5298
5299<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">
5300  <xsl:element name="{local-name()}">
5301    <xsl:apply-templates select="@*|node()" mode="issuehtml"/>
5302  </xsl:element>
5303</xsl:template>
5304
5305<xsl:template match="xhtml:p" mode="issuehtml">
5306  <xsl:apply-templates select="node()" mode="issuehtml"/>
5307  <br class="p"/>
5308</xsl:template>
5309
5310<xsl:template match="xhtml:a/@href|xhtml:q/@cite" mode="issuehtml">
5311  <xsl:attribute name="{local-name(.)}">
5312    <xsl:value-of select="."/>
5313  </xsl:attribute>
5314</xsl:template>
5315
5316<xsl:template match="ed:issueref" mode="issuehtml">
5317  <xsl:apply-templates select="."/>
5318</xsl:template>
5319
5320<xsl:template match="ed:eref" mode="issuehtml">
5321  <xsl:text>&lt;</xsl:text>
5322  <a href="{.}"><xsl:value-of select="."/></a>
5323  <xsl:text>&gt;</xsl:text>
5324</xsl:template>
5325
5326<xsl:template name="insertIssuesList">
5327
5328  <h2 id="{$anchor-prefix}.issues-list" ><a href="#{$anchor-prefix}.issues-list">Issues list</a></h2>
5329  <table>
5330    <thead>
5331      <tr>
5332        <th>Id</th>
5333        <th>Type</th>
5334        <th>Status</th>
5335        <th>Date</th>
5336        <th>Raised By</th>
5337      </tr>
5338    </thead>
5339    <tbody>
5340      <xsl:for-each select="//ed:issue">
5341        <xsl:sort select="@status" />
5342        <xsl:sort select="@name" />
5343        <tr>
5344          <td><a href="#{$anchor-prefix}.issue.{@name}"><xsl:value-of select="@name" /></a></td>
5345          <td><xsl:value-of select="@type" /></td>
5346          <td><xsl:value-of select="@status" /></td>
5347          <td><xsl:value-of select="ed:item[1]/@date" /></td>
5348          <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>
5349        </tr>
5350      </xsl:for-each>
5351    </tbody>
5352  </table>
5353 
5354</xsl:template>
5355
5356<xsl:template name="insert-diagnostics">
5357 
5358  <!-- check anchor names -->
5359  <xsl:variable name="badAnchors"
5360    select="//*[starts-with(@anchor,concat($anchor-prefix,'.'))][@anchor!=concat($anchor-prefix,'.authors') and /*/x:assign-section-number[@number='suppress' and @builtin-target='authors']]" />
5361 
5362  <xsl:if test="$badAnchors">
5363    <xsl:variable name="text">
5364      The following anchor names may collide with internally generated anchors because of their prefix "<xsl:value-of select="$anchor-prefix" />":
5365      <xsl:for-each select="$badAnchors">
5366        <xsl:value-of select="@anchor"/><xsl:if test="position()!=last()">, </xsl:if>
5367      </xsl:for-each>
5368    </xsl:variable>
5369    <xsl:call-template name="warning">
5370      <xsl:with-param name="msg"><xsl:value-of select="$text"/></xsl:with-param>
5371    </xsl:call-template>
5372  </xsl:if>
5373 
5374  <!-- check ABNF syntax references -->
5375  <xsl:if test="//artwork[@type='abnf2616']">
5376    <xsl:if test="not(//reference/seriesInfo[@name='RFC' and (@value='2068' or @value='2616')])">
5377      <xsl:call-template name="warning">
5378        <xsl:with-param name="inline">no</xsl:with-param>
5379        <xsl:with-param name="msg">document uses HTTP-style ABNF syntax, but doesn't reference RFC 2068 or 2616.</xsl:with-param>
5380      </xsl:call-template>
5381    </xsl:if>
5382  </xsl:if>
5383  <xsl:if test="//artwork[@type='abnf']">
5384    <xsl:if test="not(//reference/seriesInfo[@name='RFC' and (@value='2234' or @value='4234' or @value='5234')])">
5385      <xsl:call-template name="warning">
5386        <xsl:with-param name="inline">no</xsl:with-param>
5387        <xsl:with-param name="msg">document uses ABNF syntax, but doesn't reference RFC 2234, 4234 or 5234.</xsl:with-param>
5388      </xsl:call-template>
5389    </xsl:if>
5390  </xsl:if>
5391 
5392  <!-- check IDs -->
5393  <xsl:variable name="badTargets" select="//xref[not(@target=//@anchor) and not(ancestor::ed:del)]" />
5394  <xsl:if test="$badTargets">
5395    <xsl:variable name="text">
5396      The following target names do not exist:
5397      <xsl:for-each select="$badTargets">
5398        <xsl:value-of select="@target"/><xsl:if test="position()!=last()">, </xsl:if>
5399      </xsl:for-each>
5400    </xsl:variable>
5401    <xsl:call-template name="warning">
5402      <xsl:with-param name="msg"><xsl:value-of select="$text"/></xsl:with-param>
5403    </xsl:call-template>
5404  </xsl:if>
5405 
5406 
5407</xsl:template>
5408
5409<!-- special change mark support, not supported by RFC2629 yet -->
5410
5411<xsl:template match="@ed:*" />
5412
5413<xsl:template match="ed:del">
5414  <xsl:call-template name="insert-issue-pointer"/>
5415  <del>
5416    <xsl:copy-of select="@*[namespace-uri()='']"/>
5417    <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
5418      <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
5419    </xsl:if>
5420    <xsl:apply-templates />
5421  </del>
5422</xsl:template>
5423
5424<xsl:template match="ed:ins">
5425  <xsl:call-template name="insert-issue-pointer"/>
5426  <ins>
5427    <xsl:copy-of select="@*[namespace-uri()='']"/>
5428    <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
5429      <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
5430    </xsl:if>
5431    <xsl:apply-templates />
5432  </ins>
5433</xsl:template>
5434
5435<xsl:template name="insert-issue-pointer">
5436  <xsl:param name="deleted-anchor"/>
5437  <xsl:variable name="change" select="."/>
5438  <xsl:for-each select="@ed:resolves|ed:resolves">
5439    <xsl:variable name="resolves" select="."/>
5440    <!-- need the right context node for proper numbering -->
5441    <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>
5442    <xsl:variable name="total" select="count(//*[@ed:resolves=$resolves or ed:resolves=$resolves])" />
5443    <xsl:variable name="id">
5444      <xsl:value-of select="$anchor-prefix"/>.change.<xsl:value-of select="$resolves"/>.<xsl:value-of select="$count" />
5445    </xsl:variable>
5446    <xsl:choose>
5447      <!-- block level? -->
5448      <xsl:when test="not(ancestor::t) and not(ancestor::title) and not(ancestor::figure) and not($change/@ed:old-title)">
5449        <div class="issuepointer noprint">
5450          <xsl:if test="not($deleted-anchor)">
5451            <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
5452          </xsl:if>
5453          <xsl:if test="$count > 1">
5454            <a class="bg-issue" title="previous change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count - 1}">&#x2191;</a>
5455          </xsl:if>
5456          <a class="open-issue" href="#{$anchor-prefix}.issue.{$resolves}" title="resolves: {$resolves}">
5457            <xsl:choose>
5458              <xsl:when test="//ed:issue[@name=$resolves and @status='closed']">
5459                <xsl:attribute name="class">closed-issue</xsl:attribute>
5460              </xsl:when>
5461              <xsl:when test="//ed:issue[@name=$resolves and @status='editor']">
5462                <xsl:attribute name="class">editor-issue</xsl:attribute>
5463              </xsl:when>
5464              <xsl:otherwise>
5465                <xsl:attribute name="class">open-issue</xsl:attribute>
5466              </xsl:otherwise>
5467            </xsl:choose>
5468            <xsl:text>&#160;I&#160;</xsl:text>
5469          </a>
5470          <xsl:if test="$count &lt; $total">
5471            <a class="bg-issue" title="next change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count + 1}">&#x2193;</a>
5472          </xsl:if>
5473          <xsl:text>&#160;</xsl:text>
5474        </div>
5475      </xsl:when>
5476      <xsl:otherwise>
5477        <xsl:if test="$count > 1">
5478          <a class="bg-issue" title="previous change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count - 1}">&#x2191;</a>
5479        </xsl:if>
5480        <a title="resolves: {$resolves}" href="#{$anchor-prefix}.issue.{$resolves}">
5481          <xsl:if test="not($deleted-anchor)">
5482            <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
5483          </xsl:if>
5484          <xsl:choose>
5485            <xsl:when test="//ed:issue[@name=$resolves and @status='closed']">
5486              <xsl:attribute name="class">closed-issue noprint</xsl:attribute>
5487            </xsl:when>
5488            <xsl:when test="//ed:issue[@name=$resolves and @status='editor']">
5489              <xsl:attribute name="class">editor-issue noprint</xsl:attribute>
5490            </xsl:when>
5491            <xsl:otherwise>
5492              <xsl:attribute name="class">open-issue noprint</xsl:attribute>
5493            </xsl:otherwise>
5494          </xsl:choose>
5495          <xsl:text>&#160;I&#160;</xsl:text>
5496        </a>
5497        <xsl:if test="$count &lt; $total">
5498          <a class="bg-issue" title="next change for {$resolves}" href="#{$anchor-prefix}.change.{$resolves}.{$count + 1}">&#x2193;</a>
5499        </xsl:if>
5500      </xsl:otherwise>
5501    </xsl:choose>
5502  </xsl:for-each>
5503</xsl:template>
5504
5505<xsl:template match="ed:replace">
5506  <!-- we need to special-case things like lists and tables -->
5507  <xsl:choose>
5508    <xsl:when test="parent::list">
5509      <xsl:apply-templates select="ed:del/node()" />
5510      <xsl:apply-templates select="ed:ins/node()" />
5511    </xsl:when>
5512    <xsl:when test="parent::references">
5513      <xsl:apply-templates select="ed:del/node()" />
5514      <xsl:apply-templates select="ed:ins/node()" />
5515    </xsl:when>
5516    <xsl:otherwise>
5517      <xsl:if test="@cite">
5518        <a class="editor-issue" href="{@cite}" target="_blank" title="see {@cite}">
5519          <xsl:text>&#160;i&#160;</xsl:text>
5520        </a>
5521      </xsl:if>
5522      <xsl:call-template name="insert-issue-pointer"/>
5523      <xsl:if test="ed:del">
5524        <del>
5525          <xsl:copy-of select="@*[namespace-uri()='']"/>
5526          <xsl:if test="not(@title) and ancestor-or-self::xsl:template[@ed:entered-by] and @datetime">
5527            <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
5528          </xsl:if>
5529          <xsl:apply-templates select="ed:del/node()" />
5530        </del>
5531      </xsl:if>
5532      <xsl:if test="ed:ins">
5533        <ins>
5534          <xsl:copy-of select="@*[namespace-uri()='']"/>
5535          <xsl:if test="not(@title) and ancestor-or-self::*[@ed:entered-by] and @datetime">
5536            <xsl:attribute name="title"><xsl:value-of select="concat(@datetime,', ',ancestor-or-self::*[@ed:entered-by][1]/@ed:entered-by)"/></xsl:attribute>
5537          </xsl:if>
5538          <xsl:apply-templates select="ed:ins/node()" />
5539        </ins>
5540      </xsl:if>
5541    </xsl:otherwise>
5542  </xsl:choose>
5543</xsl:template>
5544
5545<!-- convenience template for helping Mozilla (pre/ins inheritance problem) -->
5546<xsl:template name="insertInsDelClass">
5547  <xsl:if test="ancestor::ed:del">
5548    <xsl:attribute name="class">del</xsl:attribute>
5549  </xsl:if>
5550  <xsl:if test="ancestor::ed:ins">
5551    <xsl:attribute name="class">ins</xsl:attribute>
5552  </xsl:if>
5553</xsl:template>
5554
5555
5556<xsl:template name="sectionnumberAndEdits">
5557  <xsl:choose>
5558    <xsl:when test="ancestor::ed:del">
5559      <xsl:text>del-</xsl:text>
5560      <xsl:number count="ed:del//section" level="any"/>
5561    </xsl:when>
5562    <xsl:when test="@x:fixed-section-number and @x:fixed-section-number!=''">
5563      <xsl:value-of select="@x:fixed-section-number"/>
5564    </xsl:when>
5565    <xsl:when test="@x:fixed-section-number and @x:fixed-section-number=''">
5566      <xsl:text>unnumbered-</xsl:text>
5567      <xsl:number count="section[@x:fixed-section-number='']" level="any"/>
5568    </xsl:when>
5569    <xsl:when test="self::section and parent::ed:ins and local-name(../..)='replace'">
5570      <xsl:for-each select="../.."><xsl:call-template name="sectionnumberAndEdits" /></xsl:for-each>
5571      <xsl:for-each select="..">
5572        <xsl:if test="parent::ed:replace">
5573          <xsl:for-each select="..">
5574            <xsl:if test="parent::section">.</xsl:if>
5575            <xsl:variable name="cnt" select="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)" />
5576            <xsl:choose>
5577              <xsl:when test="ancestor::back and not(ancestor::section)"><xsl:number format="A" value="$cnt"/></xsl:when>
5578              <xsl:otherwise><xsl:value-of select="$cnt"/></xsl:otherwise>
5579            </xsl:choose>
5580          </xsl:for-each>
5581        </xsl:if>
5582      </xsl:for-each>
5583    </xsl:when>
5584    <xsl:when test="self::section[parent::ed:ins]">
5585      <xsl:for-each select="../.."><xsl:call-template name="sectionnumberAndEdits" /></xsl:for-each>
5586      <xsl:for-each select="..">
5587        <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)" />
5588      </xsl:for-each>
5589    </xsl:when>
5590    <xsl:when test="self::section">
5591      <xsl:for-each select=".."><xsl:call-template name="sectionnumberAndEdits" /></xsl:for-each>
5592      <xsl:if test="parent::section">.</xsl:if>
5593      <xsl:choose>
5594        <xsl:when test="parent::back">
5595          <xsl:number format="A" value="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)" />
5596        </xsl:when>
5597        <xsl:otherwise>
5598          <xsl:number value="1+count(preceding-sibling::section|preceding-sibling::ed:ins/section|preceding-sibling::ed:replace/ed:ins/section)" />
5599        </xsl:otherwise>
5600      </xsl:choose>
5601    </xsl:when>
5602    <xsl:when test="self::references">
5603      <xsl:choose>
5604        <xsl:when test="count(/*/back/references)+count(/*/back/ed:replace/ed:ins/references)=1"><xsl:call-template name="get-references-section-number"/></xsl:when>
5605        <xsl:otherwise><xsl:call-template name="get-references-section-number"/>.<xsl:number level="any"/></xsl:otherwise>
5606      </xsl:choose>
5607    </xsl:when>
5608    <xsl:when test="self::middle or self::back"><!-- done --></xsl:when>
5609    <xsl:otherwise>
5610      <!-- go up one level -->
5611      <xsl:for-each select=".."><xsl:call-template name="sectionnumberAndEdits" /></xsl:for-each>
5612    </xsl:otherwise>
5613  </xsl:choose>
5614</xsl:template>
5615
5616<!-- utilities for warnings -->
5617
5618<xsl:template name="trace">
5619  <xsl:param name="msg"/>
5620  <xsl:param name="msg2"/>
5621  <xsl:param name="inline"/>
5622  <xsl:call-template name="emit-message">
5623    <xsl:with-param name="level">TRACE</xsl:with-param>
5624    <xsl:with-param name="msg" select="$msg"/>
5625    <xsl:with-param name="msg2" select="$msg2"/>
5626    <xsl:with-param name="inline" select="$inline"/>
5627  </xsl:call-template>
5628</xsl:template>
5629
5630<xsl:template name="warning">
5631  <xsl:param name="msg"/>
5632  <xsl:param name="msg2"/>
5633  <xsl:param name="inline"/>
5634  <xsl:call-template name="emit-message">
5635    <xsl:with-param name="level">WARNING</xsl:with-param>
5636    <xsl:with-param name="msg" select="$msg"/>
5637    <xsl:with-param name="msg2" select="$msg2"/>
5638    <xsl:with-param name="inline" select="$inline"/>
5639  </xsl:call-template>
5640</xsl:template>
5641
5642<xsl:template name="error">
5643  <xsl:param name="msg"/>
5644  <xsl:param name="msg2"/>
5645  <xsl:param name="inline"/>
5646  <xsl:call-template name="emit-message">
5647    <xsl:with-param name="level">ERROR</xsl:with-param>
5648    <xsl:with-param name="msg" select="$msg"/>
5649    <xsl:with-param name="msg2" select="$msg2"/>
5650    <xsl:with-param name="inline" select="$inline"/>
5651  </xsl:call-template>
5652</xsl:template>
5653
5654<xsl:template name="emit-message">
5655  <xsl:param name="level"/>
5656  <xsl:param name="msg"/>
5657  <xsl:param name="msg2"/>
5658  <xsl:param name="inline"/>
5659  <xsl:variable name="message"><xsl:value-of select="$level"/>: <xsl:value-of select="$msg"/><xsl:value-of select="$msg2"/><xsl:call-template name="lineno"/></xsl:variable>
5660  <xsl:choose>
5661    <xsl:when test="$inline!='no'">
5662      <div class="error"><xsl:value-of select="$message"/></div>
5663    </xsl:when>
5664    <xsl:otherwise>
5665      <!-- this fails when the message contains characters not encodable in the output encoding -->
5666      <!-- <xsl:comment><xsl:value-of select="$message"/></xsl:comment> -->
5667    </xsl:otherwise>
5668  </xsl:choose>
5669  <xsl:message><xsl:value-of select="$message"/></xsl:message>
5670</xsl:template>
5671
5672<!-- table formatting -->
5673
5674<xsl:template match="texttable">
5675
5676  <xsl:variable name="anch">
5677    <xsl:call-template name="get-table-anchor"/>
5678  </xsl:variable>
5679
5680  <div id="{$anch}">
5681
5682    <xsl:if test="@anchor!=''">
5683      <div id="{@anchor}"/>
5684    </xsl:if>
5685    <xsl:apply-templates select="preamble" />
5686    <xsl:variable name="style">
5687      <xsl:text>tt </xsl:text>
5688      <xsl:choose>
5689        <xsl:when test="@style!=''">
5690          <xsl:value-of select="@style"/>
5691        </xsl:when>
5692        <xsl:otherwise>full</xsl:otherwise>
5693      </xsl:choose>
5694      <xsl:choose>
5695        <xsl:when test="@align='left'"> left</xsl:when>
5696        <xsl:when test="@align='right'"> right</xsl:when>
5697        <xsl:when test="@align='center' or not(@align) or @align=''"> center</xsl:when>
5698        <xsl:otherwise/>
5699      </xsl:choose>
5700
5701    </xsl:variable>
5702
5703    <table class="{$style}" cellpadding="3" cellspacing="0">
5704      <xsl:if test="(@title!='' or @anchor!='') and not(@suppress-title='true')">
5705        <xsl:variable name="n"><xsl:number level="any" count="texttable[(@title!='' or @anchor!='') and not(@suppress-title='true')]" /></xsl:variable>
5706        <caption>Table <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title" /></xsl:if></caption>
5707      </xsl:if>
5708
5709      <xsl:if test="ttcol!=''">
5710        <!-- skip header when all column titles are empty -->
5711        <thead>
5712          <tr>
5713            <xsl:apply-templates select="ttcol" />
5714          </tr>
5715        </thead>
5716      </xsl:if>
5717      <tbody>
5718        <xsl:variable name="columns" select="count(ttcol)" />
5719        <xsl:variable name="fields" select="c | ed:replace/ed:ins/c | ed:replace/ed:del/c" />
5720        <xsl:for-each select="$fields[$columns=1 or (position() mod $columns) = 1]">
5721          <tr>
5722            <xsl:for-each select=". | following-sibling::c[position() &lt; $columns]">
5723              <td>
5724                <xsl:call-template name="insertInsDelClass"/>
5725                <xsl:variable name="pos" select="position()" />
5726                <xsl:variable name="col" select="../ttcol[position() = $pos]" />
5727                <xsl:choose>
5728                  <xsl:when test="$col/@align='right' or $col/@align='center'">
5729                    <xsl:attribute name="class"><xsl:value-of select="$col/@align"/></xsl:attribute>
5730                  </xsl:when>
5731                  <xsl:when test="$col/@align='left' or not($col/@align)">
5732                    <xsl:attribute name="class">left</xsl:attribute>
5733                  </xsl:when>
5734                  <xsl:otherwise>
5735                    <xsl:call-template name="warning">
5736                      <xsl:with-param name="inline" select="'no'"/>
5737                      <xsl:with-param name="msg">Unknown align attribute on ttcol: <xsl:value-of select="$col/@align"/></xsl:with-param>                     
5738                    </xsl:call-template>
5739                  </xsl:otherwise>
5740                </xsl:choose>
5741                <xsl:apply-templates select="node()" />
5742              </td>
5743            </xsl:for-each>
5744          </tr>
5745        </xsl:for-each>
5746      </tbody>
5747    </table>
5748    <xsl:apply-templates select="postamble" />
5749  </div>
5750 
5751</xsl:template>
5752
5753<xsl:template match="ttcol">
5754  <th>
5755   
5756    <xsl:choose>
5757      <xsl:when test="@align='right' or @align='center' or @align='left'">
5758        <xsl:attribute name="class"><xsl:value-of select="@align"/></xsl:attribute>
5759      </xsl:when>
5760      <xsl:when test="not(@align)">
5761        <!-- that's the default, nothing to do here -->
5762      </xsl:when>
5763      <xsl:otherwise>
5764        <xsl:message>Unknown align attribute on ttcol: <xsl:value-of select="@align"/></xsl:message>
5765      </xsl:otherwise>
5766    </xsl:choose>
5767   
5768    <xsl:if test="@width">
5769      <xsl:attribute name="style">width: <xsl:value-of select="@width" />;</xsl:attribute>
5770    </xsl:if>
5771
5772    <xsl:apply-templates />
5773  </th>
5774</xsl:template>
5775
5776<!-- cref support -->
5777
5778<xsl:template name="get-comment-name">
5779  <xsl:choose>
5780    <xsl:when test="@anchor">
5781      <xsl:value-of select="@anchor"/>
5782    </xsl:when>
5783    <xsl:otherwise>
5784      <xsl:value-of select="$anchor-prefix"/>
5785      <xsl:text>.comment.</xsl:text>
5786      <xsl:number count="cref[not(@anchor)]" level="any"/>
5787    </xsl:otherwise>
5788  </xsl:choose>
5789</xsl:template>
5790
5791<xsl:template match="cref">
5792  <xsl:if test="$xml2rfc-comments!='no'">
5793    <xsl:variable name="cid">
5794      <xsl:call-template name="get-comment-name"/>
5795    </xsl:variable>
5796   
5797    <span class="comment">
5798      <xsl:choose>
5799        <xsl:when test="$xml2rfc-inline='yes'">
5800          <xsl:attribute name="id">
5801            <xsl:value-of select="$cid"/>
5802          </xsl:attribute>
5803          <xsl:text>[</xsl:text>
5804          <a href="#{$cid}" class="smpl">
5805            <xsl:value-of select="$cid"/>
5806          </a>
5807          <xsl:text>: </xsl:text>
5808          <xsl:apply-templates select="text()|eref|xref"/>
5809          <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
5810          <xsl:text>]</xsl:text>
5811        </xsl:when>
5812        <xsl:otherwise>
5813          <xsl:attribute name="title">
5814            <xsl:if test="@source"><xsl:value-of select="@source"/>: </xsl:if>
5815            <xsl:apply-templates select="text()|eref|xref"/>
5816          </xsl:attribute>
5817          <xsl:text>[</xsl:text>
5818          <a href="#{$cid}">
5819            <xsl:value-of select="$cid"/>
5820          </a>
5821          <xsl:text>]</xsl:text>
5822        </xsl:otherwise>
5823      </xsl:choose>
5824    </span>
5825  </xsl:if>
5826</xsl:template>
5827
5828<xsl:template name="insertComments">
5829
5830  <xsl:call-template name="insert-conditional-hrule"/>
5831   
5832  <h1>
5833    <xsl:call-template name="insert-conditional-pagebreak"/>
5834    <a id="{$anchor-prefix}.comments" href="#{$anchor-prefix}.comments">Editorial Comments</a>
5835  </h1>
5836
5837  <dl>
5838    <xsl:for-each select="//cref">
5839      <xsl:variable name="cid">
5840        <xsl:choose>
5841          <xsl:when test="@anchor">
5842            <xsl:value-of select="@anchor"/>
5843          </xsl:when>
5844          <xsl:otherwise>
5845            <xsl:value-of select="$anchor-prefix"/>
5846            <xsl:text>.comment.</xsl:text>
5847            <xsl:number count="cref[not(@anchor)]" level="any"/>
5848          </xsl:otherwise>
5849        </xsl:choose>
5850      </xsl:variable>
5851      <dt id="{$cid}">
5852        [<xsl:value-of select="$cid"/>]
5853      </dt>
5854      <dd>
5855        <xsl:apply-templates select="node()"/>
5856        <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
5857      </dd>
5858    </xsl:for-each>
5859  </dl>
5860</xsl:template>
5861
5862
5863<!-- Chapter Link Generation -->
5864
5865<xsl:template match="*" mode="links"><xsl:apply-templates mode="links"/></xsl:template>
5866<xsl:template match="text()" mode="links" />
5867
5868<xsl:template match="/*/middle//section[not(myns:unnumbered) and not(ancestor::section)]" mode="links">
5869  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number" /></xsl:variable>
5870  <xsl:variable name="title">
5871    <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
5872      <xsl:value-of select="$sectionNumber"/>
5873      <xsl:text> </xsl:text>
5874    </xsl:if>
5875    <xsl:value-of select="@title"/>
5876  </xsl:variable>
5877  <link rel="Chapter" title="{$title}" href="#{$anchor-prefix}.section.{$sectionNumber}"/>
5878  <xsl:apply-templates mode="links" />
5879</xsl:template>
5880
5881<xsl:template match="/*/back//section[not(myns:unnumbered) and not(ancestor::section)]" mode="links">
5882  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number" /></xsl:variable>
5883  <xsl:variable name="title">
5884    <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
5885      <xsl:value-of select="$sectionNumber"/>
5886      <xsl:text> </xsl:text>
5887    </xsl:if>
5888    <xsl:value-of select="@title"/>
5889  </xsl:variable>
5890  <link rel="Appendix" title="{$title}" href="#{$anchor-prefix}.section.{$sectionNumber}"/>
5891  <xsl:apply-templates mode="links" />
5892</xsl:template>
5893
5894<xsl:template match="/*/back/references[position()=1]" mode="links">
5895  <xsl:variable name="sectionNumber"><xsl:call-template name="get-references-section-number" /></xsl:variable>
5896  <link rel="Chapter" href="#{$anchor-prefix}.section.{$sectionNumber}">
5897    <xsl:choose>
5898      <xsl:when test="@title and count(/*/back/references)=1">
5899        <xsl:attribute name="title">
5900          <xsl:call-template name="get-references-section-number"/>
5901          <xsl:text> </xsl:text>
5902          <xsl:value-of select="@title"/>
5903        </xsl:attribute>
5904      </xsl:when>
5905      <xsl:otherwise>
5906        <xsl:attribute name="title">
5907          <xsl:call-template name="get-references-section-number"/>
5908          <xsl:text> </xsl:text>
5909          <xsl:value-of select="$xml2rfc-refparent"/>
5910        </xsl:attribute>
5911      </xsl:otherwise>
5912    </xsl:choose>
5913  </link>
5914</xsl:template>
5915
5916<!-- convenience templates -->
5917
5918<xsl:template name="get-author-summary">
5919  <xsl:choose>
5920    <xsl:when test="count(/rfc/front/author)=1">
5921      <xsl:value-of select="/rfc/front/author[1]/@surname" />
5922    </xsl:when>
5923    <xsl:when test="count(/rfc/front/author)=2">
5924      <xsl:value-of select="concat(/rfc/front/author[1]/@surname,' &amp; ',/rfc/front/author[2]/@surname)" />
5925    </xsl:when>
5926    <xsl:otherwise>
5927      <xsl:value-of select="concat(/rfc/front/author[1]/@surname,', et al.')" />
5928    </xsl:otherwise>
5929  </xsl:choose>
5930</xsl:template>
5931
5932<xsl:template name="get-category-long">
5933  <xsl:choose>
5934    <xsl:when test="$xml2rfc-footer!=''"><xsl:value-of select="$xml2rfc-footer" /></xsl:when>
5935    <xsl:when test="$xml2rfc-private!=''"/> <!-- private draft, footer not set -->
5936    <xsl:when test="/rfc/@category='bcp'">Best Current Practice</xsl:when>
5937    <xsl:when test="/rfc/@category='historic'">Historic</xsl:when>
5938    <xsl:when test="/rfc/@category='info' or not(/rfc/@category)">Informational</xsl:when>
5939    <xsl:when test="/rfc/@category='std'">Standards Track</xsl:when>
5940    <xsl:when test="/rfc/@category='exp'">Experimental</xsl:when>
5941    <xsl:otherwise>(category unknown)</xsl:otherwise>
5942  </xsl:choose>
5943</xsl:template>
5944
5945<xsl:template name="get-header-center">
5946  <xsl:choose>
5947    <xsl:when test="string-length(/rfc/front/title/@abbrev) &gt; 0">
5948      <xsl:value-of select="/rfc/front/title/@abbrev" />
5949    </xsl:when>
5950    <xsl:otherwise>
5951      <xsl:apply-templates select="/rfc/front/title" mode="get-text-content" />
5952    </xsl:otherwise>
5953  </xsl:choose>
5954</xsl:template>
5955
5956<xsl:template name="get-header-left">
5957  <xsl:choose>
5958    <xsl:when test="$xml2rfc-header!=''"><xsl:value-of select="$xml2rfc-header" /></xsl:when>
5959    <xsl:when test="$xml2rfc-private!=''"/> <!-- private draft, header not set -->
5960    <xsl:when test="/rfc/@ipr and not(/rfc/@number)">INTERNET DRAFT</xsl:when>
5961    <xsl:otherwise>RFC <xsl:value-of select="/rfc/@number"/></xsl:otherwise>
5962  </xsl:choose>
5963</xsl:template>
5964
5965<xsl:template name="get-generator">
5966  <xsl:variable name="gen">
5967    <xsl:text>http://greenbytes.de/tech/webdav/rfc2629.xslt, </xsl:text>
5968    <!-- when RCS keyword substitution in place, add version info -->
5969    <xsl:if test="contains('$Revision: 1.485 $',':')">
5970      <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.485 $', 'Revision: '),'$','')),', ')" />
5971    </xsl:if>
5972    <xsl:if test="contains('$Date: 2009-11-28 15:36:33 $',':')">
5973      <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2009-11-28 15:36:33 $', 'Date: '),'$','')),', ')" />
5974    </xsl:if>
5975    <xsl:value-of select="concat('XSLT vendor: ',system-property('xsl:vendor'),' ',system-property('xsl:vendor-url'))" />
5976  </xsl:variable>
5977  <xsl:value-of select="$gen" />
5978</xsl:template>
5979
5980<xsl:template name="get-header-right">
5981  <xsl:value-of select="concat($xml2rfc-ext-pub-month, ' ', $xml2rfc-ext-pub-year)" />
5982</xsl:template>
5983
5984<xsl:template name="get-keywords">
5985  <xsl:for-each select="/rfc/front/keyword">
5986    <xsl:if test="contains(.,',')">
5987      <xsl:call-template name="warning">
5988        <xsl:with-param name="inline" select="'no'"/>
5989        <xsl:with-param name="msg">keyword element appears to contain a comma-separated list, split into multiple elements instead.</xsl:with-param>
5990      </xsl:call-template>
5991    </xsl:if>
5992    <xsl:value-of select="normalize-space(.)" />
5993    <xsl:if test="position()!=last()">, </xsl:if>
5994  </xsl:for-each>
5995</xsl:template>
5996
5997<!-- get language from context node. nearest ancestor or return the default of "en" -->
5998<xsl:template name="get-lang">
5999  <xsl:choose>
6000    <xsl:when test="ancestor-or-self::*[@xml:lang]"><xsl:value-of select="ancestor-or-self::*/@xml:lang" /></xsl:when>
6001    <xsl:otherwise>en</xsl:otherwise>
6002  </xsl:choose>
6003</xsl:template>
6004
6005<xsl:template name="get-section-number">
6006  <xsl:variable name="anchor" select="@anchor"/>
6007  <xsl:choose>
6008    <xsl:when test="@x:fixed-section-number and @x:fixed-section-number!=''">
6009      <xsl:value-of select="@x:fixed-section-number"/>
6010    </xsl:when>
6011    <xsl:when test="@x:fixed-section-number and @x:fixed-section-number=''">
6012      <xsl:text>unnumbered-</xsl:text>
6013      <xsl:number count="section[@x:fixed-section-number='']" level="any"/>
6014    </xsl:when>
6015    <xsl:when test="$has-edits or ancestor::*/@x:fixed-section-number">
6016      <xsl:call-template name="sectionnumberAndEdits" />
6017    </xsl:when>
6018    <xsl:otherwise>
6019      <xsl:choose>
6020        <xsl:when test="self::references">
6021          <xsl:choose>
6022            <xsl:when test="count(/*/back/references)=1">
6023              <xsl:call-template name="get-references-section-number"/>
6024            </xsl:when>
6025            <xsl:otherwise>
6026              <xsl:call-template name="get-references-section-number"/>.<xsl:number count="references"/>
6027            </xsl:otherwise>
6028          </xsl:choose>
6029        </xsl:when>
6030        <xsl:when test="self::reference">
6031          <xsl:for-each select="parent::references">
6032            <xsl:choose>
6033              <xsl:when test="count(/*/back/references)=1">
6034                <xsl:call-template name="get-references-section-number"/>
6035              </xsl:when>
6036              <xsl:otherwise>
6037                <xsl:call-template name="get-references-section-number"/>.<xsl:number count="references"/>
6038              </xsl:otherwise>
6039            </xsl:choose>
6040          </xsl:for-each>
6041        </xsl:when>
6042        <xsl:when test="ancestor::reference">
6043          <xsl:for-each select="ancestor::reference">
6044            <xsl:call-template name="get-section-number"/>
6045          </xsl:for-each>
6046        </xsl:when>
6047        <xsl:when test="ancestor::back"><xsl:number count="section|appendix" level="multiple" format="A.1.1.1.1.1.1.1" /></xsl:when>
6048        <xsl:when test="self::appendix"><xsl:number count="appendix" level="multiple" format="A.1.1.1.1.1.1.1" /></xsl:when>
6049        <xsl:otherwise><xsl:number count="section" level="multiple"/></xsl:otherwise>
6050      </xsl:choose>
6051    </xsl:otherwise>
6052  </xsl:choose>
6053</xsl:template>
6054
6055<!-- get the section number for the references section -->
6056<xsl:template name="get-references-section-number">
6057  <xsl:value-of select="count(/rfc/middle/section) + count(/rfc/middle/ed:replace/ed:ins/section) + 1"/>
6058</xsl:template>
6059
6060<xsl:template name="emit-section-number">
6061  <xsl:param name="no"/>
6062  <xsl:value-of select="$no"/><xsl:if test="not(contains($no,'.')) or $xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
6063</xsl:template>
6064
6065<xsl:template name="get-section-type">
6066  <xsl:param name="prec" /> <!-- TODO: check this, it's unused -->
6067  <xsl:choose>
6068    <xsl:when test="ancestor::back">Appendix</xsl:when>
6069    <xsl:otherwise>Section</xsl:otherwise>
6070  </xsl:choose>
6071</xsl:template>
6072
6073<xsl:template name="get-table-anchor">
6074  <xsl:value-of select="$anchor-prefix"/>
6075  <xsl:text>.table.</xsl:text>
6076  <xsl:choose>
6077    <xsl:when test="@title!='' or @anchor!=''">
6078      <xsl:number level="any" count="texttable[@title!='' or @anchor!='']" />
6079    </xsl:when>
6080    <xsl:otherwise>
6081      <xsl:text>u.</xsl:text>
6082      <xsl:number level="any" count="texttable[not(@title!='' or @anchor!='')]" />
6083    </xsl:otherwise>
6084  </xsl:choose>
6085</xsl:template>
6086
6087<xsl:template name="get-figure-anchor">
6088  <xsl:value-of select="$anchor-prefix"/>
6089  <xsl:text>.figure.</xsl:text>
6090  <xsl:choose>
6091    <xsl:when test="@title!='' or @anchor!=''">
6092      <xsl:number level="any" count="figure[@title!='' or @anchor!='']" />
6093    </xsl:when>
6094    <xsl:otherwise>
6095      <xsl:text>u.</xsl:text>
6096      <xsl:number level="any" count="figure[not(@title!='' or @anchor!='')]" />
6097    </xsl:otherwise>
6098  </xsl:choose>
6099</xsl:template>
6100
6101<!-- reformat contents of author/@initials -->
6102<xsl:template name="format-initials">
6103  <xsl:choose>
6104    <xsl:when test="string-length(@initials)=1">
6105      <xsl:value-of select="concat(@initials,'.')"/>
6106    </xsl:when>
6107    <xsl:otherwise>
6108      <xsl:value-of select="@initials"/>
6109    </xsl:otherwise>
6110  </xsl:choose>
6111</xsl:template>
6112
6113<xsl:template name="extract-normalized">
6114  <xsl:param name="node"/>
6115  <xsl:param name="name"/>
6116  <xsl:variable name="text" select="normalize-space($node)"/>
6117  <xsl:if test="string-length($node) != string-length($text)">
6118    <xsl:call-template name="warning">
6119      <xsl:with-param name="inline" select="'no'"/>
6120      <xsl:with-param name="msg">excessive whitespace in <xsl:value-of select="$name"/>: '<xsl:value-of select="$node"/>'</xsl:with-param>
6121    </xsl:call-template>
6122  </xsl:if>
6123  <xsl:value-of select="$text"/>
6124</xsl:template>
6125
6126<!-- checking for email element -->
6127<xsl:template name="extract-email">
6128  <xsl:variable name="email" select="normalize-space(.)"/>
6129  <xsl:if test="string-length(.) != string-length($email) or contains($email,' ')">
6130    <xsl:call-template name="warning">
6131      <xsl:with-param name="inline" select="'no'"/>
6132      <xsl:with-param name="msg">excessive whitespace in email address: '<xsl:value-of select="."/>'</xsl:with-param>
6133    </xsl:call-template>
6134  </xsl:if>
6135 
6136  <xsl:variable name="email2">
6137    <xsl:choose>
6138      <xsl:when test="starts-with($email,'mailto:')">
6139        <xsl:call-template name="warning">
6140          <xsl:with-param name="inline" select="'no'"/>
6141          <xsl:with-param name="msg">email should not include URI scheme: '<xsl:value-of select="."/>'</xsl:with-param>
6142        </xsl:call-template>
6143        <xsl:value-of select="substring($email, 1 + string-length('mailto:'))"/>
6144      </xsl:when>
6145      <xsl:otherwise>
6146        <xsl:value-of select="$email"/>
6147      </xsl:otherwise>
6148    </xsl:choose>
6149  </xsl:variable>
6150 
6151  <xsl:value-of select="$email2"/>
6152</xsl:template>
6153
6154<!-- checking for uri element -->
6155<xsl:template name="extract-uri">
6156  <xsl:variable name="uri" select="normalize-space(.)"/>
6157  <xsl:if test="string-length(.) != string-length($uri) or contains($uri,' ')">
6158    <xsl:call-template name="warning">
6159      <xsl:with-param name="inline" select="'no'"/>
6160      <xsl:with-param name="msg">excessive whitespace in URI: '<xsl:value-of select="."/>'</xsl:with-param>
6161    </xsl:call-template>
6162  </xsl:if>
6163 
6164  <xsl:value-of select="$uri"/>
6165</xsl:template>
6166
6167<xsl:template name="insert-conditional-pagebreak">
6168  <xsl:if test="$xml2rfc-compact!='yes'">
6169    <xsl:attribute name="class">np</xsl:attribute>
6170  </xsl:if>
6171</xsl:template>
6172
6173<xsl:template name="insert-conditional-hrule">
6174  <xsl:if test="$xml2rfc-compact!='yes'">
6175    <hr class="noprint" />
6176  </xsl:if>
6177</xsl:template>
6178
6179<!-- get text content from marked-up text -->
6180
6181<xsl:template match="text()" mode="get-text-content">
6182  <xsl:value-of select="."/>
6183</xsl:template>
6184
6185<xsl:template match="*" mode="get-text-content">
6186  <xsl:apply-templates mode="get-text-content"/>
6187</xsl:template>
6188
6189<xsl:template match="ed:del" mode="get-text-content">
6190</xsl:template>
6191
6192<!-- parsing of processing instructions -->
6193<xsl:template name="parse-pis">
6194  <xsl:param name="nodes"/>
6195  <xsl:param name="attr"/>
6196  <xsl:param name="sep"/>
6197  <xsl:param name="ret"/>
6198  <xsl:param name="default"/>
6199 
6200  <xsl:choose>
6201    <xsl:when test="count($nodes)=0">
6202      <xsl:choose>
6203        <xsl:when test="$ret!=''">
6204          <xsl:value-of select="$ret"/>
6205        </xsl:when>
6206        <xsl:otherwise>
6207          <xsl:value-of select="$default"/>
6208        </xsl:otherwise>   
6209      </xsl:choose>
6210    </xsl:when>
6211    <xsl:otherwise>
6212      <xsl:variable name="ret2">
6213        <xsl:for-each select="$nodes[1]">
6214          <xsl:call-template name="parse-one-pi">
6215            <xsl:with-param name="str" select="."/>
6216            <xsl:with-param name="attr" select="$attr"/>
6217            <xsl:with-param name="sep" select="$sep"/>
6218            <xsl:with-param name="ret" select="$ret"/>
6219          </xsl:call-template>
6220        </xsl:for-each>
6221      </xsl:variable>
6222     
6223      <xsl:call-template name="parse-pis">
6224        <xsl:with-param name="nodes" select="$nodes[position()!=1]"/>
6225        <xsl:with-param name="attr" select="$attr"/>
6226        <xsl:with-param name="sep" select="$sep"/>
6227        <xsl:with-param name="ret" select="$ret2"/>
6228        <xsl:with-param name="default" select="$default"/>
6229      </xsl:call-template>
6230     
6231    </xsl:otherwise>
6232  </xsl:choose>
6233
6234</xsl:template>
6235
6236<xsl:template name="parse-one-pi">
6237  <xsl:param name="str"/>
6238  <xsl:param name="attr"/>
6239  <xsl:param name="sep"/>
6240  <xsl:param name="ret"/>
6241
6242  <xsl:variable name="str2">
6243    <xsl:call-template name="eat-leading-whitespace">
6244      <xsl:with-param name="str" select="$str"/>
6245    </xsl:call-template>
6246  </xsl:variable>
6247 
6248  <xsl:choose>
6249    <xsl:when test="$str2=''">
6250      <!-- done -->
6251      <xsl:value-of select="$ret"/>
6252    </xsl:when>
6253    <xsl:otherwise>
6254      <xsl:variable name="attrname" select="substring-before($str2,'=')"/>
6255     
6256      <xsl:choose>
6257        <xsl:when test="$attrname=''">
6258          <xsl:call-template name="warning">
6259            <xsl:with-param name="msg">bad PI syntax: <xsl:value-of select="$str2"/></xsl:with-param>
6260            <xsl:with-param name="inline" select="'no'"/>
6261          </xsl:call-template>
6262          <xsl:value-of select="$ret"/>
6263        </xsl:when>
6264        <xsl:otherwise>
6265          <xsl:variable name="remainder" select="substring($str2,2+string-length($attrname))"/>
626