source: rfc2629xslt/rfc2629toXHTML.xslt @ 764

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

latest version of rfc2629.xslt, bump up document dates

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