source: rfc2629xslt/rfc2629toXHTML.xslt @ 723

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

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

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