source: rfc2629xslt/rfc2629toFO.xslt @ 885

Last change on this file since 885 was 832, 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: 106.0 KB
Line 
1<!--
2    XSLT transformation from RFC2629 XML format to XSL-FO
3     
4    Copyright (c) 2006-2010, Julian Reschke (julian.reschke@greenbytes.de)
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions are met:
9
10    * Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    * Neither the name of Julian Reschke nor the names of its contributors
16      may be used to endorse or promote products derived from this software
17      without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33    version="1.0"
34
35    xmlns:ed="http://greenbytes.de/2002/rfcedit"
36    xmlns:exslt="http://exslt.org/common"
37    xmlns:fo="http://www.w3.org/1999/XSL/Format"
38    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
39    xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rcf2629.xslt"
40    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
41    xmlns:x="http://purl.org/net/xml2rfc/ext"
42
43    exclude-result-prefixes="ed exslt msxsl myns rdf x"
44>
45
46<xsl:import href="rfc2629.xslt" />
47
48<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
49
50<!-- page sizes as per <http://tools.ietf.org/html/draft-rfc-editor-rfc2223bis-08#section-3.2> -->
51<xsl:attribute-set name="page">
52  <xsl:attribute name="margin-left">1in</xsl:attribute>
53  <xsl:attribute name="margin-right">1in</xsl:attribute>
54  <xsl:attribute name="page-height">11in</xsl:attribute>
55  <xsl:attribute name="page-width">8.5in</xsl:attribute>
56</xsl:attribute-set>
57
58<xsl:attribute-set name="base">
59  <xsl:attribute name="font-family">serif</xsl:attribute>
60  <xsl:attribute name="font-size">10pt</xsl:attribute>
61</xsl:attribute-set>
62
63<xsl:attribute-set name="h1">
64  <xsl:attribute name="font-weight">bold</xsl:attribute>
65  <xsl:attribute name="font-size">14pt</xsl:attribute>
66  <xsl:attribute name="keep-with-next">always</xsl:attribute>
67  <xsl:attribute name="space-before">14pt</xsl:attribute>
68  <xsl:attribute name="space-after">7pt</xsl:attribute>
69</xsl:attribute-set>
70
71<xsl:attribute-set name="h2">
72  <xsl:attribute name="font-weight">bold</xsl:attribute>
73  <xsl:attribute name="font-size">12pt</xsl:attribute>
74  <xsl:attribute name="keep-with-next">always</xsl:attribute>
75  <xsl:attribute name="space-before">12pt</xsl:attribute>
76  <xsl:attribute name="space-after">6pt</xsl:attribute>
77</xsl:attribute-set>
78
79<xsl:attribute-set name="h3">
80  <xsl:attribute name="font-weight">bold</xsl:attribute>
81  <xsl:attribute name="font-size">11pt</xsl:attribute>
82  <xsl:attribute name="keep-with-next">always</xsl:attribute>
83  <xsl:attribute name="space-before">11pt</xsl:attribute>
84  <xsl:attribute name="space-after">3pt</xsl:attribute>
85</xsl:attribute-set>
86
87<xsl:attribute-set name="comment">
88  <xsl:attribute name="font-weight">bold</xsl:attribute>
89  <xsl:attribute name="background-color">yellow</xsl:attribute>
90</xsl:attribute-set>
91
92<xsl:attribute-set name="external-link">
93  <xsl:attribute name="color">blue</xsl:attribute>
94  <xsl:attribute name="text-decoration">underline</xsl:attribute>
95</xsl:attribute-set>
96
97<xsl:attribute-set name="index">
98  <xsl:attribute name="font-size">9pt</xsl:attribute>
99</xsl:attribute-set>
100
101<xsl:attribute-set name="internal-link">
102  <xsl:attribute name="color">#000080</xsl:attribute>
103</xsl:attribute-set>
104
105<xsl:attribute-set name="newpage">
106  <xsl:attribute name="page-break-before">
107    <xsl:choose>
108      <xsl:when test="$xml2rfc-ext-duplex='yes'">right</xsl:when>
109      <xsl:otherwise>always</xsl:otherwise>
110    </xsl:choose>
111  </xsl:attribute>
112</xsl:attribute-set>
113
114<xsl:attribute-set name="title">
115  <xsl:attribute name="text-align">center</xsl:attribute>
116  <xsl:attribute name="font-weight">bold</xsl:attribute>
117  <xsl:attribute name="font-size">18pt</xsl:attribute>
118  <xsl:attribute name="space-before">3em</xsl:attribute>
119  <xsl:attribute name="space-after">3em</xsl:attribute>
120</xsl:attribute-set>
121
122<xsl:template match="abstract">
123  <fo:block xsl:use-attribute-sets="h1" id="{concat($anchor-prefix,'.abstract')}">Abstract</fo:block>
124  <xsl:apply-templates />
125</xsl:template>
126
127<!-- optimize empty lines starting artwork -->
128<xsl:template match="artwork/text()[0=count(preceding-sibling::node())]">
129  <xsl:choose>
130    <xsl:when test="substring(.,1,1)='&#10;'">
131      <xsl:value-of select="substring(.,2)" />
132    </xsl:when>
133    <xsl:otherwise>
134      <xsl:value-of select="." />
135    </xsl:otherwise>
136  </xsl:choose>
137</xsl:template>
138
139<xsl:template name="add-artwork-attr">
140  <xsl:choose>
141    <xsl:when test="@type='abnf' or @type='abnf2045' or @type='abnf2616' or @type='application/xml-dtd' or @type='application/relax-ng-compact-syntax'">
142      <!-- just display inline -->
143    </xsl:when>
144
145    <xsl:when test="starts-with(@type,'message/http') and contains(@type,'msgtype=&quot;request&quot;')">
146      <xsl:attribute name="background-color">#f0f0f0</xsl:attribute>
147      <xsl:attribute name="border-style">dotted</xsl:attribute>
148      <xsl:attribute name="border-width">thin</xsl:attribute>
149    </xsl:when>
150
151    <xsl:when test="starts-with(@type,'message/http')">
152      <xsl:attribute name="background-color">#f8f8f8</xsl:attribute>
153      <xsl:attribute name="border-style">dotted</xsl:attribute>
154      <xsl:attribute name="border-width">thin</xsl:attribute>
155    </xsl:when>
156
157    <xsl:when test="starts-with(@type,'text/plain') or @type='example' or @type='code'">
158      <xsl:attribute name="background-color">#f8f8f8</xsl:attribute>
159      <xsl:attribute name="border-style">dotted</xsl:attribute>
160      <xsl:attribute name="border-width">thin</xsl:attribute>
161    </xsl:when>
162
163    <xsl:otherwise>
164      <xsl:attribute name="background-color">#dddddd</xsl:attribute>
165      <xsl:attribute name="font-size">9pt</xsl:attribute>
166    </xsl:otherwise>
167  </xsl:choose>
168 
169  <xsl:choose>
170    <xsl:when test="@align='center'">
171      <xsl:attribute name="text-align">center</xsl:attribute>
172    </xsl:when>
173    <xsl:when test="@align='right'">
174      <xsl:attribute name="text-align">right</xsl:attribute>
175    </xsl:when>
176    <xsl:otherwise/>
177  </xsl:choose>
178</xsl:template>
179
180<xsl:template match="artwork">
181  <xsl:if test="@x:isCodeComponent='yes'">
182    <fo:block font-family="monospace" color="gray">&lt;CODE BEGINS></fo:block>
183  </xsl:if>
184  <fo:block font-family="monospace" padding=".5em"
185    white-space-treatment="preserve" linefeed-treatment="preserve"
186    white-space-collapse="false" page-break-inside="avoid">
187    <xsl:call-template name="add-artwork-attr"/>
188    <xsl:apply-templates/>
189  </fo:block>
190  <xsl:if test="@x:isCodeComponent='yes'">
191    <fo:block font-family="monospace" color="gray">&lt;CODE ENDS></fo:block>
192  </xsl:if>
193</xsl:template>
194
195<xsl:template match="artwork[@src and starts-with(@type,'image/')]">
196  <fo:block>
197    <xsl:choose>
198      <xsl:when test="@align='center'">
199        <xsl:attribute name="text-align">center</xsl:attribute>
200      </xsl:when>
201      <xsl:when test="@align='right'">
202        <xsl:attribute name="text-align">right</xsl:attribute>
203      </xsl:when>
204      <xsl:otherwise/>
205    </xsl:choose>
206    <fo:external-graphic scaling-method="integer-pixels" src="url({@src})">
207    </fo:external-graphic>
208  </fo:block>
209</xsl:template>
210
211<xsl:template match="author">
212  <fo:block start-indent="2em" space-before=".5em" space-after=".5em">
213    <fo:block>
214      <fo:wrapper font-weight="bold"><xsl:value-of select="@fullname" /></fo:wrapper>
215      <xsl:if test="@role">
216        <fo:wrapper> (<xsl:value-of select="@role" />)</fo:wrapper>
217      </xsl:if>
218      <!-- annotation support for Martin "uuml" Duerst -->
219      <xsl:if test="@x:annotation">
220        <xsl:text> </xsl:text>
221        <fo:wrapper font-style="italic"><xsl:value-of select="@x:annotation"/></fo:wrapper>
222      </xsl:if>
223    </fo:block>
224    <fo:block><xsl:value-of select="organization" /></fo:block>
225    <xsl:for-each select="address/postal/street">
226      <fo:block><xsl:value-of select="." /></fo:block>
227    </xsl:for-each>
228    <xsl:if test="address/postal/city">
229      <fo:block><xsl:value-of select="concat(address/postal/city,', ',address/postal/region,' ',address/postal/code)" /></fo:block>
230    </xsl:if>
231    <xsl:if test="address/postal/country">
232      <fo:block><xsl:value-of select="address/postal/country" /></fo:block>
233    </xsl:if>
234    <xsl:if test="address/phone">
235      <fo:block>Phone:&#0160;<fo:basic-link external-destination="url('tel:{translate(address/phone,' ','')}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="address/phone" /></fo:basic-link></fo:block>
236    </xsl:if>
237    <xsl:if test="address/facsimile">
238      <fo:block>Fax:&#0160;<fo:basic-link external-destination="url('tel:{translate(address/facsimile,' ','')}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="address/facsimile" /></fo:basic-link></fo:block>
239    </xsl:if>
240    <xsl:for-each select="address/email">
241      <xsl:variable name="email">
242        <xsl:call-template name="extract-email"/>
243      </xsl:variable>
244      <fo:block>EMail:&#0160;
245        <xsl:choose>
246          <xsl:when test="$xml2rfc-linkmailto='no'">
247              <xsl:value-of select="$email" />
248          </xsl:when>
249          <xsl:otherwise>
250            <fo:basic-link external-destination="url('mailto:{$email}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="$email" /></fo:basic-link>
251          </xsl:otherwise>
252        </xsl:choose>
253      </fo:block>
254    </xsl:for-each>
255    <xsl:for-each select="address/uri">
256      <xsl:variable name="uri">
257        <xsl:call-template name="extract-uri"/>
258      </xsl:variable>
259      <fo:block>
260        <xsl:text>URI:&#0160;</xsl:text>
261        <fo:basic-link external-destination="url('{$uri}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="$uri" /></fo:basic-link>
262        <xsl:if test="@x:annotation">
263          <xsl:text> </xsl:text>
264          <fo:wrapper font-style="italic"><xsl:value-of select="@x:annotation"/></fo:wrapper>
265        </xsl:if>
266      </fo:block>
267    </xsl:for-each>
268  </fo:block>
269</xsl:template>
270
271<xsl:template match="back">
272  <!-- done in parent template -->
273</xsl:template>
274
275
276<xsl:template match="figure">
277
278  <xsl:variable name="anch">
279    <xsl:call-template name="get-figure-anchor"/>
280  </xsl:variable>
281
282  <fo:block space-before=".5em" space-after=".5em" id="{$anch}" page-break-inside="avoid">
283    <xsl:if test="not(ancestor::t)">
284      <xsl:attribute name="start-indent">2em</xsl:attribute>
285    </xsl:if>
286    <xsl:call-template name="add-anchor"/>
287    <xsl:apply-templates />
288    <xsl:if test="(@title!='' or @anchor!='') and not(@suppress-title='true')">
289      <xsl:variable name="n"><xsl:number level="any" count="figure[(@title!='' or @anchor!='') and not(@suppress-title='true')]" /></xsl:variable>
290      <fo:block text-align="center" space-before=".5em" space-after="1em">Figure <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title" /></xsl:if></fo:block>
291    </xsl:if>
292  </fo:block>
293</xsl:template>
294           
295<xsl:template match="front">
296
297  <xsl:if test="$xml2rfc-topblock!='no'">
298    <!-- collect information for left column -->
299     
300    <xsl:variable name="leftColumn">
301      <xsl:call-template name="collectLeftHeaderColumn" /> 
302    </xsl:variable>
303 
304    <!-- collect information for right column -->
305     
306    <xsl:variable name="rightColumn">
307      <xsl:call-template name="collectRightHeaderColumn" />   
308    </xsl:variable>
309     
310      <!-- insert the collected information -->
311     
312    <fo:table width="100%" table-layout="fixed">
313      <fo:table-column column-width="proportional-column-width(1)" />
314      <fo:table-column column-width="proportional-column-width(1)" />
315      <fo:table-body>
316        <xsl:choose>
317          <xsl:when test="function-available('exslt:node-set')">
318             <xsl:call-template name="emitheader">
319               <xsl:with-param name="lc" select="exslt:node-set($leftColumn)" />   
320               <xsl:with-param name="rc" select="exslt:node-set($rightColumn)" />   
321            </xsl:call-template>
322          </xsl:when>   
323          <xsl:otherwise>   
324             <xsl:call-template name="emitheader">
325               <xsl:with-param name="lc" select="$leftColumn" />   
326               <xsl:with-param name="rc" select="$rightColumn" />   
327            </xsl:call-template>
328          </xsl:otherwise>   
329        </xsl:choose>
330      </fo:table-body>
331    </fo:table>
332  </xsl:if>
333     
334  <fo:block xsl:use-attribute-sets="title">
335    <xsl:apply-templates select="/rfc/front/title" mode="get-text-content" />
336    <xsl:if test="/rfc/@docName">
337      <fo:block font-size="80%"><xsl:value-of select="/rfc/@docName" /></fo:block>
338    </xsl:if>
339  </fo:block>
340 
341  <xsl:if test="$xml2rfc-private='' and not($abstract-first)">
342    <xsl:call-template name="emit-ietf-preamble"/>
343  </xsl:if>
344 
345  <xsl:apply-templates select="x:boilerplate"/>
346  <xsl:apply-templates select="abstract" />
347  <xsl:apply-templates select="note" />
348
349  <xsl:if test="$xml2rfc-private='' and $abstract-first">
350    <xsl:call-template name="emit-ietf-preamble"/>
351  </xsl:if>
352
353  <xsl:if test="$xml2rfc-toc='yes'">
354    <xsl:apply-templates select="/" mode="toc" />
355    <!--<xsl:call-template name="insertTocAppendix" />-->
356  </xsl:if>
357
358</xsl:template>
359   
360<xsl:template match="eref[node()]">
361  <fo:basic-link external-destination="url('{@target}')" xsl:use-attribute-sets="external-link">
362    <xsl:call-template name="format-uri">
363      <xsl:with-param name="s" select="."/>
364    </xsl:call-template>
365  </fo:basic-link>
366  <fo:footnote>
367    <fo:inline font-size="6pt" vertical-align="super"><xsl:number level="any" count="eref[node()]" /></fo:inline>
368    <fo:footnote-body>
369      <fo:block font-size="8pt" start-indent="2em" text-align="left">
370        <fo:inline font-size="6pt" vertical-align="super"><xsl:number level="any" count="eref[node()]" /></fo:inline>
371        <xsl:text> </xsl:text>
372        <xsl:value-of select="@target" />
373      </fo:block>
374    </fo:footnote-body>
375  </fo:footnote>
376</xsl:template>
377
378<xsl:template match="eref[not(node())]">
379  <xsl:text>&lt;</xsl:text>
380  <fo:basic-link external-destination="url('{@target}')" xsl:use-attribute-sets="external-link">
381    <xsl:call-template name="format-uri">
382      <xsl:with-param name="s" select="@target"/>
383    </xsl:call-template>
384  </fo:basic-link>
385  <xsl:text>&gt;</xsl:text>
386</xsl:template>
387
388<!-- processed in a later stage -->
389<xsl:template match="iref[not(ancestor::t) and not(parent::section)]">
390  <fo:block>
391    <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix" />.iref.<xsl:number level="any"/></xsl:attribute>
392    <xsl:choose>
393      <xsl:when test="@primary='true'">
394        <xsl:attribute name="index-key">
395          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem,',primary')"/>
396        </xsl:attribute>
397      </xsl:when>
398      <xsl:otherwise>
399        <xsl:attribute name="index-key">
400          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem)"/>
401        </xsl:attribute>
402      </xsl:otherwise>
403    </xsl:choose>
404  </fo:block>
405</xsl:template>
406
407<xsl:template match="iref[parent::section]">
408  <!-- processed on section level -->
409</xsl:template>
410
411<xsl:template match="iref[ancestor::t and not(parent::section)]">
412  <fo:inline>
413    <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix" />.iref.<xsl:number level="any"/></xsl:attribute>
414    <xsl:choose>
415      <xsl:when test="@primary='true'">
416        <xsl:attribute name="index-key">
417          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem,',primary')"/>
418        </xsl:attribute>
419      </xsl:when>
420      <xsl:otherwise>
421        <xsl:attribute name="index-key">
422          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem)"/>
423        </xsl:attribute>
424      </xsl:otherwise>
425    </xsl:choose>
426  </fo:inline>
427</xsl:template>
428
429<xsl:template match="iref" mode="iref-start">
430  <fo:index-range-begin>
431    <xsl:attribute name="id"><xsl:value-of select="$anchor-prefix" />.iref.<xsl:number level="any"/></xsl:attribute>
432    <xsl:choose>
433      <xsl:when test="@primary='true'">
434        <xsl:attribute name="index-key">
435          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem,',primary')"/>
436        </xsl:attribute>
437      </xsl:when>
438      <xsl:otherwise>
439        <xsl:attribute name="index-key">
440          <xsl:value-of select="concat('item=',@item,',subitem=',@subitem)"/>
441        </xsl:attribute>
442      </xsl:otherwise>
443    </xsl:choose>
444  </fo:index-range-begin>
445</xsl:template>
446
447<xsl:template match="iref" mode="iref-end">
448  <fo:index-range-end>
449    <xsl:attribute name="ref-id"><xsl:value-of select="$anchor-prefix" />.iref.<xsl:number level="any"/></xsl:attribute>
450  </fo:index-range-end>
451</xsl:template>
452
453<xsl:template match="list[@style='hanging']" priority="1">
454
455  <xsl:variable name="width">
456    <xsl:choose>
457      <xsl:when test="@x:indent">
458        <xsl:value-of select="@x:indent"/>
459      </xsl:when>
460      <xsl:otherwise>
461        <!-- find longest label and use it to calculate indentation-->
462        <xsl:variable name="l">
463          <xsl:for-each select="t">
464            <xsl:sort select="string-length(@hangText)" order="descending" data-type="number"/>
465            <xsl:if test="position()=1">
466              <xsl:value-of select="@hangText" />
467            </xsl:if>
468          </xsl:for-each>
469        </xsl:variable>
470        <xsl:value-of select="concat(format-number(string-length($l) * 0.8, '#.0'),'em')"/>
471      </xsl:otherwise>
472    </xsl:choose>
473  </xsl:variable>
474
475  <fo:list-block provisional-distance-between-starts="{$width}">
476    <xsl:apply-templates />
477  </fo:list-block>
478</xsl:template>
479
480<xsl:template match="list[@style='hanging']/x:lt" priority="1">
481  <fo:list-item space-before=".25em" space-after=".25em">
482    <xsl:call-template name="copy-anchor"/>
483    <fo:list-item-label end-indent="label-end()"><fo:block><xsl:value-of select="@hangText" /></fo:block></fo:list-item-label>
484    <fo:list-item-body start-indent="body-start()">
485      <xsl:for-each select="t">
486        <fo:block>
487          <xsl:if test="position()!=1">
488            <xsl:attribute name="space-before">.25em</xsl:attribute>
489          </xsl:if>
490          <xsl:apply-templates />
491        </fo:block>
492      </xsl:for-each>
493    </fo:list-item-body>
494  </fo:list-item>
495</xsl:template>
496
497<xsl:template match="list[@style='hanging']/t | list[@style='hanging']/ed:replace/ed:ins/t" priority="1">
498  <fo:list-item space-before=".25em" space-after=".25em">
499    <xsl:call-template name="copy-anchor"/>
500    <fo:list-item-label end-indent="label-end()"><fo:block><xsl:value-of select="@hangText" /></fo:block></fo:list-item-label>
501    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
502  </fo:list-item>
503</xsl:template>
504
505<xsl:template match="list[@style='symbols']" priority="1">
506  <fo:list-block provisional-distance-between-starts="1.5em">
507    <xsl:apply-templates />
508  </fo:list-block>
509</xsl:template>
510
511<xsl:template match="list[@style='symbols']/t" priority="1">
512  <fo:list-item space-before=".25em" space-after=".25em">
513    <xsl:call-template name="copy-anchor"/>
514    <fo:list-item-label end-indent="label-end()"><fo:block>&#x2022;</fo:block></fo:list-item-label>
515    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
516  </fo:list-item>
517</xsl:template>
518
519<xsl:template match="list[@style='symbols']/x:lt" priority="1">
520  <fo:list-item space-before=".25em" space-after=".25em">
521    <xsl:call-template name="copy-anchor"/>
522    <fo:list-item-label end-indent="label-end()"><fo:block>&#x2022;</fo:block></fo:list-item-label>
523    <fo:list-item-body start-indent="body-start()">
524      <xsl:for-each select="t">
525        <fo:block>
526          <xsl:if test="position()!=1">
527            <xsl:attribute name="space-before">.25em</xsl:attribute>
528          </xsl:if>
529          <xsl:apply-templates />
530        </fo:block>
531      </xsl:for-each>
532    </fo:list-item-body>
533  </fo:list-item>
534</xsl:template>
535
536<xsl:template match="list">
537  <xsl:if test="@style!='' and @style!='empty' and @style">
538    <xsl:call-template name="warning">
539      <xsl:with-param name="inline" select="'no'"/>
540      <xsl:with-param name="msg">unknown style '<xsl:value-of select="@style"/>' for list, continueing with default format.</xsl:with-param>
541    </xsl:call-template>
542  </xsl:if>
543  <fo:list-block provisional-distance-between-starts="2em">
544    <xsl:apply-templates />
545  </fo:list-block>
546</xsl:template>
547
548<xsl:template match="list/t">
549  <fo:list-item space-before=".25em" space-after=".25em">
550    <xsl:call-template name="copy-anchor"/>
551    <fo:list-item-label end-indent="label-end()"><fo:block></fo:block></fo:list-item-label>
552    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
553  </fo:list-item>
554</xsl:template>
555
556<xsl:template match="list[@style='numbers' or @style='letters']" priority="1">
557  <fo:list-block provisional-distance-between-starts="1.5em">
558    <xsl:apply-templates />
559  </fo:list-block>
560</xsl:template>
561
562<xsl:template match="list[@style='numbers' or @style='letters']/t" priority="1">
563  <fo:list-item space-before=".25em" space-after=".25em">
564    <xsl:call-template name="copy-anchor"/>
565    <fo:list-item-label end-indent="label-end()">
566      <fo:block>
567        <xsl:choose>
568          <xsl:when test="ancestor::list/@style='numbers'"><xsl:number/>.</xsl:when>
569          <xsl:when test="ancestor::list/@style='letters'"><xsl:number format="a"/>.</xsl:when>
570          <xsl:otherwise>???</xsl:otherwise>
571        </xsl:choose>
572      </fo:block>
573    </fo:list-item-label>
574    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
575  </fo:list-item>
576</xsl:template>
577
578<xsl:template match="list[@style='numbers' or @style='letters']/x:lt" priority="1">
579  <fo:list-item space-before=".25em" space-after=".25em">
580    <xsl:call-template name="copy-anchor"/>
581    <fo:list-item-label end-indent="label-end()">
582      <fo:block>
583        <xsl:choose>
584          <xsl:when test="ancestor::list/@style='numbers'"><xsl:number/>.</xsl:when>
585          <xsl:when test="ancestor::list/@style='letters'"><xsl:number format="a"/>.</xsl:when>
586          <xsl:otherwise>???</xsl:otherwise>
587        </xsl:choose>
588      </fo:block>
589    </fo:list-item-label>
590    <fo:list-item-body start-indent="body-start()">
591      <xsl:for-each select="t">
592        <fo:block>
593          <xsl:if test="position()!=1">
594            <xsl:attribute name="space-before">.25em</xsl:attribute>
595          </xsl:if>
596          <xsl:apply-templates />
597        </fo:block>
598      </xsl:for-each>
599    </fo:list-item-body>
600  </fo:list-item>
601</xsl:template>
602
603<!-- special case: nested -->
604<xsl:template match="list//t//list[@style='letters']/t" priority="9">
605  <fo:list-item space-before=".25em" space-after=".25em">
606    <xsl:call-template name="copy-anchor"/>
607    <fo:list-item-label end-indent="label-end()"><fo:block><xsl:number format="A"/>.</fo:block></fo:list-item-label>
608    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
609  </fo:list-item>
610</xsl:template>
611
612<xsl:template match="list[starts-with(@style,'format ')]" priority="1">
613  <fo:list-block provisional-distance-between-starts="{string-length(@style) - string-length('format ')}em">
614    <xsl:apply-templates />
615  </fo:list-block>
616</xsl:template>
617
618<xsl:template match="list[starts-with(@style,'format ') and (contains(@style,'%c') or contains(@style,'%d'))]/t" priority="1">
619  <xsl:variable name="list" select=".." />
620  <xsl:variable name="format" select="substring-after(../@style,'format ')" />
621  <xsl:variable name="pos">
622    <xsl:choose>
623      <xsl:when test="$list/@counter">
624        <xsl:number level="any" count="list[@counter=$list/@counter or (not(@counter) and @style=concat('format ',$list/@counter))]/t" />
625      </xsl:when>
626      <xsl:otherwise>
627        <xsl:number level="any" count="list[concat('format ',@counter)=$list/@style or (not(@counter) and @style=$list/@style)]/t" />
628      </xsl:otherwise>
629    </xsl:choose>
630  </xsl:variable>
631  <fo:list-item space-before=".25em" space-after=".25em">
632    <xsl:call-template name="copy-anchor"/>
633    <fo:list-item-label end-indent="label-end()">
634      <fo:block>
635        <xsl:choose>
636          <xsl:when test="contains($format,'%c')">
637            <xsl:value-of select="substring-before($format,'%c')"/><xsl:number value="$pos" format="a" /><xsl:value-of select="substring-after($format,'%c')"/>
638          </xsl:when>
639          <xsl:otherwise>
640            <xsl:value-of select="substring-before($format,'%d')"/><xsl:number value="$pos" format="1" /><xsl:value-of select="substring-after($format,'%d')"/>
641          </xsl:otherwise>
642        </xsl:choose>
643      </fo:block>
644    </fo:list-item-label>
645    <fo:list-item-body start-indent="body-start()">
646      <fo:block>
647        <xsl:apply-templates />
648      </fo:block>
649    </fo:list-item-body>
650  </fo:list-item>
651</xsl:template>
652
653<xsl:template match="middle">
654  <xsl:apply-templates />
655</xsl:template>
656               
657<xsl:template match="note">
658  <xsl:variable name="num"><xsl:number count="note"/></xsl:variable>
659  <fo:block xsl:use-attribute-sets="h1" id="{concat($anchor-prefix,'.note.',$num)}"><xsl:value-of select="@title" /></fo:block>
660  <xsl:apply-templates />
661</xsl:template>
662
663<xsl:template match="preamble">
664  <fo:block space-after=".5em">
665    <xsl:call-template name="copy-anchor"/>
666    <xsl:apply-templates />
667  </fo:block>
668</xsl:template>
669
670<xsl:template match="postamble">
671  <fo:block space-before=".5em"><xsl:apply-templates /></fo:block>
672</xsl:template>
673
674<xsl:template match="reference">
675
676  <xsl:variable name="target">
677    <xsl:choose>
678      <xsl:when test="@target"><xsl:value-of select="@target" /></xsl:when>
679      <xsl:when test="seriesInfo/@name='RFC'"><xsl:value-of select="concat($rfcUrlPrefix,seriesInfo[@name='RFC']/@value,'.txt')" /></xsl:when>
680      <xsl:when test="seriesInfo[starts-with(.,'RFC')]">
681        <xsl:variable name="rfcRef" select="seriesInfo[starts-with(.,'RFC')]" />
682        <xsl:value-of select="concat($rfcUrlPrefix,substring-after (normalize-space($rfcRef), ' '),'.txt')" />
683      </xsl:when>
684      <xsl:otherwise />
685    </xsl:choose>
686  </xsl:variable>
687
688  <fo:list-item space-after=".5em">
689    <fo:list-item-label end-indent="label-end()">
690      <fo:block id="{@anchor}">
691        <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
692          <xsl:attribute name="index-key">
693            <xsl:value-of select="concat('xrefitem=',@anchor)"/>
694          </xsl:attribute>
695        </xsl:if>
696        <xsl:call-template name="referencename">
697          <xsl:with-param name="node" select="." />
698        </xsl:call-template>
699      </fo:block>
700    </fo:list-item-label>
701   
702    <fo:list-item-body start-indent="body-start()"><fo:block>
703
704      <xsl:for-each select="front/author">
705        <xsl:variable name="initials">
706          <xsl:call-template name="format-initials"/>
707        </xsl:variable>
708        <xsl:variable name="truncated-initials" select="concat(substring-before($initials,'.'),'.')"/>
709        <xsl:choose>
710          <xsl:when test="@surname and @surname!=''">
711            <xsl:choose>
712              <xsl:when test="@surname and position()=last() and position()!=1">
713                <xsl:value-of select="concat($truncated-initials,' ',@surname)" />
714              </xsl:when>
715              <xsl:when test="@surname">
716                <xsl:value-of select="concat(@surname,', ',$truncated-initials)" />
717              </xsl:when>
718              <xsl:when test="organization/text()">
719                <xsl:value-of select="organization" />
720              </xsl:when>
721              <xsl:otherwise />
722            </xsl:choose>
723            <xsl:if test="@role='editor'">
724              <xsl:text>, Ed.</xsl:text>
725            </xsl:if>
726            <xsl:choose>
727              <xsl:when test="position()=last() - 1">
728                <xsl:if test="last() &gt; 2">,</xsl:if>
729                <xsl:text> and </xsl:text>
730              </xsl:when>
731              <xsl:otherwise>
732                <xsl:text>, </xsl:text>
733              </xsl:otherwise>
734            </xsl:choose>
735          </xsl:when>
736          <xsl:when test="organization/text()">
737            <xsl:value-of select="organization" />
738            <xsl:choose>
739              <xsl:when test="position()=last() - 1">
740                <xsl:if test="last() &gt; 2">,</xsl:if>
741                <xsl:text> and </xsl:text>
742              </xsl:when>
743              <xsl:otherwise>
744                <xsl:text>, </xsl:text>
745              </xsl:otherwise>
746            </xsl:choose>
747          </xsl:when>
748          <xsl:otherwise />
749        </xsl:choose>
750      </xsl:for-each>
751
752      <xsl:text>"</xsl:text>
753      <xsl:choose>
754        <xsl:when test="string-length($target) &gt; 0">
755          <fo:basic-link external-destination="url('{$target}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="normalize-space(front/title)" /></fo:basic-link>
756        </xsl:when>
757        <xsl:otherwise>
758          <xsl:value-of select="normalize-space(front/title)" />
759        </xsl:otherwise>
760      </xsl:choose>
761      <xsl:text>"</xsl:text>
762     
763      <xsl:for-each select="seriesInfo">
764        <xsl:text>, </xsl:text>
765        <xsl:choose>
766          <xsl:when test="not(@name) and not(@value) and ./text()"><xsl:value-of select="." /></xsl:when>
767          <xsl:otherwise>
768            <xsl:value-of select="@name" />
769            <xsl:if test="@value!=''">&#0160;<xsl:value-of select="@value" /></xsl:if>
770            <xsl:if test="translate(@name,$ucase,$lcase)='internet-draft'"> (work in progress)</xsl:if>
771          </xsl:otherwise>
772        </xsl:choose>
773      </xsl:for-each>
774
775      <xsl:if test="front/date/@year!=''">
776        <xsl:text>, </xsl:text>
777        <xsl:value-of select="front/date/@month" />&#0160;<xsl:value-of select="front/date/@year" />
778      </xsl:if>
779     
780      <xsl:if test="@target">
781        <xsl:text>, &lt;</xsl:text>
782        <xsl:call-template name="format-uri">
783          <xsl:with-param name="s" select="@target"/>
784        </xsl:call-template>
785        <xsl:text>&gt;</xsl:text>
786      </xsl:if>
787
788      <xsl:text>.</xsl:text>
789     
790      <xsl:for-each select="annotation">
791        <fo:block><xsl:apply-templates /></fo:block>
792      </xsl:for-each>
793     
794    </fo:block></fo:list-item-body>
795  </fo:list-item>
796</xsl:template>
797
798<xsl:template match="references">
799
800  <xsl:variable name="name">
801    <xsl:number/>     
802  </xsl:variable>
803
804  <!-- insert pseudo section when needed -->
805  <xsl:if test="$name='1' and count(/*/back/references)!=1">
806    <fo:block id="{$anchor-prefix}.references" xsl:use-attribute-sets="h1">
807      <xsl:if test="$name='1'">
808        <xsl:attribute name="page-break-before">always</xsl:attribute>
809      </xsl:if>
810      <xsl:variable name="sectionNumber">
811        <xsl:call-template name="get-references-section-number"/>
812      </xsl:variable>
813      <xsl:call-template name="emit-section-number">
814        <xsl:with-param name="no" select="$sectionNumber"/>
815      </xsl:call-template>
816      <xsl:text>&#160;&#160;</xsl:text>
817      <xsl:value-of select="$xml2rfc-refparent"/>
818    </fo:block>
819  </xsl:if>
820
821  <xsl:choose>
822    <xsl:when test="count(/*/back/references)=1">
823      <fo:block id="{$anchor-prefix}.references" xsl:use-attribute-sets="h1 newpage">
824        <xsl:variable name="sectionNumber">
825          <xsl:call-template name="get-section-number"/>
826        </xsl:variable>
827        <xsl:call-template name="emit-section-number">
828          <xsl:with-param name="no" select="$sectionNumber"/>
829        </xsl:call-template>
830        <xsl:text>&#160;&#160;</xsl:text>
831        <xsl:choose>
832          <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
833          <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
834        </xsl:choose>
835      </fo:block>
836    </xsl:when>
837    <xsl:otherwise>
838      <fo:block id="{$anchor-prefix}.references.{$name}" xsl:use-attribute-sets="h2">
839        <xsl:variable name="sectionNumber">
840          <xsl:call-template name="get-section-number"/>
841        </xsl:variable>
842        <xsl:call-template name="emit-section-number">
843          <xsl:with-param name="no" select="$sectionNumber"/>
844        </xsl:call-template>
845        <xsl:text>&#160;&#160;</xsl:text>
846        <xsl:choose>
847          <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
848          <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
849        </xsl:choose>
850      </fo:block>
851    </xsl:otherwise>
852  </xsl:choose>
853
854  <!-- find longest label and use it to calculate indentation-->
855  <xsl:variable name="l">
856    <xsl:choose>
857      <xsl:when test="$xml2rfc-symrefs='no'">[99]</xsl:when>
858      <xsl:otherwise>
859        <xsl:for-each select="//reference">
860          <xsl:sort select="string-length(@anchor)" order="descending" data-type="number"/>
861          <xsl:if test="position()=1">
862            <xsl:value-of select="@anchor" />
863          </xsl:if>
864        </xsl:for-each>
865      </xsl:otherwise>
866    </xsl:choose>
867  </xsl:variable>
868
869  <fo:list-block provisional-distance-between-starts="{string-length($l) * 0.8}em">
870    <xsl:choose>
871      <xsl:when test="$xml2rfc-sortrefs='yes'">
872        <xsl:apply-templates>
873          <xsl:sort select="@anchor" />
874        </xsl:apply-templates>
875      </xsl:when>
876      <xsl:otherwise>
877        <xsl:apply-templates />
878      </xsl:otherwise>
879    </xsl:choose>
880  </fo:list-block>
881</xsl:template>
882
883<xsl:template match="rfc">
884  <fo:root xsl:use-attribute-sets="base">
885   
886    <fo:layout-master-set>
887      <fo:simple-page-master master-name="first-page" xsl:use-attribute-sets="page">
888        <fo:region-body margin-bottom="1in" margin-top="1in"/>
889         <fo:region-after extent="1cm" region-name="footer"/>
890      </fo:simple-page-master>
891      <fo:simple-page-master master-name="other-pages-right" xsl:use-attribute-sets="page">
892        <fo:region-body margin-bottom="1in" margin-top="1in" />
893        <fo:region-before extent="1cm" region-name="header-right"/>
894        <fo:region-after extent="1cm" region-name="footer-right"/>
895      </fo:simple-page-master>
896      <fo:simple-page-master master-name="other-pages-left" xsl:use-attribute-sets="page">
897        <fo:region-body margin-bottom="1in" margin-top="1in" />
898        <fo:region-before extent="1cm" region-name="header-left"/>
899        <fo:region-after extent="1cm" region-name="footer-left"/>
900      </fo:simple-page-master>
901      <fo:simple-page-master master-name="other-pages-dc-right" xsl:use-attribute-sets="page">
902        <fo:region-body margin-bottom="1in" margin-top="1in" column-count="2"/>
903        <fo:region-before extent="1cm" region-name="header-right"/>
904        <fo:region-after extent="1cm" region-name="footer-right"/>
905      </fo:simple-page-master>
906      <fo:simple-page-master master-name="other-pages-dc-left" xsl:use-attribute-sets="page">
907        <fo:region-body margin-bottom="1in" margin-top="1in" column-count="2"/>
908        <fo:region-before extent="1cm" region-name="header-left"/>
909        <fo:region-after extent="1cm" region-name="footer-left"/>
910      </fo:simple-page-master>
911      <fo:page-sequence-master master-name="sequence"> 
912        <fo:single-page-master-reference master-reference="first-page" />
913        <xsl:choose>
914          <xsl:when test="$xml2rfc-ext-duplex='yes'">
915            <fo:repeatable-page-master-alternatives>
916              <fo:conditional-page-master-reference odd-or-even="even" master-reference="other-pages-left"/>
917              <fo:conditional-page-master-reference odd-or-even="odd" master-reference="other-pages-right"/>
918            </fo:repeatable-page-master-alternatives>
919          </xsl:when>
920          <xsl:otherwise>
921            <fo:repeatable-page-master-reference master-reference="other-pages-right" /> 
922          </xsl:otherwise>
923        </xsl:choose>
924      </fo:page-sequence-master>
925      <fo:page-sequence-master master-name="sequence-dc"> 
926        <xsl:choose>
927          <xsl:when test="$xml2rfc-ext-duplex='yes'">
928            <fo:repeatable-page-master-alternatives>
929              <fo:conditional-page-master-reference odd-or-even="even" master-reference="other-pages-dc-left"/>
930              <fo:conditional-page-master-reference odd-or-even="odd" master-reference="other-pages-dc-right"/>
931            </fo:repeatable-page-master-alternatives>
932          </xsl:when>
933          <xsl:otherwise>
934            <fo:repeatable-page-master-reference master-reference="other-pages-dc-right" /> 
935          </xsl:otherwise>
936        </xsl:choose>
937      </fo:page-sequence-master>
938    </fo:layout-master-set>
939
940    <fo:declarations>
941      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
942        <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
943          <dc:title><xsl:value-of select="/rfc/front/title"/></dc:title>
944          <dc:creator><xsl:call-template name="get-author-summary" /></dc:creator>
945          <dc:description><xsl:value-of select="normalize-space(/rfc/front/abstract)"/></dc:description>
946          <xsl:if test="/rfc/@number">
947            <dc:isPartOf>urn:ISSN:2070-1721</dc:isPartOf>
948          </xsl:if>     
949          <xsl:if test="/rfc/front/keyword" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
950            <pdf:Keywords>
951              <xsl:for-each select="/rfc/front/keyword">
952                <xsl:value-of select="."/>
953                <xsl:if test="position()!=last()">, </xsl:if>
954              </xsl:for-each>
955            </pdf:Keywords>
956          </xsl:if>
957        </rdf:Description>
958      </rdf:RDF>
959    </fo:declarations>
960   
961    <fo:bookmark-tree>
962      <xsl:apply-templates select="." mode="bookmarks" />
963    </fo:bookmark-tree>
964
965    <xsl:variable name="lang"><xsl:call-template name="get-lang"/></xsl:variable>
966
967    <fo:page-sequence master-reference="sequence" language="{$lang}">
968      <xsl:if test="$xml2rfc-ext-duplex='yes'">
969        <xsl:attribute name="force-page-count">even</xsl:attribute>
970      </xsl:if>
971
972      <xsl:call-template name="insertHeader" />
973      <xsl:call-template name="insertFooter" />
974     
975      <fo:flow flow-name="xsl-region-body">
976       
977        <!-- process front & middle section, but not back -->
978        <xsl:apply-templates />
979       
980        <!-- because it requires multiple page masters -->
981        <!-- references first -->
982        <xsl:apply-templates select="back/references" />
983       
984        <xsl:if test="$xml2rfc-ext-authors-section!='end'">
985          <xsl:call-template name="insertAuthors" />
986        </xsl:if>
987       
988        <!-- add all other top-level sections under <back> -->
989        <xsl:apply-templates select="back/*[not(self::references)]" />
990     
991      </fo:flow>
992    </fo:page-sequence>
993   
994    <xsl:if test="$has-index">
995      <fo:page-sequence master-reference="sequence-dc" language="{$lang}">
996        <xsl:if test="$xml2rfc-ext-duplex='yes'">
997          <xsl:attribute name="force-page-count">even</xsl:attribute>
998        </xsl:if>
999        <xsl:call-template name="insertHeader" />
1000        <xsl:call-template name="insertFooter" />
1001        <fo:flow flow-name="xsl-region-body" xsl:use-attribute-sets="index">
1002          <xsl:call-template name="insertIndex" />   
1003        </fo:flow>
1004      </fo:page-sequence>
1005    </xsl:if>
1006
1007    <xsl:if test="$xml2rfc-ext-authors-section='end' or ($xml2rfc-private='' and not($no-copylong))">
1008      <fo:page-sequence master-reference="sequence" language="{$lang}">
1009        <xsl:if test="$xml2rfc-ext-duplex='yes'">
1010          <xsl:attribute name="force-page-count">even</xsl:attribute>
1011        </xsl:if>
1012 
1013        <xsl:call-template name="insertHeader" />
1014        <xsl:call-template name="insertFooter" />
1015       
1016        <fo:flow flow-name="xsl-region-body">
1017         
1018          <xsl:if test="$xml2rfc-ext-authors-section='end'">
1019            <xsl:call-template name="insertAuthors" />
1020          </xsl:if>
1021 
1022          <xsl:if test="$xml2rfc-private=''">
1023            <!-- copyright statements -->
1024            <xsl:variable name="copyright">
1025              <xsl:call-template name="insertCopyright" />
1026            </xsl:variable>
1027         
1028            <!-- emit it -->
1029            <xsl:choose>
1030              <xsl:when test="function-available('exslt:node-set')">
1031                <xsl:apply-templates select="exslt:node-set($copyright)/node()" />
1032              </xsl:when>
1033              <xsl:otherwise> <!--proceed with fingers crossed-->
1034                <xsl:variable name="temp" select="$copyright"/>
1035                <xsl:apply-templates select="$temp/node()" />
1036              </xsl:otherwise>
1037            </xsl:choose>
1038          </xsl:if>
1039         
1040        </fo:flow>
1041      </fo:page-sequence>
1042    </xsl:if>
1043   
1044  </fo:root>
1045</xsl:template>
1046
1047
1048<xsl:template name="section-maker">
1049  <xsl:variable name="sectionNumber">
1050    <xsl:choose>
1051      <xsl:when test="@myns:unnumbered"></xsl:when>
1052      <xsl:when test="ancestor::x:boilerplate"></xsl:when>
1053      <xsl:otherwise><xsl:call-template name="get-section-number" /></xsl:otherwise>
1054    </xsl:choose>
1055  </xsl:variable>
1056
1057  <xsl:if test="$sectionNumber!=''">
1058    <xsl:attribute name="id"><xsl:value-of select="concat($anchor-prefix,'.section.',$sectionNumber)"/>
1059  </xsl:attribute></xsl:if>
1060 
1061  <xsl:call-template name="add-anchor" />
1062 
1063  <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
1064    <xsl:call-template name="emit-section-number">
1065      <xsl:with-param name="no" select="$sectionNumber"/>
1066    </xsl:call-template>
1067    <xsl:text>&#0160;&#0160;</xsl:text>
1068  </xsl:if>
1069  <xsl:value-of select="@title" />
1070
1071</xsl:template>
1072
1073<xsl:template match="section[count(ancestor::section) = 0 and (@myns:notoclink or ancestor::x:boilerplate)]">
1074
1075  <fo:block xsl:use-attribute-sets="h1">
1076    <xsl:call-template name="section-maker" />
1077  </fo:block>
1078
1079  <xsl:apply-templates select="iref" mode="iref-start"/>
1080  <xsl:apply-templates />
1081  <xsl:apply-templates select="iref" mode="iref-end"/>
1082</xsl:template>
1083
1084<xsl:template match="section[count(ancestor::section) = 0 and not(@myns:notoclink or ancestor::x:boilerplate)]">
1085
1086  <fo:block xsl:use-attribute-sets="h1 newpage">
1087    <xsl:call-template name="section-maker" />
1088  </fo:block>
1089
1090  <xsl:apply-templates select="iref" mode="iref-start"/>
1091  <xsl:apply-templates />
1092  <xsl:apply-templates select="iref" mode="iref-end"/>
1093</xsl:template>
1094
1095<xsl:template match="section[count(ancestor::section) = 1]">
1096  <fo:block xsl:use-attribute-sets="h2">
1097    <xsl:call-template name="section-maker" />
1098  </fo:block>
1099
1100  <xsl:apply-templates select="iref" mode="iref-start"/>
1101  <xsl:apply-templates />
1102  <xsl:apply-templates select="iref" mode="iref-end"/>
1103</xsl:template>
1104
1105<xsl:template match="section[count(ancestor::section) &gt; 1]">
1106  <fo:block xsl:use-attribute-sets="h3">
1107    <xsl:call-template name="section-maker" />
1108  </fo:block>
1109
1110  <xsl:apply-templates select="iref" mode="iref-start"/>
1111  <xsl:apply-templates />
1112  <xsl:apply-templates select="iref" mode="iref-end"/>
1113</xsl:template>
1114
1115<xsl:template match="spanx[@style='emph' or not(@style)]">
1116  <fo:wrapper font-style="italic">
1117    <xsl:call-template name="copy-anchor"/>
1118    <xsl:apply-templates />
1119  </fo:wrapper>
1120</xsl:template>
1121
1122<xsl:template match="spanx[@style='strong']">
1123  <fo:wrapper font-weight="bold">
1124    <xsl:call-template name="copy-anchor"/>
1125    <xsl:apply-templates />
1126  </fo:wrapper>
1127</xsl:template>
1128
1129<xsl:template match="spanx[@style='verb']">
1130  <fo:wrapper font-family="monospace">
1131    <xsl:call-template name="copy-anchor"/>
1132    <xsl:apply-templates/>
1133  </fo:wrapper>
1134</xsl:template>
1135
1136<xsl:template match="t">
1137  <fo:block space-before=".5em" space-after=".5em">
1138    <xsl:call-template name="insert-justification"/>
1139    <xsl:choose>
1140      <xsl:when test="parent::x:blockquote">
1141        <xsl:attribute name="start-indent">4em</xsl:attribute>
1142      </xsl:when>
1143      <xsl:when test="parent::x:note">
1144        <xsl:attribute name="start-indent">4em</xsl:attribute>
1145      </xsl:when>
1146      <xsl:otherwise>
1147        <xsl:attribute name="start-indent">2em</xsl:attribute>
1148      </xsl:otherwise>
1149    </xsl:choose>
1150    <xsl:call-template name="copy-anchor"/>
1151    <xsl:apply-templates />
1152  </fo:block>
1153</xsl:template>
1154               
1155<xsl:template match="vspace">
1156  <fo:block/>
1157</xsl:template>
1158
1159<xsl:template name="render-section-ref">
1160  <xsl:param name="from" />
1161  <xsl:param name="to" />
1162  <xsl:variable name="target" select="$from/@target" />
1163
1164  <xsl:variable name="refname">
1165    <xsl:for-each select="$to">
1166      <xsl:call-template name="get-section-type">
1167        <xsl:with-param name="prec" select="$from/preceding-sibling::node()[1]" />
1168      </xsl:call-template>
1169    </xsl:for-each>
1170  </xsl:variable>
1171  <xsl:variable name="refnum">
1172    <xsl:for-each select="$to">
1173      <xsl:call-template name="get-section-number" />
1174    </xsl:for-each>
1175  </xsl:variable>
1176  <xsl:choose>
1177    <xsl:when test="@format='counter'">
1178      <xsl:value-of select="$refnum"/>
1179    </xsl:when>
1180    <xsl:when test="@format='title'">
1181      <xsl:value-of select="$to/@title"/>
1182    </xsl:when>
1183    <xsl:otherwise>
1184      <xsl:value-of select="normalize-space(concat($refname,'&#160;',$refnum))"/>
1185    </xsl:otherwise>
1186  </xsl:choose>
1187</xsl:template>
1188
1189<xsl:template match="xref[node()]">
1190  <xsl:variable name="target" select="@target" />
1191  <xsl:variable name="node" select="//*[@anchor=$target]" />
1192  <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>
1193  <xsl:choose>
1194    <xsl:when test="@x:fmt='none'">
1195      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1196        <xsl:if test="$node/self::reference and $xml2rfc-ext-include-references-in-index='yes'">
1197          <xsl:attribute name="id">
1198            <xsl:value-of select="$anchor"/>
1199          </xsl:attribute>
1200          <xsl:attribute name="index-key">
1201            <xsl:value-of select="concat('xrefitem=',@target)"/>
1202          </xsl:attribute>
1203        </xsl:if>
1204        <!-- insert id when a backlink to this xref is needed in the index -->
1205        <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1206        <xsl:if test="$ireftargets">
1207          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1208        </xsl:if>
1209        <xsl:for-each select="$ireftargets">
1210          <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1211        </xsl:for-each>
1212        <xsl:apply-templates/>
1213      </fo:basic-link>
1214    </xsl:when>
1215   
1216    <xsl:when test="$node/self::section or $node/self::appendix">
1217      <xsl:choose>
1218        <xsl:when test="@format='none'">
1219          <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1220            <!-- insert id when a backlink to this xref is needed in the index -->
1221            <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1222            <xsl:if test="$ireftargets">
1223              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1224            </xsl:if>
1225            <xsl:for-each select="$ireftargets">
1226              <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1227            </xsl:for-each>
1228            <xsl:apply-templates/>
1229          </fo:basic-link>
1230        </xsl:when>
1231        <xsl:otherwise>
1232          <xsl:apply-templates/>
1233          <xsl:text> (</xsl:text>
1234          <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1235            <!-- insert id when a backlink to this xref is needed in the index -->
1236            <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1237            <xsl:if test="$ireftargets">
1238              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1239            </xsl:if>
1240            <xsl:for-each select="$ireftargets">
1241              <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1242            </xsl:for-each>
1243            <xsl:call-template name="render-section-ref">
1244              <xsl:with-param name="from" select="."/>
1245              <xsl:with-param name="to" select="$node"/>
1246            </xsl:call-template>
1247          </fo:basic-link>
1248          <xsl:text>)</xsl:text>
1249        </xsl:otherwise>
1250      </xsl:choose>
1251    </xsl:when>
1252   
1253    <xsl:otherwise>
1254      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1255        <xsl:value-of select="." />
1256      </fo:basic-link>
1257      <xsl:if test="not(@format='none')">
1258        <xsl:for-each select="//reference[@anchor=$target]">
1259          &#160;<xsl:call-template name="referencename"><xsl:with-param name="node" select="." /></xsl:call-template>
1260        </xsl:for-each>
1261      </xsl:if>
1262    </xsl:otherwise>
1263  </xsl:choose>
1264
1265</xsl:template>
1266
1267<xsl:template match="xref[not(node())]">
1268
1269  <xsl:variable name="target" select="@target" />
1270  <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>
1271  <xsl:variable name="node" select="//*[@anchor=$target]" />
1272  <xsl:if test="count($node)=0 and not(ancestor::ed:del)">
1273    <xsl:message>Undefined target: <xsl:value-of select="@target" /></xsl:message>
1274    <span class="error">Undefined target: <xsl:value-of select="@target" /></span>
1275  </xsl:if>
1276
1277  <xsl:choose>
1278
1279    <!-- Section links -->
1280    <xsl:when test="$node/self::section or $node/self::appendix">
1281      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1282        <!-- insert id when a backlink to this xref is needed in the index -->
1283        <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1284        <xsl:if test="$ireftargets">
1285          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1286        </xsl:if>
1287        <xsl:for-each select="$ireftargets">
1288          <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1289        </xsl:for-each>
1290        <xsl:call-template name="render-section-ref">
1291          <xsl:with-param name="from" select="."/>
1292          <xsl:with-param name="to" select="$node"/>
1293        </xsl:call-template>
1294      </fo:basic-link>
1295    </xsl:when>
1296
1297    <!-- Figure links -->
1298    <xsl:when test="$node//self::figure">
1299      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1300        <xsl:variable name="figcnt">
1301          <xsl:for-each select="$node">
1302            <xsl:number level="any" count="figure[(@title!='' or @anchor!='') and not(@suppress-title='true')]" />
1303          </xsl:for-each>
1304        </xsl:variable>
1305        <xsl:choose>
1306          <xsl:when test="@format='counter'">
1307            <xsl:value-of select="$figcnt" />
1308          </xsl:when>
1309          <xsl:when test="@format='title'">
1310            <xsl:value-of select="$node/@title" />
1311          </xsl:when>
1312          <xsl:otherwise>
1313            <xsl:value-of select="normalize-space(concat('Figure&#160;',$figcnt))"/>
1314          </xsl:otherwise>
1315        </xsl:choose>
1316      </fo:basic-link>
1317    </xsl:when>
1318
1319    <!-- Table links -->
1320    <xsl:when test="$node/self::texttable">
1321      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1322        <xsl:variable name="tabcnt">
1323          <xsl:for-each select="$node">
1324            <xsl:number level="any" count="texttable[(@title!='' or @anchor!='') and not(@suppress-title='true')]" />
1325          </xsl:for-each>
1326        </xsl:variable>
1327        <xsl:choose>
1328          <xsl:when test="@format='counter'">
1329            <xsl:value-of select="$tabcnt" />
1330          </xsl:when>
1331          <xsl:when test="@format='title'">
1332            <xsl:value-of select="$node/@title" />
1333          </xsl:when>
1334          <xsl:otherwise>
1335            <xsl:value-of select="normalize-space(concat('Table&#160;',$tabcnt))"/>
1336          </xsl:otherwise>
1337        </xsl:choose>
1338      </fo:basic-link>
1339    </xsl:when>
1340
1341    <!-- Paragraph links -->
1342    <xsl:when test="$node/self::t">
1343      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1344        <xsl:variable name="tcnt">
1345          <xsl:for-each select="$node">
1346            <xsl:call-template name="get-paragraph-number" />
1347          </xsl:for-each>
1348        </xsl:variable>
1349        <xsl:choose>
1350          <xsl:when test="@format='counter'">
1351            <xsl:value-of select="$tcnt" />
1352          </xsl:when>
1353          <xsl:when test="@format='title'">
1354            <xsl:value-of select="$node/@title" />
1355          </xsl:when>
1356          <xsl:otherwise>
1357            <xsl:value-of select="normalize-space(concat('Paragraph&#160;',substring-after($tcnt,'p.')))"/>
1358          </xsl:otherwise>
1359        </xsl:choose>
1360      </fo:basic-link>
1361    </xsl:when>
1362
1363    <!-- Comment links -->
1364    <xsl:when test="$node/self::cref">
1365      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1366        <xsl:variable name="name">
1367          <xsl:for-each select="$node">
1368            <xsl:call-template name="get-comment-name" />
1369          </xsl:for-each>
1370        </xsl:variable>
1371        <xsl:choose>
1372          <xsl:when test="@format='counter'">
1373            <xsl:value-of select="$name" />
1374          </xsl:when>
1375          <xsl:when test="@format='title'">
1376            <xsl:value-of select="$node/@title" />
1377          </xsl:when>
1378          <xsl:otherwise>
1379            <xsl:value-of select="normalize-space(concat('Comment&#160;',$name))"/>
1380          </xsl:otherwise>
1381        </xsl:choose>
1382      </fo:basic-link>
1383    </xsl:when>
1384
1385    <!-- Reference links -->
1386    <xsl:when test="$node/self::reference">
1387      <!--
1388      Formats:
1389     
1390        ()      [XXXX] (Section SS)
1391        ,       [XXXX], Section SS
1392        of      Section SS of [XXXX]
1393        sec     Section SS
1394        number  SS
1395      -->
1396
1397      <xsl:variable name="sec">
1398        <xsl:choose>
1399          <xsl:when test="starts-with(@x:rel,'#') and not(@x:sec) and $node/x:source/@href">
1400            <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
1401            <xsl:for-each select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]">
1402              <xsl:call-template name="get-section-number"/>
1403            </xsl:for-each>
1404          </xsl:when>
1405          <xsl:otherwise>
1406            <xsl:value-of select="@x:sec"/>
1407          </xsl:otherwise>
1408        </xsl:choose>
1409      </xsl:variable>
1410
1411      <xsl:variable name="fmt">
1412        <xsl:choose>
1413          <xsl:when test="@x:fmt!=''"><xsl:value-of select="@x:fmt"/></xsl:when>
1414          <xsl:when test="ancestor::artwork">,</xsl:when>
1415          <xsl:otherwise>of</xsl:otherwise>
1416        </xsl:choose>
1417      </xsl:variable>
1418
1419      <xsl:if test="$sec!=''">
1420        <xsl:choose>
1421          <xsl:when test="$fmt='of' or $fmt='sec'">
1422            <xsl:text>Section </xsl:text>
1423            <xsl:value-of select="$sec"/>
1424            <xsl:if test="$fmt='of'">
1425              <xsl:text> of </xsl:text>
1426            </xsl:if>
1427          </xsl:when>
1428          <xsl:when test="$fmt='number'">
1429            <xsl:value-of select="$sec"/>
1430          </xsl:when>
1431          <xsl:when test="$fmt=','"/>
1432          <xsl:when test="$fmt='()'"/>
1433          <xsl:otherwise>
1434            <xsl:message>UNKNOWN xref x:fmt: <xsl:value-of select="$fmt"/></xsl:message>
1435          </xsl:otherwise>
1436        </xsl:choose>
1437      </xsl:if>
1438     
1439      <!-- anchor for index -->
1440      <xsl:if test="$xml2rfc-ext-include-references-in-index='yes' and $sec!='' and ($fmt='sec' or $fmt='number')">
1441        <fo:wrapper>
1442          <xsl:attribute name="id">
1443            <xsl:value-of select="$anchor"/>
1444          </xsl:attribute>
1445          <xsl:attribute name="index-key">
1446            <xsl:value-of select="concat('xrefitem=',@target)"/>
1447          </xsl:attribute>
1448          <xsl:if test="$sec!=''">
1449            <fo:wrapper>
1450              <xsl:attribute name="index-key">
1451                <xsl:value-of select="concat('xrefitem=',@target,'#',$sec)"/>
1452              </xsl:attribute>
1453            </fo:wrapper>
1454          </xsl:if>
1455        </fo:wrapper>
1456      </xsl:if>
1457
1458      <xsl:if test="$sec='' or ($fmt!='sec' and $fmt!='number')">
1459        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1460          <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1461            <xsl:attribute name="id">
1462              <xsl:value-of select="$anchor"/>
1463            </xsl:attribute>
1464            <xsl:attribute name="index-key">
1465              <xsl:value-of select="concat('xrefitem=',@target)"/>
1466            </xsl:attribute>
1467            <xsl:if test="$sec!=''">
1468              <fo:wrapper>
1469                <xsl:attribute name="index-key">
1470                  <xsl:value-of select="concat('xrefitem=',@target,'#',$sec)"/>
1471                </xsl:attribute>
1472              </fo:wrapper>
1473            </xsl:if>
1474          </xsl:if>
1475          <xsl:variable name="val">
1476            <xsl:call-template name="referencename">
1477              <xsl:with-param name="node" select="$node" />
1478            </xsl:call-template>
1479          </xsl:variable>
1480          <xsl:choose>
1481            <xsl:when test="$fmt='anchor'">
1482              <!-- remove brackets -->
1483              <xsl:value-of select="substring($val,2,string-length($val)-2)"/>
1484            </xsl:when>
1485            <xsl:otherwise>
1486              <xsl:value-of select="$val"/>
1487            </xsl:otherwise>
1488          </xsl:choose>
1489        </fo:basic-link>
1490      </xsl:if>
1491
1492      <xsl:if test="$sec!=''">
1493        <xsl:choose>
1494          <xsl:when test="$fmt='()'">
1495            <xsl:text> (Section </xsl:text>
1496            <xsl:value-of select="$sec"/>
1497            <xsl:text>)</xsl:text>
1498          </xsl:when>
1499          <xsl:when test="$fmt=','">
1500            <xsl:text>, Section </xsl:text>
1501            <xsl:value-of select="$sec"/>
1502          </xsl:when>
1503          <xsl:otherwise/>
1504        </xsl:choose>
1505      </xsl:if>
1506
1507    </xsl:when>
1508   
1509    <xsl:otherwise>
1510      <xsl:call-template name="error">
1511        <xsl:with-param name="msg" select="concat('xref to unknown element: ',name($node))"/>
1512      </xsl:call-template>
1513    </xsl:otherwise>
1514  </xsl:choose>
1515</xsl:template>
1516
1517<xsl:template match="/">
1518  <xsl:apply-templates />
1519</xsl:template>
1520
1521<xsl:template match="*">
1522  <xsl:message terminate="yes">ERROR: unknown or unexpected element: {<xsl:value-of select="namespace-uri()" />}<xsl:value-of select="local-name()" /><xsl:call-template name="lineno"/>: '<xsl:value-of select="."/>'</xsl:message>
1523</xsl:template>
1524
1525<xsl:template name="emitheader">
1526  <xsl:param name="lc" />
1527  <xsl:param name="rc" />
1528
1529  <xsl:for-each select="$lc/myns:item | $rc/myns:item">
1530    <xsl:variable name="pos" select="position()" />
1531    <xsl:if test="$pos &lt; count($lc/myns:item) + 1 or $pos &lt; count($rc/myns:item) + 1">
1532      <fo:table-row>
1533        <fo:table-cell>
1534          <fo:block>
1535            <xsl:apply-templates select="$lc/myns:item[$pos]/node()" mode="simple-html" />
1536          </fo:block>
1537        </fo:table-cell>
1538        <fo:table-cell>
1539          <fo:block text-align="right">
1540            <xsl:apply-templates select="$rc/myns:item[$pos]/node()" mode="simple-html" />
1541          </fo:block>
1542        </fo:table-cell>
1543      </fo:table-row>
1544    </xsl:if>
1545  </xsl:for-each>
1546</xsl:template>
1547
1548
1549<xsl:template match="text()" mode="simple-html">
1550  <xsl:apply-templates select="." />
1551</xsl:template>
1552
1553<xsl:template match="a" mode="simple-html">
1554  <fo:basic-link external-destination="url('{@href}')" xsl:use-attribute-sets="external-link">
1555    <xsl:apply-templates />
1556  </fo:basic-link>
1557</xsl:template>
1558
1559
1560<!-- produce back section with author information -->
1561<xsl:template name="insertAuthors">
1562
1563  <xsl:variable name="sectionNumber">
1564    <xsl:call-template name="get-authors-section-number"/>
1565  </xsl:variable>
1566
1567  <xsl:if test="$sectionNumber!='suppress'">
1568    <fo:block id="{$anchor-prefix}.authors" xsl:use-attribute-sets="h1 newpage">
1569      <xsl:if test="$sectionNumber != ''">
1570        <xsl:call-template name="emit-section-number">
1571          <xsl:with-param name="no" select="$sectionNumber"/>
1572        </xsl:call-template>
1573        <xsl:text>&#0160;&#0160;</xsl:text>
1574      </xsl:if>
1575      <xsl:call-template name="get-authors-section-title"/>
1576    </fo:block>
1577   
1578    <xsl:apply-templates select="/rfc/front/author" />
1579  </xsl:if>
1580</xsl:template>
1581
1582
1583<!-- generate the index section -->
1584
1585<xsl:template name="insertIndex">
1586
1587  <fo:block xsl:use-attribute-sets="h1 newpage" id="{$anchor-prefix}.index">
1588    <xsl:text>Index</xsl:text>
1589  </fo:block>
1590
1591  <xsl:variable name="irefs" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
1592  <xsl:variable name="xrefs" select="//reference[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@anchor,1,1),$lcase,$ucase)))]"/>
1593
1594  <xsl:for-each select="$irefs | $xrefs">
1595    <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)" />
1596    <xsl:variable name="letter" select="translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase)"/>
1597           
1598    <xsl:variable name="showit">
1599      <xsl:choose>
1600        <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
1601          <xsl:if test="$irefs[starts-with(translate(@item,$lcase,$ucase),$letter)]">
1602            <xsl:text>yes</xsl:text>
1603          </xsl:if>
1604        </xsl:when>
1605        <xsl:otherwise>
1606          <xsl:text>yes</xsl:text>
1607        </xsl:otherwise>
1608      </xsl:choose>
1609    </xsl:variable>
1610
1611    <xsl:if test="$showit='yes'">
1612      <fo:block space-before="1em" font-weight="bold">
1613        <xsl:value-of select="$letter" />
1614      </fo:block>
1615           
1616      <xsl:for-each select="key('index-first-letter',translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase))">
1617 
1618      <xsl:sort select="translate(concat(@item,@anchor),$lcase,$ucase)" />
1619     
1620        <xsl:choose>
1621          <xsl:when test="self::reference">
1622            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1623           
1624              <xsl:variable name="entries" select="//xref[@target=current()/@anchor and not(ancestor::ed:del)]" />
1625             
1626              <xsl:if test="$entries">
1627                <fo:block start-indent="1em" hyphenate="true">
1628                  <fo:wrapper font-style="italic"><xsl:value-of select="concat(@anchor,' ')" /></fo:wrapper>
1629 
1630                  <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1631                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@anchor,',primary')}" font-weight="bold"/>
1632                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@anchor)}"/>
1633                  </fo:index-page-citation-list>
1634
1635                  <xsl:variable name="rs2" select="$entries[@x:sec]"/>
1636
1637                  <xsl:if test="$rs2">
1638                    <xsl:for-each select="$rs2">
1639                      <xsl:sort select="substring-before(concat(@x:sec,'.'),'.')" data-type="number"/>
1640                      <xsl:sort select="substring(@x:sec,2+string-length(substring-before(@x:sec,'.')))" data-type="number"/>
1641                      <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-sec',concat(@target,'..',@x:sec)))">
1642                        <fo:block start-indent="2em" hyphenate="true">
1643                          <fo:wrapper font-style="italic">
1644                            <xsl:choose>
1645                              <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
1646                                <xsl:text>Appendix </xsl:text>
1647                              </xsl:when>
1648                              <xsl:otherwise>
1649                                <xsl:text>Section </xsl:text>
1650                              </xsl:otherwise>
1651                            </xsl:choose>
1652                            <xsl:value-of select="@x:sec"/>
1653                            <xsl:text> </xsl:text>
1654                          </fo:wrapper>
1655                          <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1656                            <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@target,'#',@x:sec)}"/>
1657                          </fo:index-page-citation-list>
1658                        </fo:block>
1659                      </xsl:if>
1660                    </xsl:for-each>
1661                  </xsl:if>
1662
1663                  <xsl:if test="current()/x:source/@href">
1664                    <xsl:variable name="rs3" select="$entries[not(@x:sec) and @x:rel]"/>
1665                    <xsl:if test="$rs3">
1666                      <xsl:variable name="doc" select="document(current()/x:source/@href)"/>
1667                      <xsl:for-each select="$rs3">
1668                        <xsl:sort select="count($doc//*[@anchor and following::*/@anchor=substring-after(current()/@x:rel,'#')])" order="ascending" data-type="number"/>
1669                        <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-anchor',concat(@target,'..',@x:rel)))">
1670                          <fo:block start-indent="2em" hyphenate="true">
1671                            <xsl:variable name="sec">
1672                              <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
1673                                <xsl:call-template name="get-section-number"/>
1674                              </xsl:for-each>
1675                            </xsl:variable>
1676                            <fo:wrapper font-style="italic">
1677                              <xsl:choose>
1678                                <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
1679                                  <xsl:text>Appendix </xsl:text>
1680                                </xsl:when>
1681                                <xsl:otherwise>
1682                                  <xsl:text>Section </xsl:text>
1683                                </xsl:otherwise>
1684                              </xsl:choose>
1685                              <xsl:value-of select="$sec"/>
1686                              <xsl:text> </xsl:text>
1687                            </fo:wrapper>
1688                            <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1689                              <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@target,'#',$sec)}"/>
1690                            </fo:index-page-citation-list>
1691                          </fo:block>
1692                        </xsl:if>
1693                      </xsl:for-each>
1694                    </xsl:if>
1695                  </xsl:if>
1696
1697                </fo:block>
1698              </xsl:if>
1699
1700            </xsl:if>
1701          </xsl:when>
1702          <xsl:otherwise>
1703            <xsl:if test="generate-id(.) = generate-id(key('index-item',@item))">
1704           
1705              <xsl:variable name="item" select="@item"/>
1706              <xsl:variable name="in-artwork" select="count(//iref[@item=$item and @primary='true' and ancestor::artwork])!=0"/>
1707       
1708              <fo:block start-indent="1em" hyphenate="true">
1709                <xsl:choose>
1710                  <xsl:when test="$in-artwork">
1711                    <fo:wrapper font-family="monospace"><xsl:value-of select="concat(@item,' ')" /></fo:wrapper>
1712                  </xsl:when>
1713                  <xsl:otherwise>
1714                    <xsl:value-of select="concat(@item,' ')" />
1715                  </xsl:otherwise>
1716                </xsl:choose>
1717               
1718                <xsl:variable name="entries" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
1719                                       
1720                <xsl:if test="$entries">
1721                  <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1722                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem,',primary')}" font-weight="bold"/>
1723                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem)}"/>
1724                  </fo:index-page-citation-list>
1725                </xsl:if>
1726     
1727              </fo:block>
1728                   
1729              <xsl:for-each select="key('index-item',@item)[@subitem and @subitem!='']">
1730              <xsl:sort select="translate(@subitem,$lcase,$ucase)" />
1731           
1732                <xsl:if test="generate-id(.) = generate-id(key('index-item-subitem',concat(@item,'..',@subitem)))">
1733               
1734                  <xsl:variable name="itemsubitem" select="concat(@item,'..',@subitem)"/>
1735                  <xsl:variable name="in-artwork2" select="count(//iref[concat(@item,'..',@subitem)=$itemsubitem and @primary='true' and ancestor::artwork])!=0"/>
1736                             
1737                  <fo:block start-indent="2em" hyphenate="true">
1738                 
1739                    <xsl:choose>
1740                      <xsl:when test="$in-artwork2">
1741                        <fo:wrapper font-family="monospace"><xsl:value-of select="concat(@subitem,' ')" /></fo:wrapper>
1742                      </xsl:when>
1743                      <xsl:otherwise>
1744                        <xsl:value-of select="concat(@subitem,' ')" />
1745                      </xsl:otherwise>
1746                    </xsl:choose>
1747     
1748                    <xsl:variable name="entries2" select="key('index-item-subitem',concat(@item,'..',@subitem))" />
1749                   
1750                    <xsl:if test="$entries2">
1751                      <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1752                        <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem,',primary')}" font-weight="bold"/>
1753                        <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1754                      </fo:index-page-citation-list>
1755                    </xsl:if>
1756     
1757                  </fo:block>
1758                </xsl:if>
1759              </xsl:for-each>
1760                     
1761            </xsl:if>
1762          </xsl:otherwise>
1763        </xsl:choose>
1764   
1765                 
1766      </xsl:for-each>           
1767    </xsl:if>
1768  </xsl:for-each>
1769</xsl:template>
1770
1771
1772
1773<xsl:template match="/" mode="toc">
1774  <fo:block xsl:use-attribute-sets="h1 newpage" id="{concat($anchor-prefix,'.toc')}">
1775    <xsl:text>Table of Contents</xsl:text>
1776  </fo:block>
1777
1778  <xsl:apply-templates mode="toc" />
1779</xsl:template>
1780
1781<xsl:template name="back-toc">
1782
1783  <xsl:apply-templates select="references" mode="toc" />
1784
1785  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
1786    <xsl:apply-templates select="/rfc/front" mode="toc" />
1787  </xsl:if>
1788
1789  <xsl:apply-templates select="back/*[not(self::references)]" mode="toc" />
1790
1791  <!-- insert the index if index entries exist -->
1792  <xsl:if test="$has-index">
1793    <xsl:call-template name="insert-toc-line">
1794      <xsl:with-param name="target" select="concat($anchor-prefix,'.index')"/>
1795      <xsl:with-param name="title" select="'Index'"/>
1796    </xsl:call-template>
1797  </xsl:if>
1798
1799  <xsl:if test="$xml2rfc-ext-authors-section='end'">
1800    <xsl:apply-templates select="/rfc/front" mode="toc" />
1801  </xsl:if>
1802
1803  <!-- copyright statements -->
1804  <xsl:if test="$xml2rfc-private='' and not($no-copylong)">
1805    <xsl:call-template name="insert-toc-line">
1806      <xsl:with-param name="target" select="concat($anchor-prefix,'.ipr')"/>
1807      <xsl:with-param name="title" select="'Intellectual Property and Copyright Statements'"/>
1808    </xsl:call-template>
1809  </xsl:if>
1810 
1811</xsl:template>
1812
1813<xsl:template match="front" mode="toc">
1814 
1815  <xsl:variable name="authors-title">
1816    <xsl:call-template name="get-authors-section-title"/>
1817  </xsl:variable>
1818  <xsl:variable name="authors-number">
1819    <xsl:call-template name="get-authors-section-number"/>
1820  </xsl:variable>
1821  <xsl:if test="$authors-number!='suppress'">
1822    <xsl:call-template name="insert-toc-line">
1823      <xsl:with-param name="target" select="concat($anchor-prefix,'.authors')"/>
1824      <xsl:with-param name="title" select="$authors-title"/>
1825      <xsl:with-param name="number" select="$authors-number"/>
1826    </xsl:call-template>
1827  </xsl:if>
1828
1829</xsl:template>
1830
1831<xsl:template name="references-toc">
1832
1833  <!-- distinguish two cases: (a) single references element (process
1834  as toplevel section; (b) multiple references sections (add one toplevel
1835  container with subsection) -->
1836
1837  <xsl:choose>
1838    <xsl:when test="count(/*/back/references) = 0">
1839      <!-- nop -->
1840    </xsl:when>
1841    <xsl:when test="count(/*/back/references) = 1">
1842      <xsl:for-each select="/*/back/references">
1843        <xsl:variable name="title">
1844          <xsl:choose>
1845            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
1846            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
1847          </xsl:choose>
1848        </xsl:variable>
1849     
1850        <xsl:call-template name="insert-toc-line">
1851          <xsl:with-param name="number">
1852            <xsl:call-template name="get-references-section-number"/>
1853          </xsl:with-param>
1854          <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
1855          <xsl:with-param name="title" select="$title"/>
1856        </xsl:call-template>
1857      </xsl:for-each>
1858    </xsl:when>
1859    <xsl:otherwise>
1860      <!-- insert pseudo container -->   
1861      <xsl:call-template name="insert-toc-line">
1862        <xsl:with-param name="number">
1863          <xsl:call-template name="get-references-section-number"/>
1864        </xsl:with-param>
1865        <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
1866        <xsl:with-param name="title" select="$xml2rfc-refparent"/>
1867      </xsl:call-template>
1868 
1869      <!-- ...with subsections... -->   
1870      <xsl:for-each select="/*/back/references">
1871        <xsl:variable name="title">
1872          <xsl:choose>
1873            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
1874            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
1875          </xsl:choose>
1876        </xsl:variable>
1877     
1878        <xsl:variable name="sectionNumber">
1879          <xsl:call-template name="get-section-number" />
1880        </xsl:variable>
1881
1882        <xsl:variable name="num">
1883          <xsl:number/>
1884        </xsl:variable>
1885
1886        <xsl:call-template name="insert-toc-line">
1887          <xsl:with-param name="number" select="$sectionNumber"/>
1888          <xsl:with-param name="target" select="concat($anchor-prefix,'.references','.',$num)"/>
1889          <xsl:with-param name="title" select="$title"/>
1890        </xsl:call-template>
1891      </xsl:for-each>
1892    </xsl:otherwise>
1893  </xsl:choose>
1894</xsl:template>
1895
1896<xsl:template match="section" mode="toc">
1897  <xsl:variable name="sectionNumber">
1898    <xsl:call-template name="get-section-number" />
1899  </xsl:variable>
1900
1901  <xsl:variable name="target">
1902    <xsl:choose>
1903      <xsl:when test="@anchor"><xsl:value-of select="@anchor" /></xsl:when>
1904       <xsl:otherwise><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber" /></xsl:otherwise>
1905    </xsl:choose>
1906  </xsl:variable>
1907
1908  <xsl:call-template name="insert-toc-line">
1909    <xsl:with-param name="number" select="$sectionNumber"/>
1910    <xsl:with-param name="target" select="$target"/>
1911    <xsl:with-param name="title" select="@title"/>
1912    <xsl:with-param name="tocparam" select="@toc"/>
1913  </xsl:call-template>
1914 
1915  <xsl:if test=".//section">
1916    <xsl:apply-templates mode="toc" />
1917  </xsl:if>
1918</xsl:template>
1919
1920<xsl:template name="insert-toc-line">
1921  <xsl:param name="number" />
1922  <xsl:param name="target" />
1923  <xsl:param name="title" />
1924  <xsl:param name="tocparam" />
1925 
1926  <xsl:variable name="depth" select="string-length(translate($number,'.ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890&#167;','.'))" />
1927 
1928  <!-- handle tocdepth parameter -->
1929  <xsl:choose>
1930    <xsl:when test="($tocparam='' or $tocparam='default') and string-length(translate($number,'.ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890&#167;','.')) &gt;= $parsedTocDepth">
1931      <!-- dropped entry because of depth-->
1932    </xsl:when>
1933    <xsl:when test="$tocparam='exclude'">
1934      <!-- dropped entry because excluded -->
1935    </xsl:when>
1936    <xsl:when test="$depth = 0">
1937      <fo:block space-before="1em" font-weight="bold" text-align-last="justify">
1938        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
1939          <xsl:value-of select="$number" />
1940          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
1941          <xsl:text>&#0160;&#0160;</xsl:text>
1942        </xsl:if>
1943        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link"><xsl:value-of select="$title"/></fo:basic-link>
1944        <fo:leader leader-pattern="dots"/>
1945        <fo:page-number-citation ref-id="{$target}"/>
1946      </fo:block>
1947    </xsl:when>
1948    <xsl:when test="$depth = 1">
1949      <fo:block space-before="0.5em" text-align-last="justify">
1950        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
1951          <xsl:value-of select="$number" />
1952          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
1953          <xsl:text>&#0160;&#0160;&#0160;&#0160;</xsl:text>
1954        </xsl:if>
1955        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link"><xsl:value-of select="$title"/></fo:basic-link>
1956        <fo:leader leader-pattern="dots"/>
1957        <fo:page-number-citation ref-id="{$target}"/>
1958      </fo:block>
1959    </xsl:when>
1960    <xsl:otherwise>
1961      <fo:block text-align-last="justify">
1962        <xsl:text>&#0160;&#0160;</xsl:text>
1963        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
1964          <xsl:value-of select="$number" />
1965          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
1966          <xsl:text>&#0160;&#0160;&#0160;&#0160;</xsl:text>
1967        </xsl:if>
1968        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link"><xsl:value-of select="$title"/></fo:basic-link>
1969        <fo:leader leader-pattern="dots"/>
1970        <fo:page-number-citation ref-id="{$target}"/>
1971      </fo:block>
1972    </xsl:otherwise>
1973  </xsl:choose>
1974
1975</xsl:template>
1976
1977
1978<!--
1979<xsl:template name="rfclist">
1980  <xsl:param name="list" />
1981  <xsl:choose>
1982      <xsl:when test="contains($list,',')">
1983          <xsl:variable name="rfcNo" select="substring-before($list,',')" />
1984          <a href="{concat($rfcUrlPrefix,$rfcNo,'.txt')}"><xsl:value-of select="$rfcNo" /></a>,
1985          <xsl:call-template name="rfclist">
1986              <xsl:with-param name="list" select="normalize-space(substring-after($list,','))" />
1987            </xsl:call-template>
1988        </xsl:when>
1989        <xsl:otherwise>
1990          <xsl:variable name="rfcNo" select="$list" />
1991          <a href="{concat($rfcUrlPrefix,$rfcNo,'.txt')}"><xsl:value-of select="$rfcNo" /></a>
1992         </xsl:otherwise>
1993    </xsl:choose>
1994</xsl:template>
1995-->
1996
1997<xsl:template name="insertHeader">
1998  <xsl:variable name="left">
1999    <xsl:call-template name="get-header-left" />
2000  </xsl:variable>
2001  <xsl:variable name="center">
2002    <xsl:call-template name="get-header-center" />
2003  </xsl:variable>
2004  <xsl:variable name="right">
2005    <xsl:call-template name="get-header-right" />
2006  </xsl:variable>
2007
2008  <fo:static-content flow-name="header-right">
2009    <fo:block space-after=".5cm" />
2010    <fo:table width="100%" text-align="center" table-layout="fixed">
2011      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2012      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2013      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2014      <fo:table-body>
2015        <fo:table-row>
2016          <fo:table-cell>
2017            <fo:block text-align="start">
2018              <xsl:value-of select="$left" />
2019             </fo:block>
2020          </fo:table-cell>
2021          <fo:table-cell text-align="center">
2022            <fo:block>
2023              <xsl:value-of select="$center" />
2024             </fo:block>
2025          </fo:table-cell>
2026          <fo:table-cell text-align="end">
2027            <fo:block>
2028              <xsl:value-of select="$right" />
2029             </fo:block>
2030          </fo:table-cell>
2031        </fo:table-row>
2032      </fo:table-body>
2033    </fo:table>
2034  </fo:static-content>
2035
2036  <fo:static-content flow-name="header-left">
2037    <fo:block space-after=".5cm" />
2038    <fo:table width="100%" text-align="center" table-layout="fixed">
2039      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2040      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2041      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2042      <fo:table-body>
2043        <fo:table-row>
2044          <fo:table-cell text-align="start">
2045            <fo:block>
2046              <xsl:value-of select="$right" />
2047             </fo:block>
2048          </fo:table-cell>
2049          <fo:table-cell text-align="center">
2050            <fo:block>
2051              <xsl:value-of select="$center" />
2052             </fo:block>
2053          </fo:table-cell>
2054          <fo:table-cell>
2055            <fo:block text-align="end">
2056              <xsl:value-of select="$left" />
2057             </fo:block>
2058          </fo:table-cell>
2059        </fo:table-row>
2060      </fo:table-body>
2061    </fo:table>
2062  </fo:static-content>
2063
2064</xsl:template>
2065
2066<xsl:template name="insertFooter">
2067  <xsl:variable name="left">
2068    <xsl:call-template name="get-author-summary" />
2069  </xsl:variable>
2070  <xsl:variable name="center">
2071    <xsl:call-template name="get-category-long" />
2072  </xsl:variable>
2073  <xsl:variable name="right">[Page 999]</xsl:variable>
2074
2075  <fo:static-content flow-name="footer-right">
2076    <fo:table text-align="center" width="100%" table-layout="fixed">
2077      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2078      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2079      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2080      <fo:table-body>
2081        <fo:table-row>
2082          <fo:table-cell>
2083            <fo:block text-align="start">
2084              <xsl:value-of select="$left" />
2085             </fo:block>
2086          </fo:table-cell>
2087          <fo:table-cell>
2088            <fo:block text-align="center">
2089              <xsl:value-of select="$center" />
2090             </fo:block>
2091          </fo:table-cell>
2092          <fo:table-cell>
2093            <fo:block text-align="end">[Page <fo:page-number />]</fo:block>
2094          </fo:table-cell>
2095        </fo:table-row>
2096      </fo:table-body>
2097    </fo:table>
2098  </fo:static-content>
2099
2100  <fo:static-content flow-name="footer-left">
2101    <fo:table text-align="center" width="100%" table-layout="fixed">
2102      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2103      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2104      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2105      <fo:table-body>
2106        <fo:table-row>
2107          <fo:table-cell>
2108            <fo:block text-align="start">[Page <fo:page-number />]</fo:block>
2109          </fo:table-cell>
2110          <fo:table-cell>
2111            <fo:block text-align="center">
2112              <xsl:value-of select="$center" />
2113             </fo:block>
2114          </fo:table-cell>
2115          <fo:table-cell>
2116            <fo:block text-align="end">
2117              <xsl:value-of select="$left" />
2118             </fo:block>
2119          </fo:table-cell>
2120        </fo:table-row>
2121      </fo:table-body>
2122    </fo:table>
2123  </fo:static-content>
2124
2125</xsl:template>
2126
2127<!-- change tracking -->
2128
2129<xsl:template match="ed:annotation" />
2130<xsl:template match="ed:del" />
2131<xsl:template match="ed:issue" />
2132<xsl:template match="ed:ins">
2133  <xsl:apply-templates />
2134</xsl:template>
2135<xsl:template match="ed:issueref">
2136  <xsl:apply-templates />
2137</xsl:template>
2138
2139<xsl:template match="ed:replace">
2140  <!--<xsl:variable name="no">change<xsl:number level="any"/></xsl:variable>
2141  <fo:change-bar-begin change-bar-class="{$no}" change-bar-style="solid" change-bar-color="red" change-bar-offset="2mm"/>-->
2142  <xsl:apply-templates />
2143  <!--<fo:change-bar-end change-bar-class="{$no}"/>-->
2144</xsl:template>
2145
2146<!-- extensions -->
2147
2148<xsl:template match="ed:link" />
2149
2150
2151<xsl:template match="node()" mode="bookmarks">
2152  <xsl:apply-templates mode="bookmarks"/>
2153</xsl:template>
2154
2155<xsl:template match="abstract" mode="bookmarks">
2156  <fo:bookmark internal-destination="{concat($anchor-prefix,'.abstract')}">
2157    <fo:bookmark-title>Abstract</fo:bookmark-title>
2158    <xsl:apply-templates mode="bookmarks"/>
2159  </fo:bookmark>
2160</xsl:template>
2161
2162<xsl:template match="note" mode="bookmarks">
2163  <xsl:variable name="num">
2164    <xsl:number count="note" />
2165  </xsl:variable>
2166  <fo:bookmark internal-destination="{concat($anchor-prefix,'.note.',$num)}">
2167    <fo:bookmark-title><xsl:value-of select="@title"/></fo:bookmark-title>
2168    <xsl:apply-templates mode="bookmarks"/>
2169  </fo:bookmark>
2170</xsl:template>
2171
2172<xsl:template match="section[not(@myns:unnumbered)]" mode="bookmarks">
2173  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number" /></xsl:variable>
2174  <fo:bookmark internal-destination="{$anchor-prefix}.section.{$sectionNumber}">
2175    <fo:bookmark-title>
2176      <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
2177        <xsl:value-of select="$sectionNumber"/>
2178        <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2179        <xsl:text> </xsl:text>
2180      </xsl:if>
2181      <xsl:value-of select="@title"/>
2182    </fo:bookmark-title>
2183    <xsl:apply-templates mode="bookmarks"/>
2184  </fo:bookmark>
2185</xsl:template>
2186
2187<xsl:template match="section[@myns:unnumbered]" mode="bookmarks">
2188  <fo:bookmark internal-destination="{@anchor}">
2189    <fo:bookmark-title><xsl:value-of select="@title"/></fo:bookmark-title>
2190    <xsl:apply-templates mode="bookmarks"/>
2191  </fo:bookmark>
2192</xsl:template>
2193
2194<xsl:template match="back" mode="bookmarks">
2195
2196  <xsl:call-template name="references-bookmarks" />
2197
2198  <xsl:if test="$xml2rfc-ext-authors-section!='end'">
2199    <xsl:apply-templates select="/rfc/front" mode="bookmarks" />
2200  </xsl:if>
2201 
2202  <xsl:apply-templates select="*[not(self::references)]" mode="bookmarks" />
2203
2204  <!-- insert the index if index entries exist -->
2205  <xsl:if test="$has-index">
2206    <fo:bookmark internal-destination="{concat($anchor-prefix,'.index')}">
2207      <fo:bookmark-title>Index</fo:bookmark-title>
2208    </fo:bookmark>
2209  </xsl:if>
2210
2211  <xsl:if test="$xml2rfc-ext-authors-section='end'">
2212    <xsl:apply-templates select="/rfc/front" mode="bookmarks" />
2213  </xsl:if>
2214
2215  <xsl:if test="$xml2rfc-private='' and not($no-copylong)">
2216    <!-- copyright statements -->
2217    <fo:bookmark internal-destination="{concat($anchor-prefix,'.ipr')}">
2218      <fo:bookmark-title>Intellectual Property and Copyright Statements</fo:bookmark-title>
2219    </fo:bookmark>
2220  </xsl:if>
2221 
2222</xsl:template>
2223
2224<xsl:template match="front" mode="bookmarks">
2225
2226  <xsl:variable name="authors-number">
2227    <xsl:call-template name="get-authors-section-number"/>
2228  </xsl:variable>
2229
2230  <xsl:variable name="title">
2231    <xsl:if test="$authors-number!=''">
2232      <xsl:value-of select="$authors-number"/>
2233      <xsl:text> </xsl:text>
2234    </xsl:if>
2235    <xsl:call-template name="get-authors-section-title"/>
2236  </xsl:variable>
2237
2238  <xsl:if test="$authors-number!='suppress'">
2239    <fo:bookmark internal-destination="{concat($anchor-prefix,'.authors')}">
2240      <fo:bookmark-title><xsl:value-of select="$title"/></fo:bookmark-title>
2241    </fo:bookmark>
2242  </xsl:if>
2243</xsl:template>
2244
2245<xsl:template match="middle" mode="bookmarks">
2246  <xsl:apply-templates mode="bookmarks" />
2247</xsl:template>
2248
2249<xsl:template name="references-bookmarks">
2250
2251  <!-- distinguish two cases: (a) single references element (process
2252  as toplevel section; (b) multiple references sections (add one toplevel
2253  container with subsection) -->
2254
2255  <xsl:choose>
2256    <xsl:when test="count(/*/back/references) = 0">
2257      <!-- nothing to do -->
2258    </xsl:when>
2259    <xsl:when test="count(/*/back/references) = 1">
2260      <xsl:for-each select="/*/back/references">
2261        <xsl:variable name="title">
2262          <xsl:choose>
2263            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2264            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2265          </xsl:choose>
2266        </xsl:variable>
2267     
2268        <fo:bookmark internal-destination="{$anchor-prefix}.references">
2269          <fo:bookmark-title>
2270            <xsl:call-template name="get-references-section-number"/>
2271            <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2272            <xsl:text> </xsl:text>
2273            <xsl:value-of select="$title"/>
2274          </fo:bookmark-title>
2275        </fo:bookmark>
2276      </xsl:for-each>
2277    </xsl:when>
2278    <xsl:otherwise>
2279      <!-- insert pseudo container -->   
2280      <fo:bookmark internal-destination="{$anchor-prefix}.references">
2281        <fo:bookmark-title>
2282          <xsl:call-template name="get-references-section-number"/>
2283          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2284          <xsl:text> </xsl:text>
2285          <xsl:value-of select="$xml2rfc-refparent"/>
2286        </fo:bookmark-title>
2287
2288        <!-- ...with subsections... -->   
2289        <xsl:for-each select="/*/back/references">
2290          <xsl:variable name="title">
2291            <xsl:choose>
2292              <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2293              <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2294            </xsl:choose>
2295          </xsl:variable>
2296       
2297          <xsl:variable name="sectionNumber">
2298            <xsl:call-template name="get-section-number" />
2299            <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2300          </xsl:variable>
2301 
2302          <xsl:variable name="num">
2303            <xsl:number/>
2304          </xsl:variable>
2305 
2306          <fo:bookmark internal-destination="{$anchor-prefix}.references.{$num}">
2307            <fo:bookmark-title><xsl:value-of select="concat($sectionNumber,' ',$title)"/></fo:bookmark-title>
2308          </fo:bookmark>
2309        </xsl:for-each>
2310      </fo:bookmark>
2311
2312    </xsl:otherwise>
2313  </xsl:choose>
2314</xsl:template>
2315
2316<xsl:template match="rfc" mode="bookmarks">
2317  <xsl:if test="$xml2rfc-private=''">
2318    <!-- Get status info formatted as per RFC2629-->
2319    <xsl:variable name="preamble"><xsl:call-template name="insertPreamble" /></xsl:variable>
2320   
2321    <!-- emit it -->
2322    <xsl:choose>
2323      <xsl:when test="function-available('exslt:node-set')">
2324        <xsl:apply-templates select="exslt:node-set($preamble)/node()" mode="bookmarks"/>
2325      </xsl:when>
2326      <xsl:otherwise>
2327        <xsl:variable name="temp" select="$preamble"/>
2328        <xsl:apply-templates select="$temp/node()" mode="bookmarks"/>
2329      </xsl:otherwise>
2330    </xsl:choose>
2331  </xsl:if>
2332 
2333  <xsl:apply-templates select="front/abstract" mode="bookmarks"/>
2334  <xsl:apply-templates select="front/note" mode="bookmarks"/>
2335
2336  <xsl:if test="$xml2rfc-toc='yes'">
2337    <fo:bookmark internal-destination="{concat($anchor-prefix,'.toc')}">
2338      <fo:bookmark-title>Table of Contents</fo:bookmark-title>
2339    </fo:bookmark>
2340  </xsl:if>
2341 
2342  <xsl:apply-templates select="middle|back" mode="bookmarks"/>
2343</xsl:template>
2344
2345<!-- experimental table formatting -->
2346
2347<xsl:template name="sum-widths">
2348  <xsl:param name="list"/>
2349  <xsl:choose>
2350    <xsl:when test="count($list)=0">
2351      <xsl:value-of select="0"/>
2352    </xsl:when>
2353    <xsl:when test="count($list)=1">
2354      <xsl:value-of select="number(substring-before($list[1],'%'))"/>
2355    </xsl:when>
2356    <xsl:otherwise>
2357      <xsl:variable name="remainder">
2358        <xsl:call-template name="sum-widths">
2359          <xsl:with-param name="list" select="$list[position()>1]" />
2360        </xsl:call-template>
2361      </xsl:variable>
2362      <xsl:value-of select="$remainder + number(substring-before($list[1],'%'))" />
2363    </xsl:otherwise>
2364  </xsl:choose>
2365</xsl:template>
2366
2367<!--
2368<xsl:attribute-set name="all-borders-solid">
2369  <xsl:attribute name="border-left-style">solid</xsl:attribute>
2370  <xsl:attribute name="border-right-style">solid</xsl:attribute>
2371  <xsl:attribute name="border-top-style">solid</xsl:attribute>
2372  <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2373  <xsl:attribute name="border-left-width">thin</xsl:attribute>
2374  <xsl:attribute name="border-right-width">thin</xsl:attribute>
2375  <xsl:attribute name="border-top-width">thin</xsl:attribute>
2376  <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2377  <xsl:attribute name="padding-left">0.5em</xsl:attribute>
2378  <xsl:attribute name="padding-right">0.5em</xsl:attribute>
2379</xsl:attribute-set>
2380
2381-->
2382
2383<xsl:template match="texttable">
2384
2385  <xsl:variable name="style">
2386    <xsl:choose>
2387      <xsl:when test="@style!=''">
2388        <xsl:value-of select="@style"/>
2389      </xsl:when>
2390      <xsl:otherwise>full</xsl:otherwise>
2391    </xsl:choose>
2392  </xsl:variable>
2393
2394  <xsl:variable name="anch">
2395    <xsl:call-template name="get-table-anchor"/>
2396  </xsl:variable>
2397
2398  <fo:block space-before=".5em" space-after=".5em" start-indent="2em" id="{$anch}">
2399    <xsl:call-template name="add-anchor"/>
2400    <xsl:apply-templates select="preamble" />
2401    <fo:table>
2402      <xsl:variable name="total-specified">
2403        <xsl:call-template name="sum-widths">
2404          <xsl:with-param name="list" select="ttcol/@width" />
2405        </xsl:call-template>
2406      </xsl:variable>
2407      <xsl:for-each select="ttcol">
2408        <fo:table-column>
2409          <xsl:choose>
2410            <xsl:when test="@width">
2411              <xsl:attribute name="column-width">proportional-column-width(<xsl:value-of select="substring-before(@width,'%')" />)</xsl:attribute>
2412            </xsl:when>
2413            <xsl:otherwise>
2414              <xsl:attribute name="column-width">proportional-column-width(<xsl:value-of select="(100 - number($total-specified)) div count(../ttcol[not(@width)])" />)</xsl:attribute>
2415            </xsl:otherwise>
2416          </xsl:choose>
2417        </fo:table-column>
2418      </xsl:for-each>
2419      <xsl:if test="ttcol!=''">
2420        <!-- skip header when all column titles are empty -->
2421        <fo:table-header start-indent="0em" space-after=".5em">
2422          <fo:table-row>
2423            <xsl:apply-templates select="ttcol" />
2424          </fo:table-row>
2425        </fo:table-header>
2426      </xsl:if>
2427      <fo:table-body start-indent="0em">
2428        <xsl:if test="$style='full' or $style='headers'">
2429          <xsl:attribute name="border-left-style">solid</xsl:attribute>
2430          <xsl:attribute name="border-right-style">solid</xsl:attribute>
2431          <xsl:attribute name="border-top-style">solid</xsl:attribute>
2432          <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2433          <xsl:attribute name="border-left-width">thin</xsl:attribute>
2434          <xsl:attribute name="border-right-width">thin</xsl:attribute>
2435          <xsl:attribute name="border-top-width">thin</xsl:attribute>
2436          <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2437        </xsl:if>
2438        <xsl:variable name="columns" select="count(ttcol)" />
2439        <xsl:for-each select="c[$columns=1 or (position() mod $columns) = 1]">
2440          <fo:table-row>
2441            <xsl:for-each select=". | following-sibling::c[position() &lt; $columns]">
2442              <fo:table-cell padding-left="0.5em" padding-right="0.5em">
2443                <xsl:if test="$style='full' or $style='headers'">
2444                  <xsl:attribute name="border-left-style">solid</xsl:attribute>
2445                  <xsl:attribute name="border-right-style">solid</xsl:attribute>
2446                  <xsl:attribute name="border-left-width">thin</xsl:attribute>
2447                  <xsl:attribute name="border-right-width">thin</xsl:attribute>
2448                </xsl:if>
2449                <xsl:if test="$style='full'">
2450                  <xsl:attribute name="border-top-style">solid</xsl:attribute>
2451                  <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2452                  <xsl:attribute name="border-top-width">thin</xsl:attribute>
2453                  <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2454                </xsl:if>
2455                <fo:block>
2456                  <xsl:variable name="pos" select="position()" />
2457                  <xsl:variable name="col" select="../ttcol[position() = $pos]" />
2458                  <xsl:if test="$col/@align">
2459                    <xsl:attribute name="text-align"><xsl:value-of select="$col/@align" /></xsl:attribute>
2460                  </xsl:if>
2461                  <xsl:apply-templates select="node()" />
2462                </fo:block>
2463              </fo:table-cell>
2464            </xsl:for-each>
2465          </fo:table-row>
2466        </xsl:for-each>
2467      </fo:table-body>
2468    </fo:table>
2469    <xsl:apply-templates select="postamble" />
2470    <xsl:if test="(@title!='' or @anchor!='') and not(@suppress-title='true')">
2471      <xsl:variable name="n"><xsl:number level="any" count="texttable[(@title!='' or @anchor!='') and not(@suppress-title='true')]" /></xsl:variable>
2472      <fo:block text-align="center" space-before="1em" space-after="1em">Table <xsl:value-of select="$n"/><xsl:if test="@title!=''">: <xsl:value-of select="@title" /></xsl:if></fo:block>
2473    </xsl:if>
2474  </fo:block>
2475</xsl:template>
2476
2477<xsl:template match="ttcol">
2478  <xsl:variable name="style">
2479    <xsl:choose>
2480      <xsl:when test="../@style!=''">
2481        <xsl:value-of select="../@style"/>
2482      </xsl:when>
2483      <xsl:otherwise>full</xsl:otherwise>
2484    </xsl:choose>
2485  </xsl:variable>
2486
2487  <fo:table-cell padding-left="0.5em" padding-right="0.5em">
2488    <xsl:if test="$style='full' or $style='headers'">
2489      <xsl:attribute name="border-left-style">solid</xsl:attribute>
2490      <xsl:attribute name="border-right-style">solid</xsl:attribute>
2491      <xsl:attribute name="border-top-style">solid</xsl:attribute>
2492      <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2493      <xsl:attribute name="border-left-width">thin</xsl:attribute>
2494      <xsl:attribute name="border-right-width">thin</xsl:attribute>
2495      <xsl:attribute name="border-top-width">thin</xsl:attribute>
2496      <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2497    </xsl:if>
2498<!--    <xsl:if test="@width">
2499      <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
2500    </xsl:if> -->
2501    <xsl:choose>
2502      <xsl:when test="@align">
2503        <xsl:attribute name="text-align"><xsl:value-of select="@align" /></xsl:attribute>
2504      </xsl:when>
2505      <xsl:otherwise>
2506        <xsl:attribute name="text-align">left</xsl:attribute>
2507      </xsl:otherwise>
2508    </xsl:choose>
2509    <fo:block font-weight="bold">
2510      <xsl:apply-templates />
2511    </fo:block>
2512  </fo:table-cell>
2513</xsl:template>
2514
2515<xsl:template name="add-anchor">
2516  <xsl:if test="@anchor">
2517    <fo:block id="{@anchor}" />
2518  </xsl:if>
2519</xsl:template>
2520
2521<!-- cref support -->
2522
2523<xsl:template match="cref">
2524  <xsl:if test="$xml2rfc-comments!='no'">
2525    <xsl:variable name="cid">
2526      <xsl:call-template name="get-comment-name"/>
2527    </xsl:variable>
2528   
2529    <xsl:choose>
2530      <xsl:when test="$xml2rfc-inline!='yes'">
2531        <fo:footnote>
2532          <fo:inline>
2533            <fo:basic-link font-size="8pt" vertical-align="super" internal-destination="{$cid}">[<xsl:value-of select="$cid"/>]</fo:basic-link>
2534          </fo:inline>
2535          <fo:footnote-body>
2536            <fo:block font-size="10pt" start-indent="2em" text-align="left" id="{$cid}">
2537              <fo:inline font-size="8pt" vertical-align="super">[<xsl:value-of select="$cid"/>]</fo:inline>
2538              <xsl:text> </xsl:text>
2539              <xsl:apply-templates select="node()"/>
2540              <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
2541            </fo:block>
2542          </fo:footnote-body>
2543        </fo:footnote>
2544      </xsl:when>
2545      <xsl:otherwise>
2546        <fo:inline xsl:use-attribute-sets="comment">
2547          <xsl:text>[</xsl:text>
2548          <xsl:value-of select="$cid"/>
2549          <xsl:text>: </xsl:text>
2550          <xsl:apply-templates select="node()"/>
2551          <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
2552          <xsl:text>]</xsl:text>
2553        </fo:inline>
2554      </xsl:otherwise>
2555    </xsl:choose>   
2556  </xsl:if>
2557</xsl:template>
2558
2559
2560
2561<xsl:template name="insert-justification">
2562  <xsl:if test="$xml2rfc-ext-justification='always' or $xml2rfc-ext-justification='print'">
2563    <xsl:attribute name="text-align">justify</xsl:attribute>
2564  </xsl:if>
2565</xsl:template>
2566
2567<!-- Extensions -->
2568
2569<!-- Nothing to do for PDF output -->
2570<xsl:template match="x:assign-section-number" />
2571<xsl:template match="x:link" />
2572
2573<!-- Nothing to do here -->
2574<xsl:template match="x:anchor-alias" />
2575
2576<!-- internal ref support -->
2577<xsl:template match="x:ref">
2578  <xsl:variable name="val" select="."/>
2579  <xsl:variable name="target" select="//*[(@anchor and x:anchor-alias/@value=$val) or (@anchor=$val)]"/>
2580  <xsl:choose>
2581    <xsl:when test="$target">
2582      <fo:basic-link internal-destination="{$target/@anchor}" xsl:use-attribute-sets="internal-link">
2583        <xsl:call-template name="copy-anchor"/>
2584        <xsl:apply-templates/>
2585      </fo:basic-link>
2586    </xsl:when>
2587    <xsl:otherwise>
2588      <xsl:call-template name="warning">
2589        <xsl:with-param name="inline" select="'no'"/>
2590        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:with-param>
2591      </xsl:call-template>
2592      <xsl:apply-templates/>
2593    </xsl:otherwise>
2594  </xsl:choose>
2595</xsl:template>
2596
2597<!-- BCP14 keywords -->
2598<xsl:template match="x:bcp14">
2599  <!-- figure out something that prints well -->
2600  <xsl:apply-templates/>
2601</xsl:template>
2602
2603<!-- Notes -->
2604<xsl:template match="x:note">
2605  <xsl:apply-templates/>
2606</xsl:template>
2607
2608<!-- Quotes -->
2609<xsl:template match="x:blockquote">
2610  <fo:block font-style="italic" space-before=".5em" space-after=".5em" start-indent="3em"
2611      border-left-style="solid" border-left-color="gray" border-left-width=".25em" padding-left=".5em">
2612    <xsl:apply-templates/>
2613  </fo:block>
2614</xsl:template>
2615
2616<xsl:template match="x:q">
2617  <fo:wrapper font-style="italic">
2618    <xsl:text>&#8220;</xsl:text>
2619    <xsl:apply-templates/>
2620    <xsl:text>&#8221;</xsl:text>
2621  </fo:wrapper>
2622</xsl:template>
2623
2624<!-- Definitions -->
2625<xsl:template match="x:dfn">
2626  <fo:wrapper font-style="italic">
2627    <xsl:if test="not(preceding-sibling::x:dfn) and count(following-sibling::list)=1">
2628      <xsl:attribute name="keep-with-next">always</xsl:attribute>
2629    </xsl:if>
2630    <xsl:apply-templates/>
2631  </fo:wrapper>
2632</xsl:template>
2633
2634<!-- Headings -->
2635<xsl:template match="x:h">
2636  <fo:wrapper font-weight="bold">
2637    <xsl:apply-templates/>
2638  </fo:wrapper>
2639</xsl:template>
2640
2641<!-- Highlightinghing -->
2642<xsl:template match="x:highlight">
2643  <fo:wrapper font-weight="bold">
2644    <xsl:apply-templates/>
2645  </fo:wrapper>
2646</xsl:template>
2647
2648<!-- Superscripts -->
2649<xsl:template match="x:sup">
2650  <xsl:text>^</xsl:text> <!-- make this prettier -->
2651  <xsl:apply-templates/>
2652</xsl:template>
2653
2654<!-- measuring lengths -->
2655<xsl:template match="x:length-of">
2656  <xsl:variable name="target" select="//*[@anchor=current()/@target]"/>
2657  <xsl:if test="count($target)!=1">
2658    <xsl:call-template name="error">
2659      <xsl:with-param name="msg" select="concat('@target ',@target,' defined ',count($target),' times.')"/>
2660    </xsl:call-template>
2661  </xsl:if>
2662  <xsl:variable name="content">
2663    <xsl:apply-templates select="$target"/>
2664  </xsl:variable>
2665  <xsl:variable name="lineends" select="string-length($content) - string-length(translate($content,'&#10;',''))"/>
2666  <xsl:variable name="indents">
2667    <xsl:choose>
2668      <xsl:when test="@indented">
2669        <xsl:value-of select="number(@indented) * $lineends"/>
2670      </xsl:when>
2671      <xsl:otherwise>0</xsl:otherwise>
2672    </xsl:choose>
2673  </xsl:variable>
2674  <xsl:value-of select="string-length($content) + $lineends - $indents"/>
2675</xsl:template>
2676
2677<!-- Nop -->
2678<xsl:template match="x:span">
2679  <xsl:apply-templates/>
2680</xsl:template>
2681
2682<!-- XML checking -->
2683<xsl:template match="x:parse-xml">
2684  <xsl:apply-templates/>
2685</xsl:template>
2686
2687<xsl:template match="x:abnf-char-sequence">
2688  <xsl:choose>
2689    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
2690      <xsl:call-template name="error">
2691        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
2692      </xsl:call-template>
2693    </xsl:when>
2694    <xsl:otherwise>
2695      <xsl:text>%x</xsl:text>
2696      <xsl:call-template name="to-abnf-char-sequence">
2697        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
2698      </xsl:call-template>
2699    </xsl:otherwise>
2700  </xsl:choose>
2701</xsl:template>
2702
2703<!-- inlined RDF support -->
2704<xsl:template match="rdf:Description">
2705  <!-- ignore -->
2706</xsl:template>
2707
2708<!-- box drawing -->
2709
2710<!-- nop for alignment -->
2711<xsl:template match="x:x"/>
2712
2713<!-- box -->
2714<xsl:template match="x:bt|x:bc|x:bb">
2715  <xsl:apply-templates />
2716</xsl:template>
2717
2718<!-- author handling extensions -->
2719<xsl:template match="x:include-author">
2720  <xsl:for-each select="/*/front/author[@anchor=current()/@target]">
2721    <xsl:apply-templates select="."/>
2722  </xsl:for-each>
2723</xsl:template>
2724
2725<!-- boilerplate -->
2726<xsl:template match="x:boilerplate">
2727  <xsl:apply-templates/>
2728</xsl:template>
2729
2730  <!-- experimental: format URI with zero-width spaces to ease line breaks -->
2731 
2732  <xsl:template name="format-uri">
2733    <xsl:param name="s"/>
2734    <xsl:param name="mode"/>
2735   
2736    <xsl:choose>
2737      <!-- optimization for not hypenating the scheme name -->
2738      <xsl:when test="$mode!='after-scheme' and string-length(substring-before($s,':')) > 2">
2739        <xsl:value-of select="concat(substring-before($s,':'),':&#x200b;')"/>
2740        <xsl:call-template name="format-uri">
2741          <xsl:with-param name="s" select="substring-after($s,':')"/>
2742          <xsl:with-param name="mode" select="'after-scheme'"/>
2743        </xsl:call-template>
2744      </xsl:when>
2745      <!-- do no insert break points after hyphens -->
2746      <xsl:when test="starts-with($s,'-')">
2747        <xsl:text>-</xsl:text>
2748        <xsl:call-template name="format-uri">
2749          <xsl:with-param name="s" select="substring($s,2)"/>
2750          <xsl:with-param name="mode" select="'after-scheme'"/>
2751        </xsl:call-template>
2752      </xsl:when>
2753      <!-- last char?-->
2754      <xsl:when test="string-length($s)=1">
2755        <xsl:value-of select="$s"/>
2756      </xsl:when>
2757      <!-- add one zwsp after each character -->
2758      <xsl:when test="$s!=''">
2759        <xsl:value-of select="concat(substring($s,1,1),'&#x200b;')"/>
2760        <xsl:call-template name="format-uri">
2761          <xsl:with-param name="s" select="substring($s,2)"/>
2762          <xsl:with-param name="mode" select="'after-scheme'"/>
2763        </xsl:call-template>
2764      </xsl:when>
2765      <xsl:otherwise>
2766        <!-- done -->
2767      </xsl:otherwise>
2768    </xsl:choose>
2769   
2770  </xsl:template>
2771
2772</xsl:transform>
Note: See TracBrowser for help on using the repository browser.