source: rfc2629xslt/rfc2629.xslt @ 571

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

Update to latest version of rfc2629.xslt.

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