source: rfc2629xslt/rfc2629toFO.xslt @ 2610

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