source: rfc2629xslt/rfc2629toFO.xslt @ 276

Last change on this file since 276 was 272, checked in by julian.reschke@…, 12 years ago

Update to latest version of rfc2629.xslt, and take advantage of it.

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