source: rfc2629xslt/rfc2629toFO.xslt @ 2280

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

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

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