source: rfc2629xslt/rfc2629.xslt @ 689

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

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

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