source: rfc2629xslt/rfc2629toFO.xslt @ 2649

Last change on this file since 2649 was 2628, checked in by julian.reschke@…, 6 years ago

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

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