source: rfc2629xslt/rfc2629toXHTML.xslt @ 713

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

upgrade to latest version of rfc2629.xslt/xml2rfc.tcl; remove now superfluous empty <organization/> elements in references

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