source: rfc2629xslt/rfc2629toXHTML.xslt @ 689

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

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

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