source: rfc2629xslt/rfc2629.xslt @ 741

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

Update to latest version of xml2rfc and rfc2629.xslt, bump document dates

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