source: rfc2629xslt/rfc2629toFO.xslt @ 2738

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

update rfc2629.xslt

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