source: rfc2629xslt/rfc2629.xslt @ 704

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

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

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