source: rfc2629xslt/rfc2629toFO.xslt @ 2734

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

update XSLTs, switch to Saxon 9.6 HE in Makefile, regen specs

  • Property svn:eol-style set to native
File size: 118.2 KB
Line 
1<!--
2    XSLT transformation from RFC2629 XML format to XSL-FO
3     
4    Copyright (c) 2006-2014, Julian Reschke (julian.reschke@greenbytes.de)
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions are met:
9
10    * Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    * Neither the name of Julian Reschke nor the names of its contributors
16      may be used to endorse or promote products derived from this software
17      without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33    version="1.0"
34    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="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="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="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 | 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::list/@style='numbers' or parent::ol"><xsl:number/>.</xsl:when>
676          <xsl:when test="ancestor::list/@style='letters'"><xsl:number format="a"/>.</xsl:when>
677          <xsl:otherwise>???</xsl:otherwise>
678        </xsl:choose>
679      </fo:block>
680    </fo:list-item-label>
681    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
682  </fo:list-item>
683</xsl:template>
684
685<xsl:template match="list[@style='numbers' or @style='letters' or (not(@style) and ancestor::list[@style='numbers' or @style='letters'])]/x:lt" priority="1">
686  <fo:list-item space-before=".25em" space-after=".25em">
687    <xsl:call-template name="copy-anchor"/>
688    <fo:list-item-label end-indent="label-end()">
689      <fo:block>
690        <xsl:choose>
691          <xsl:when test="ancestor::list/@style='numbers'"><xsl:number/>.</xsl:when>
692          <xsl:when test="ancestor::list/@style='letters'"><xsl:number format="a"/>.</xsl:when>
693          <xsl:otherwise>???</xsl:otherwise>
694        </xsl:choose>
695      </fo:block>
696    </fo:list-item-label>
697    <fo:list-item-body start-indent="body-start()">
698      <xsl:for-each select="t">
699        <fo:block>
700          <xsl:if test="position()!=1">
701            <xsl:attribute name="space-before">.25em</xsl:attribute>
702          </xsl:if>
703          <xsl:apply-templates />
704        </fo:block>
705      </xsl:for-each>
706    </fo:list-item-body>
707  </fo:list-item>
708</xsl:template>
709
710<!-- special case: nested -->
711<xsl:template match="list//t//list[@style='letters']/t" priority="9">
712  <fo:list-item space-before=".25em" space-after=".25em">
713    <xsl:call-template name="copy-anchor"/>
714    <fo:list-item-label end-indent="label-end()"><fo:block><xsl:number format="A"/>.</fo:block></fo:list-item-label>
715    <fo:list-item-body start-indent="body-start()"><fo:block><xsl:apply-templates /></fo:block></fo:list-item-body>
716  </fo:list-item>
717</xsl:template>
718
719<xsl:template match="list[starts-with(@style,'format ')]" priority="1">
720  <fo:list-block provisional-distance-between-starts="{string-length(@style) - string-length('format ')}em">
721    <xsl:apply-templates />
722  </fo:list-block>
723</xsl:template>
724
725<xsl:template match="list[starts-with(@style,'format ')]/t" priority="1">
726  <xsl:variable name="list" select=".." />
727  <xsl:variable name="format" select="substring-after(../@style,'format ')" />
728  <xsl:variable name="pos">
729    <xsl:choose>
730      <xsl:when test="$list/@counter">
731        <xsl:number level="any" count="list[@counter=$list/@counter or (not(@counter) and @style=concat('format ',$list/@counter))]/t" />
732      </xsl:when>
733      <xsl:otherwise>
734        <xsl:number level="any" count="list[concat('format ',@counter)=$list/@style or (not(@counter) and @style=$list/@style)]/t" />
735      </xsl:otherwise>
736    </xsl:choose>
737  </xsl:variable>
738  <fo:list-item space-before=".25em" space-after=".25em">
739    <xsl:call-template name="copy-anchor"/>
740    <fo:list-item-label end-indent="label-end()">
741      <fo:block>
742        <xsl:call-template name="expand-format-percent">
743          <xsl:with-param name="format" select="$format"/>
744          <xsl:with-param name="pos" select="$pos"/>
745        </xsl:call-template>
746      </fo:block>
747    </fo:list-item-label>
748    <fo:list-item-body start-indent="body-start()">
749      <fo:block>
750        <xsl:apply-templates />
751      </fo:block>
752    </fo:list-item-body>
753  </fo:list-item>
754</xsl:template>
755
756<xsl:template match="middle">
757  <xsl:apply-templates />
758</xsl:template>
759               
760<xsl:template match="note">
761  <xsl:variable name="num"><xsl:number count="note"/></xsl:variable>
762  <fo:block xsl:use-attribute-sets="h1" id="{concat($anchor-prefix,'.note.',$num)}"><xsl:value-of select="@title" /></fo:block>
763  <xsl:apply-templates />
764</xsl:template>
765
766<xsl:template match="preamble">
767  <fo:block space-after=".5em">
768    <xsl:call-template name="copy-anchor"/>
769    <xsl:apply-templates />
770  </fo:block>
771</xsl:template>
772
773<xsl:template match="postamble">
774  <fo:block space-before=".5em"><xsl:apply-templates /></fo:block>
775</xsl:template>
776
777<!-- processed elsewhere -->
778<xsl:template match="displayreference"/>
779
780<xsl:template match="reference">
781
782  <xsl:variable name="target">
783    <xsl:choose>
784      <xsl:when test="@target"><xsl:value-of select="@target" /></xsl:when>
785      <xsl:when test="seriesInfo/@name='RFC'"><xsl:value-of select="concat($rfcUrlPrefix,seriesInfo[@name='RFC']/@value,'.txt')" /></xsl:when>
786      <xsl:when test="seriesInfo[starts-with(.,'RFC')]">
787        <xsl:variable name="rfcRef" select="seriesInfo[starts-with(.,'RFC')]" />
788        <xsl:value-of select="concat($rfcUrlPrefix,substring-after (normalize-space($rfcRef), ' '),'.txt')" />
789      </xsl:when>
790      <xsl:otherwise />
791    </xsl:choose>
792  </xsl:variable>
793
794  <fo:list-item space-after=".5em">
795    <fo:list-item-label end-indent="label-end()">
796      <fo:block id="{@anchor}">
797        <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
798          <xsl:attribute name="index-key">
799            <xsl:value-of select="concat('xrefitem=',@anchor)"/>
800          </xsl:attribute>
801        </xsl:if>
802        <xsl:call-template name="reference-name"/>
803      </fo:block>
804    </fo:list-item-label>
805   
806    <fo:list-item-body start-indent="body-start()"><fo:block>
807
808      <xsl:for-each select="front/author">
809        <xsl:variable name="initials">
810          <xsl:call-template name="format-initials"/>
811        </xsl:variable>
812        <xsl:variable name="truncated-initials">
813          <xsl:call-template name="truncate-initials">
814            <xsl:with-param name="initials" select="$initials"/>
815          </xsl:call-template>
816        </xsl:variable>
817        <xsl:choose>
818          <xsl:when test="@surname and @surname!=''">
819            <xsl:choose>
820              <xsl:when test="@surname and position()=last() and position()!=1">
821                <xsl:value-of select="concat($truncated-initials,' ',@surname)" />
822              </xsl:when>
823              <xsl:when test="@surname">
824                <xsl:value-of select="concat(@surname,', ',$truncated-initials)" />
825              </xsl:when>
826              <xsl:when test="organization/text()">
827                <xsl:value-of select="organization" />
828              </xsl:when>
829              <xsl:otherwise />
830            </xsl:choose>
831            <xsl:if test="@role='editor'">
832              <xsl:text>, Ed.</xsl:text>
833            </xsl:if>
834            <xsl:choose>
835              <xsl:when test="position()=last() - 1">
836                <xsl:if test="last() &gt; 2">,</xsl:if>
837                <xsl:text> and </xsl:text>
838              </xsl:when>
839              <xsl:otherwise>
840                <xsl:text>, </xsl:text>
841              </xsl:otherwise>
842            </xsl:choose>
843          </xsl:when>
844          <xsl:when test="organization/text()">
845            <xsl:value-of select="organization" />
846            <xsl:choose>
847              <xsl:when test="position()=last() - 1">
848                <xsl:if test="last() &gt; 2">,</xsl:if>
849                <xsl:text> and </xsl:text>
850              </xsl:when>
851              <xsl:otherwise>
852                <xsl:text>, </xsl:text>
853              </xsl:otherwise>
854            </xsl:choose>
855          </xsl:when>
856          <xsl:otherwise />
857        </xsl:choose>
858      </xsl:for-each>
859
860      <xsl:if test="not(front/title/@x:quotes='false')">"<!--&#8220;--></xsl:if>
861      <xsl:choose>
862        <xsl:when test="string-length($target) &gt; 0">
863          <fo:basic-link external-destination="url('{$target}')" xsl:use-attribute-sets="external-link"><xsl:value-of select="normalize-space(front/title)" /></fo:basic-link>
864        </xsl:when>
865        <xsl:otherwise>
866          <xsl:value-of select="normalize-space(front/title)" />
867        </xsl:otherwise>
868      </xsl:choose>
869      <xsl:if test="not(front/title/@x:quotes='false')">"<!--&#8221;--></xsl:if>
870     
871      <xsl:for-each select="seriesInfo">
872        <xsl:text>, </xsl:text>
873        <xsl:choose>
874          <xsl:when test="not(@name) and not(@value) and ./text()"><xsl:value-of select="." /></xsl:when>
875          <xsl:otherwise>
876            <xsl:value-of select="@name" />
877            <xsl:if test="@value!=''">&#0160;<xsl:value-of select="@value" /></xsl:if>
878            <xsl:if test="translate(@name,$ucase,$lcase)='internet-draft'"> (work in progress)</xsl:if>
879          </xsl:otherwise>
880        </xsl:choose>
881      </xsl:for-each>
882
883      <!-- avoid hacks using seriesInfo when it's not really series information -->
884      <xsl:for-each select="x:prose|refcontent">
885        <xsl:text>, </xsl:text>
886        <xsl:apply-templates/>
887      </xsl:for-each>
888
889      <xsl:if test="front/date/@year!=''">
890        <xsl:text>, </xsl:text>
891        <xsl:value-of select="front/date/@month" />&#0160;<xsl:value-of select="front/date/@year" />
892      </xsl:if>
893     
894      <xsl:if test="@target">
895        <xsl:text>, &lt;</xsl:text>
896        <xsl:call-template name="format-uri">
897          <xsl:with-param name="s" select="@target"/>
898        </xsl:call-template>
899        <xsl:text>&gt;</xsl:text>
900      </xsl:if>
901
902      <xsl:text>.</xsl:text>
903     
904      <xsl:for-each select="annotation">
905        <fo:block><xsl:apply-templates /></fo:block>
906      </xsl:for-each>
907     
908    </fo:block></fo:list-item-body>
909  </fo:list-item>
910</xsl:template>
911
912<xsl:template match="references">
913
914  <xsl:variable name="name">
915    <xsl:number/>     
916  </xsl:variable>
917
918  <!-- insert pseudo section when needed -->
919  <xsl:if test="$name='1' and count(/*/back/references)!=1">
920    <fo:block id="{$anchor-prefix}.references" xsl:use-attribute-sets="h1">
921      <xsl:if test="$name='1'">
922        <xsl:attribute name="page-break-before">always</xsl:attribute>
923      </xsl:if>
924      <xsl:variable name="sectionNumber">
925        <xsl:call-template name="get-references-section-number"/>
926      </xsl:variable>
927      <xsl:call-template name="emit-section-number">
928        <xsl:with-param name="no" select="$sectionNumber"/>
929      </xsl:call-template>
930      <xsl:text>&#160;&#160;</xsl:text>
931      <xsl:value-of select="$xml2rfc-refparent"/>
932    </fo:block>
933  </xsl:if>
934
935  <xsl:choose>
936    <xsl:when test="count(/*/back/references)=1">
937      <fo:block id="{$anchor-prefix}.references" xsl:use-attribute-sets="h1 newpage">
938        <xsl:variable name="sectionNumber">
939          <xsl:call-template name="get-section-number"/>
940        </xsl:variable>
941        <xsl:call-template name="emit-section-number">
942          <xsl:with-param name="no" select="$sectionNumber"/>
943        </xsl:call-template>
944        <xsl:text>&#160;&#160;</xsl:text>
945        <xsl:choose>
946          <xsl:when test="name">
947            <xsl:if test="@title">
948              <xsl:call-template name="warning">
949                <xsl:with-param name="msg">both @title attribute and name child node present</xsl:with-param>
950              </xsl:call-template>
951            </xsl:if>
952            <xsl:apply-templates select="name/node()"/>
953          </xsl:when>
954          <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
955          <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
956        </xsl:choose>
957      </fo:block>
958    </xsl:when>
959    <xsl:otherwise>
960      <fo:block id="{$anchor-prefix}.references.{$name}" xsl:use-attribute-sets="h2">
961        <xsl:variable name="sectionNumber">
962          <xsl:call-template name="get-section-number"/>
963        </xsl:variable>
964        <xsl:call-template name="emit-section-number">
965          <xsl:with-param name="no" select="$sectionNumber"/>
966        </xsl:call-template>
967        <xsl:text>&#160;&#160;</xsl:text>
968        <xsl:choose>
969          <xsl:when test="@title!=''"><xsl:value-of select="@title"/></xsl:when>
970          <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
971        </xsl:choose>
972      </fo:block>
973    </xsl:otherwise>
974  </xsl:choose>
975
976  <!-- find longest label and use it to calculate indentation-->
977  <xsl:variable name="l">
978    <xsl:choose>
979      <xsl:when test="$xml2rfc-symrefs='no'">[99]</xsl:when>
980      <xsl:otherwise>
981        <xsl:for-each select="//reference">
982          <xsl:sort select="string-length(@anchor)" order="descending" data-type="number"/>
983          <xsl:if test="position()=1">
984            <xsl:value-of select="@anchor" />
985          </xsl:if>
986        </xsl:for-each>
987      </xsl:otherwise>
988    </xsl:choose>
989  </xsl:variable>
990
991  <fo:list-block provisional-distance-between-starts="{string-length($l) * 0.8}em">
992    <xsl:choose>
993      <xsl:when test="$xml2rfc-sortrefs='yes'">
994        <xsl:apply-templates>
995          <xsl:sort select="/rfc/back/displayreference[@target=current()/@anchor]/@to|@anchor"/>
996        </xsl:apply-templates>
997      </xsl:when>
998      <xsl:otherwise>
999        <xsl:apply-templates />
1000      </xsl:otherwise>
1001    </xsl:choose>
1002  </fo:list-block>
1003</xsl:template>
1004
1005<!-- handled above -->
1006<xsl:template match="references/name"/>
1007
1008<xsl:template match="rfc">
1009  <fo:root xsl:use-attribute-sets="base">
1010   
1011    <fo:layout-master-set>
1012      <fo:simple-page-master master-name="first-page" xsl:use-attribute-sets="page">
1013        <fo:region-body margin-bottom="1in" margin-top="1in"/>
1014         <fo:region-after extent="1cm" region-name="footer"/>
1015      </fo:simple-page-master>
1016      <fo:simple-page-master master-name="other-pages-right" xsl:use-attribute-sets="page">
1017        <fo:region-body margin-bottom="1in" margin-top="1in" />
1018        <fo:region-before extent="1cm" region-name="header-right"/>
1019        <fo:region-after extent="1cm" region-name="footer-right"/>
1020      </fo:simple-page-master>
1021      <fo:simple-page-master master-name="other-pages-left" xsl:use-attribute-sets="page">
1022        <fo:region-body margin-bottom="1in" margin-top="1in" />
1023        <fo:region-before extent="1cm" region-name="header-left"/>
1024        <fo:region-after extent="1cm" region-name="footer-left"/>
1025      </fo:simple-page-master>
1026      <fo:simple-page-master master-name="other-pages-dc-right" xsl:use-attribute-sets="page">
1027        <fo:region-body margin-bottom="1in" margin-top="1in" column-count="2"/>
1028        <fo:region-before extent="1cm" region-name="header-right"/>
1029        <fo:region-after extent="1cm" region-name="footer-right"/>
1030      </fo:simple-page-master>
1031      <fo:simple-page-master master-name="other-pages-dc-left" xsl:use-attribute-sets="page">
1032        <fo:region-body margin-bottom="1in" margin-top="1in" column-count="2"/>
1033        <fo:region-before extent="1cm" region-name="header-left"/>
1034        <fo:region-after extent="1cm" region-name="footer-left"/>
1035      </fo:simple-page-master>
1036      <fo:page-sequence-master master-name="sequence"> 
1037        <fo:single-page-master-reference master-reference="first-page" />
1038        <xsl:choose>
1039          <xsl:when test="$xml2rfc-ext-duplex='yes'">
1040            <fo:repeatable-page-master-alternatives>
1041              <fo:conditional-page-master-reference odd-or-even="even" master-reference="other-pages-left"/>
1042              <fo:conditional-page-master-reference odd-or-even="odd" master-reference="other-pages-right"/>
1043            </fo:repeatable-page-master-alternatives>
1044          </xsl:when>
1045          <xsl:otherwise>
1046            <fo:repeatable-page-master-reference master-reference="other-pages-right" /> 
1047          </xsl:otherwise>
1048        </xsl:choose>
1049      </fo:page-sequence-master>
1050      <fo:page-sequence-master master-name="sequence-dc"> 
1051        <xsl:choose>
1052          <xsl:when test="$xml2rfc-ext-duplex='yes'">
1053            <fo:repeatable-page-master-alternatives>
1054              <fo:conditional-page-master-reference odd-or-even="even" master-reference="other-pages-dc-left"/>
1055              <fo:conditional-page-master-reference odd-or-even="odd" master-reference="other-pages-dc-right"/>
1056            </fo:repeatable-page-master-alternatives>
1057          </xsl:when>
1058          <xsl:otherwise>
1059            <fo:repeatable-page-master-reference master-reference="other-pages-dc-right" /> 
1060          </xsl:otherwise>
1061        </xsl:choose>
1062      </fo:page-sequence-master>
1063    </fo:layout-master-set>
1064
1065    <fo:declarations>
1066      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
1067        <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
1068          <dc:title><xsl:value-of select="/rfc/front/title"/></dc:title>
1069          <dc:creator><xsl:call-template name="get-author-summary" /></dc:creator>
1070          <dc:description><xsl:value-of select="normalize-space(/rfc/front/abstract)"/></dc:description>
1071          <xsl:if test="/rfc/@number">
1072            <dc:isPartOf>urn:ISSN:2070-1721</dc:isPartOf>
1073          </xsl:if>     
1074          <xsl:if test="/rfc/front/keyword" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
1075            <pdf:Keywords>
1076              <xsl:for-each select="/rfc/front/keyword">
1077                <xsl:value-of select="."/>
1078                <xsl:if test="position()!=last()">, </xsl:if>
1079              </xsl:for-each>
1080            </pdf:Keywords>
1081          </xsl:if>
1082        </rdf:Description>
1083      </rdf:RDF>
1084    </fo:declarations>
1085   
1086    <fo:bookmark-tree>
1087      <xsl:apply-templates select="." mode="bookmarks" />
1088    </fo:bookmark-tree>
1089
1090    <xsl:variable name="lang"><xsl:call-template name="get-lang"/></xsl:variable>
1091
1092    <fo:page-sequence master-reference="sequence" language="{$lang}">
1093      <xsl:if test="$xml2rfc-ext-duplex='yes'">
1094        <xsl:attribute name="force-page-count">even</xsl:attribute>
1095      </xsl:if>
1096
1097      <xsl:call-template name="insertHeader" />
1098      <xsl:call-template name="insertFooter" />
1099     
1100      <fo:flow flow-name="xsl-region-body">
1101       
1102        <!-- process front & middle section, but not back -->
1103        <xsl:apply-templates />
1104       
1105        <!-- because it requires multiple page masters -->
1106        <!-- references first -->
1107        <xsl:apply-templates select="back/references" />
1108       
1109        <xsl:if test="$xml2rfc-ext-authors-section='before-appendices'">
1110          <xsl:call-template name="insertAuthors" />
1111        </xsl:if>
1112       
1113        <!-- add all other top-level sections under <back> -->
1114        <xsl:apply-templates select="back/*[not(self::references)]" />
1115     
1116      </fo:flow>
1117    </fo:page-sequence>
1118   
1119    <xsl:if test="$has-index">
1120      <fo:page-sequence master-reference="sequence-dc" language="{$lang}">
1121        <xsl:if test="$xml2rfc-ext-duplex='yes'">
1122          <xsl:attribute name="force-page-count">even</xsl:attribute>
1123        </xsl:if>
1124        <xsl:call-template name="insertHeader" />
1125        <xsl:call-template name="insertFooter" />
1126        <fo:flow flow-name="xsl-region-body" xsl:use-attribute-sets="index">
1127          <xsl:call-template name="insertIndex" />   
1128        </fo:flow>
1129      </fo:page-sequence>
1130    </xsl:if>
1131
1132    <xsl:if test="$xml2rfc-ext-authors-section='end' or ($xml2rfc-private='' and not($no-copylong))">
1133      <fo:page-sequence master-reference="sequence" language="{$lang}">
1134        <xsl:if test="$xml2rfc-ext-duplex='yes'">
1135          <xsl:attribute name="force-page-count">even</xsl:attribute>
1136        </xsl:if>
1137 
1138        <xsl:call-template name="insertHeader" />
1139        <xsl:call-template name="insertFooter" />
1140       
1141        <fo:flow flow-name="xsl-region-body">
1142         
1143          <xsl:if test="$xml2rfc-ext-authors-section='end'">
1144            <xsl:call-template name="insertAuthors" />
1145          </xsl:if>
1146 
1147          <xsl:if test="$xml2rfc-private=''">
1148            <!-- copyright statements -->
1149            <xsl:variable name="copyright">
1150              <xsl:call-template name="insertCopyright" />
1151            </xsl:variable>
1152         
1153            <!-- emit it -->
1154            <xsl:choose>
1155              <xsl:when test="function-available('exslt:node-set')">
1156                <xsl:apply-templates select="exslt:node-set($copyright)/node()" />
1157              </xsl:when>
1158              <xsl:otherwise> <!--proceed with fingers crossed-->
1159                <xsl:variable name="temp" select="$copyright"/>
1160                <xsl:apply-templates select="$temp/node()" />
1161              </xsl:otherwise>
1162            </xsl:choose>
1163          </xsl:if>
1164         
1165        </fo:flow>
1166      </fo:page-sequence>
1167    </xsl:if>
1168   
1169  </fo:root>
1170</xsl:template>
1171
1172
1173<xsl:template name="section-maker">
1174  <xsl:variable name="sectionNumber">
1175    <xsl:choose>
1176      <xsl:when test="@myns:unnumbered"></xsl:when>
1177      <xsl:when test="ancestor::x:boilerplate"></xsl:when>
1178      <xsl:otherwise><xsl:call-template name="get-section-number" /></xsl:otherwise>
1179    </xsl:choose>
1180  </xsl:variable>
1181
1182  <xsl:if test="$sectionNumber!=''">
1183    <xsl:attribute name="id"><xsl:value-of select="concat($anchor-prefix,'.section.',$sectionNumber)"/>
1184  </xsl:attribute></xsl:if>
1185 
1186  <xsl:call-template name="add-anchor" />
1187 
1188  <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
1189    <xsl:call-template name="emit-section-number">
1190      <xsl:with-param name="no" select="$sectionNumber"/>
1191    </xsl:call-template>
1192    <xsl:text>&#0160;&#0160;</xsl:text>
1193  </xsl:if>
1194 
1195  <xsl:choose>
1196    <xsl:when test="name">
1197      <xsl:apply-templates select="name/node()"/>
1198      <xsl:if test="@title">
1199        <xsl:call-template name="warning">
1200          <xsl:with-param name="msg">both @title attribute and name child node present</xsl:with-param>
1201        </xsl:call-template>
1202      </xsl:if>
1203    </xsl:when>
1204    <xsl:otherwise>
1205      <xsl:value-of select="@title" />
1206    </xsl:otherwise>
1207  </xsl:choose>
1208
1209  <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>
1210</xsl:template>
1211
1212<!-- handled in section-maker -->
1213<xsl:template match="section/name"/>
1214
1215<xsl:template match="section[count(ancestor::section) = 0 and (@myns:notoclink or ancestor::x:boilerplate)]">
1216
1217  <fo:block xsl:use-attribute-sets="h1">
1218    <xsl:call-template name="section-maker" />
1219  </fo:block>
1220
1221  <xsl:apply-templates select="iref" mode="iref-start"/>
1222  <xsl:apply-templates />
1223  <xsl:apply-templates select="iref" mode="iref-end"/>
1224</xsl:template>
1225
1226<xsl:template match="section[count(ancestor::section) = 0 and not(@myns:notoclink or ancestor::x:boilerplate)]">
1227
1228  <fo:block xsl:use-attribute-sets="h1 newpage">
1229    <xsl:call-template name="section-maker" />
1230  </fo:block>
1231
1232  <xsl:apply-templates select="iref" mode="iref-start"/>
1233  <xsl:apply-templates />
1234  <xsl:apply-templates select="iref" mode="iref-end"/>
1235</xsl:template>
1236
1237<xsl:template match="section[count(ancestor::section) = 1]">
1238  <fo:block xsl:use-attribute-sets="h2">
1239    <xsl:call-template name="section-maker" />
1240  </fo:block>
1241
1242  <xsl:apply-templates select="iref" mode="iref-start"/>
1243  <xsl:apply-templates />
1244  <xsl:apply-templates select="iref" mode="iref-end"/>
1245</xsl:template>
1246
1247<xsl:template match="section[count(ancestor::section) &gt; 1]">
1248  <fo:block xsl:use-attribute-sets="h3">
1249    <xsl:call-template name="section-maker" />
1250  </fo:block>
1251
1252  <xsl:apply-templates select="iref" mode="iref-start"/>
1253  <xsl:apply-templates />
1254  <xsl:apply-templates select="iref" mode="iref-end"/>
1255</xsl:template>
1256
1257<xsl:template match="spanx[@style='emph' or not(@style)]|em|i">
1258  <fo:wrapper font-style="italic">
1259    <xsl:call-template name="copy-anchor"/>
1260    <xsl:apply-templates />
1261  </fo:wrapper>
1262</xsl:template>
1263
1264<xsl:template match="spanx[@style='strong']|strong|b">
1265  <fo:wrapper font-weight="bold">
1266    <xsl:call-template name="copy-anchor"/>
1267    <xsl:apply-templates />
1268  </fo:wrapper>
1269</xsl:template>
1270
1271<xsl:template match="spanx[@style='verb' or @style='vbare']|tt">
1272  <fo:wrapper font-family="monospace">
1273    <xsl:call-template name="copy-anchor"/>
1274    <xsl:apply-templates/>
1275  </fo:wrapper>
1276</xsl:template>
1277
1278<xsl:template match="t">
1279  <fo:block space-before=".5em" space-after=".5em">
1280    <xsl:call-template name="insert-justification"/>
1281    <xsl:attribute name="start-indent">
1282      <xsl:choose>
1283        <xsl:when test="parent::x:blockquote|parent::blockquote">4em</xsl:when>
1284        <xsl:when test="parent::x:note|parent::aside">4em</xsl:when>
1285        <xsl:otherwise>2em</xsl:otherwise>
1286      </xsl:choose>
1287    </xsl:attribute>
1288    <xsl:call-template name="copy-anchor"/>
1289    <xsl:apply-templates />
1290  </fo:block>
1291</xsl:template>
1292               
1293<xsl:template match="vspace">
1294  <fo:block/>
1295</xsl:template>
1296
1297<xsl:template name="render-section-ref">
1298  <xsl:param name="from" />
1299  <xsl:param name="to" />
1300  <xsl:variable name="target" select="$from/@target" />
1301
1302  <xsl:variable name="refname">
1303    <xsl:for-each select="$to">
1304      <xsl:call-template name="get-section-type">
1305        <xsl:with-param name="prec" select="$from/preceding-sibling::node()[1]" />
1306      </xsl:call-template>
1307    </xsl:for-each>
1308  </xsl:variable>
1309  <xsl:variable name="refnum">
1310    <xsl:for-each select="$to">
1311      <xsl:call-template name="get-section-number" />
1312    </xsl:for-each>
1313  </xsl:variable>
1314  <xsl:choose>
1315    <xsl:when test="@format='counter'">
1316      <xsl:value-of select="$refnum"/>
1317    </xsl:when>
1318    <xsl:when test="@format='none'">
1319      <!-- Nothing to do -->
1320    </xsl:when>
1321    <xsl:when test="@format='title'">
1322      <xsl:choose>
1323        <xsl:when test="$to/name">
1324          <xsl:apply-templates select="$to/name/node()"/>
1325        </xsl:when>
1326        <xsl:otherwise>
1327          <xsl:value-of select="$to/@title"/>
1328        </xsl:otherwise>
1329      </xsl:choose>
1330    </xsl:when>
1331    <xsl:otherwise>
1332      <xsl:value-of select="normalize-space(concat($refname,'&#160;',$refnum))"/>
1333    </xsl:otherwise>
1334  </xsl:choose>
1335</xsl:template>
1336
1337<xsl:template match="xref[node()]">
1338
1339  <xsl:variable name="target" select="@target" />
1340  <xsl:variable name="node" select="//*[@anchor=$target]" />
1341  <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>
1342
1343  <xsl:variable name="sfmt">
1344    <xsl:call-template name="get-section-xref-format"/>
1345  </xsl:variable>
1346
1347  <xsl:choose>
1348    <xsl:when test="$sfmt='none'">
1349      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1350        <xsl:if test="$node/self::reference and $xml2rfc-ext-include-references-in-index='yes'">
1351          <xsl:attribute name="id">
1352            <xsl:value-of select="$anchor"/>
1353          </xsl:attribute>
1354          <xsl:attribute name="index-key">
1355            <xsl:value-of select="concat('xrefitem=',@target)"/>
1356          </xsl:attribute>
1357        </xsl:if>
1358        <!-- insert id when a backlink to this xref is needed in the index -->
1359        <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1360        <xsl:if test="$ireftargets">
1361          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1362        </xsl:if>
1363        <xsl:for-each select="$ireftargets">
1364          <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1365        </xsl:for-each>
1366        <xsl:apply-templates/>
1367      </fo:basic-link>
1368    </xsl:when>
1369   
1370    <xsl:when test="$node/self::section or $node/self::appendix">
1371      <xsl:choose>
1372        <xsl:when test="@format='none'">
1373          <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1374            <!-- insert id when a backlink to this xref is needed in the index -->
1375            <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1376            <xsl:if test="$ireftargets">
1377              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1378            </xsl:if>
1379            <xsl:for-each select="$ireftargets">
1380              <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1381            </xsl:for-each>
1382            <xsl:apply-templates/>
1383          </fo:basic-link>
1384        </xsl:when>
1385        <xsl:otherwise>
1386          <xsl:apply-templates/>
1387          <xsl:text> (</xsl:text>
1388          <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1389            <!-- insert id when a backlink to this xref is needed in the index -->
1390            <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1391            <xsl:if test="$ireftargets">
1392              <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1393            </xsl:if>
1394            <xsl:for-each select="$ireftargets">
1395              <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1396            </xsl:for-each>
1397            <xsl:call-template name="render-section-ref">
1398              <xsl:with-param name="from" select="."/>
1399              <xsl:with-param name="to" select="$node"/>
1400            </xsl:call-template>
1401          </fo:basic-link>
1402          <xsl:text>)</xsl:text>
1403        </xsl:otherwise>
1404      </xsl:choose>
1405    </xsl:when>
1406   
1407    <xsl:otherwise>
1408      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1409        <xsl:value-of select="." />
1410      </fo:basic-link>
1411      <xsl:if test="not(@format='none')">
1412        <xsl:for-each select="//reference[@anchor=$target]">
1413          &#160;<xsl:call-template name="reference-name"/>
1414        </xsl:for-each>
1415      </xsl:if>
1416    </xsl:otherwise>
1417  </xsl:choose>
1418
1419</xsl:template>
1420
1421<xsl:template match="xref[not(node())]">
1422
1423  <xsl:variable name="xref" select="."/>
1424  <xsl:variable name="target" select="@target"/>
1425  <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>
1426  <xsl:variable name="node" select="//*[@anchor=$target]" />
1427  <xsl:if test="count($node)=0 and not(ancestor::ed:del)">
1428    <xsl:message>Undefined target: <xsl:value-of select="@target" /></xsl:message>
1429    <span class="error">Undefined target: <xsl:value-of select="@target" /></span>
1430  </xsl:if>
1431
1432  <xsl:variable name="sfmt">
1433    <xsl:call-template name="get-section-xref-format">
1434      <xsl:with-param name="default">
1435        <xsl:choose>
1436          <xsl:when test="ancestor::artwork">comma</xsl:when>
1437          <xsl:otherwise>of</xsl:otherwise>
1438        </xsl:choose>
1439      </xsl:with-param>
1440    </xsl:call-template>
1441  </xsl:variable>
1442
1443  <xsl:variable name="ssec">
1444    <xsl:call-template name="get-section-xref-section"/>
1445  </xsl:variable>
1446
1447  <xsl:choose>
1448    <!-- Section links -->
1449    <xsl:when test="$node/self::section or $node/self::appendix">
1450      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1451        <!-- insert id when a backlink to this xref is needed in the index -->
1452        <xsl:variable name="ireftargets" select="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]"/>
1453        <xsl:if test="$ireftargets">
1454          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
1455        </xsl:if>
1456        <xsl:for-each select="$ireftargets">
1457          <fo:wrapper index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1458        </xsl:for-each>
1459        <xsl:call-template name="render-section-ref">
1460          <xsl:with-param name="from" select="."/>
1461          <xsl:with-param name="to" select="$node"/>
1462        </xsl:call-template>
1463      </fo:basic-link>
1464    </xsl:when>
1465
1466    <!-- Figure links -->
1467    <xsl:when test="$node//self::figure">
1468      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1469        <xsl:variable name="figcnt">
1470          <xsl:for-each select="$node">
1471            <xsl:call-template name="get-figure-number"/>
1472          </xsl:for-each>
1473        </xsl:variable>
1474        <xsl:choose>
1475          <xsl:when test="@format='counter'">
1476            <xsl:value-of select="$figcnt" />
1477          </xsl:when>
1478          <xsl:when test="@format='none'">
1479            <!-- Nothing to do -->
1480          </xsl:when>
1481          <xsl:when test="@format='title'">
1482            <xsl:value-of select="$node/@title" />
1483          </xsl:when>
1484          <xsl:otherwise>
1485            <xsl:value-of select="normalize-space(concat('Figure&#160;',$figcnt))"/>
1486          </xsl:otherwise>
1487        </xsl:choose>
1488      </fo:basic-link>
1489    </xsl:when>
1490
1491    <!-- Table links -->
1492    <xsl:when test="$node/self::texttable">
1493      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1494        <xsl:variable name="tabcnt">
1495          <xsl:for-each select="$node">
1496            <xsl:call-template name="get-table-number"/>
1497          </xsl:for-each>
1498        </xsl:variable>
1499        <xsl:choose>
1500          <xsl:when test="@format='counter'">
1501            <xsl:value-of select="$tabcnt" />
1502          </xsl:when>
1503          <xsl:when test="@format='none'">
1504            <!-- Nothing to do -->
1505          </xsl:when>
1506          <xsl:when test="@format='title'">
1507            <xsl:value-of select="$node/@title" />
1508          </xsl:when>
1509          <xsl:otherwise>
1510            <xsl:value-of select="normalize-space(concat('Table&#160;',$tabcnt))"/>
1511          </xsl:otherwise>
1512        </xsl:choose>
1513      </fo:basic-link>
1514    </xsl:when>
1515
1516    <!-- Paragraph links -->
1517    <xsl:when test="$node/self::t or $node/self::dt">
1518      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1519        <xsl:variable name="tcnt">
1520          <xsl:for-each select="$node">
1521            <xsl:call-template name="get-paragraph-number" />
1522          </xsl:for-each>
1523        </xsl:variable>
1524        <xsl:variable name="pparent" select="$node/.."/>
1525        <xsl:variable name="listtype">
1526          <xsl:choose>
1527            <xsl:when test="$pparent/self::list">
1528              <xsl:value-of select="$pparent/@style"/>
1529            </xsl:when>
1530            <xsl:when test="$pparent/self::dl">definition</xsl:when>
1531            <xsl:otherwise></xsl:otherwise>
1532          </xsl:choose>
1533        </xsl:variable>
1534        <xsl:variable name="listindex">
1535          <xsl:choose>
1536            <xsl:when test="$listtype='numbers'">
1537              <xsl:for-each select="$node">
1538                <xsl:number/>
1539              </xsl:for-each>
1540            </xsl:when>
1541            <xsl:when test="$listtype='letters'">
1542              <xsl:for-each select="$node">
1543                <xsl:number format="a"/>
1544              </xsl:for-each>
1545            </xsl:when>
1546            <xsl:otherwise/>
1547          </xsl:choose>
1548        </xsl:variable>
1549        <xsl:choose>
1550          <xsl:when test="@format='counter'">
1551            <xsl:choose>
1552              <xsl:when test="$listtype!='' and $listindex!=''">
1553                <xsl:value-of select="$listindex"/>
1554              </xsl:when>
1555              <xsl:when test="$listtype!='' and $listindex=''">
1556                <xsl:call-template name="warning">
1557                  <xsl:with-param name="msg" select="concat('Use of format=counter for unsupported list type ',$listtype)"/>
1558                </xsl:call-template>
1559                <xsl:value-of select="$tcnt"/>             
1560              </xsl:when>
1561              <xsl:otherwise>
1562                <xsl:value-of select="$tcnt"/>             
1563              </xsl:otherwise>
1564            </xsl:choose>
1565          </xsl:when>
1566          <xsl:when test="@format='none'">
1567            <!-- Nothing to do -->
1568          </xsl:when>
1569          <xsl:when test="@format='title'">
1570            <xsl:choose>
1571              <xsl:when test="$node/self::dt">
1572                <xsl:apply-templates select="$node/node()"/>
1573              </xsl:when>
1574              <xsl:when test="$node/@hangText">
1575                <xsl:value-of select="$node/@hangText"/>
1576              </xsl:when>
1577              <xsl:otherwise>
1578                <xsl:value-of select="$node/@title" />
1579              </xsl:otherwise>
1580            </xsl:choose>
1581          </xsl:when>
1582          <xsl:otherwise>
1583            <xsl:value-of select="normalize-space(concat('Paragraph&#160;',substring-after($tcnt,'p.')))"/>
1584          </xsl:otherwise>
1585        </xsl:choose>
1586      </fo:basic-link>
1587    </xsl:when>
1588
1589    <!-- Comment links -->
1590    <xsl:when test="$node/self::cref">
1591      <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1592        <xsl:variable name="name">
1593          <xsl:for-each select="$node">
1594            <xsl:call-template name="get-comment-name" />
1595          </xsl:for-each>
1596        </xsl:variable>
1597        <xsl:choose>
1598          <xsl:when test="@format='counter'">
1599            <xsl:value-of select="$name" />
1600          </xsl:when>
1601          <xsl:when test="@format='none'">
1602            <!-- Nothing to do -->
1603          </xsl:when>
1604          <xsl:when test="@format='title'">
1605            <xsl:value-of select="$node/@title" />
1606          </xsl:when>
1607          <xsl:otherwise>
1608            <xsl:value-of select="normalize-space(concat('Comment&#160;',$name))"/>
1609          </xsl:otherwise>
1610        </xsl:choose>
1611      </fo:basic-link>
1612    </xsl:when>
1613
1614    <!-- Reference links -->
1615    <xsl:when test="$node/self::reference">
1616      <!--
1617      Formats:
1618     
1619        ()      [XXXX] (Section SS)
1620        ,       [XXXX], Section SS
1621        of      Section SS of [XXXX]
1622        sec     Section SS
1623        number  SS
1624      -->
1625
1626      <xsl:variable name="sec">
1627        <xsl:choose>
1628          <xsl:when test="starts-with(@x:rel,'#') and $ssec='' and $node/x:source/@href">
1629            <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
1630            <xsl:for-each select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]">
1631              <xsl:call-template name="get-section-number"/>
1632            </xsl:for-each>
1633          </xsl:when>
1634          <xsl:otherwise>
1635            <xsl:value-of select="$ssec"/>
1636          </xsl:otherwise>
1637        </xsl:choose>
1638      </xsl:variable>
1639
1640      <xsl:if test="$sec!=''">
1641        <xsl:choose>
1642          <xsl:when test="$sfmt='of' or $sfmt='sec'">
1643            <xsl:text>Section </xsl:text>
1644            <xsl:value-of select="$sec"/>
1645            <xsl:if test="$sfmt='of'">
1646              <xsl:text> of </xsl:text>
1647            </xsl:if>
1648          </xsl:when>
1649          <xsl:when test="$sfmt='number'">
1650            <xsl:value-of select="$sec"/>
1651          </xsl:when>
1652          <xsl:otherwise/>
1653        </xsl:choose>
1654      </xsl:if>
1655     
1656      <!-- anchor for index -->
1657      <xsl:if test="$xml2rfc-ext-include-references-in-index='yes' and $sec!='' and ($sfmt='sec' or $sfmt='number')">
1658        <fo:wrapper>
1659          <xsl:attribute name="id">
1660            <xsl:value-of select="$anchor"/>
1661          </xsl:attribute>
1662          <xsl:attribute name="index-key">
1663            <xsl:value-of select="concat('xrefitem=',@target)"/>
1664          </xsl:attribute>
1665          <xsl:if test="$sec!=''">
1666            <fo:wrapper>
1667              <xsl:attribute name="index-key">
1668                <xsl:value-of select="concat('xrefitem=',@target,'#',$sec)"/>
1669              </xsl:attribute>
1670            </fo:wrapper>
1671          </xsl:if>
1672        </fo:wrapper>
1673      </xsl:if>
1674
1675      <xsl:if test="$sec='' or ($sfmt!='sec' and $sfmt!='number')">
1676        <xsl:choose>
1677          <xsl:when test="$xref/@format='none'">
1678            <!-- Nothing to do -->
1679          </xsl:when>
1680          <xsl:otherwise>
1681            <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
1682              <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1683                <xsl:attribute name="id">
1684                  <xsl:value-of select="$anchor"/>
1685                </xsl:attribute>
1686                <xsl:attribute name="index-key">
1687                  <xsl:value-of select="concat('xrefitem=',@target)"/>
1688                </xsl:attribute>
1689                <xsl:if test="$sec!=''">
1690                  <fo:wrapper>
1691                    <xsl:attribute name="index-key">
1692                      <xsl:value-of select="concat('xrefitem=',@target,'#',$sec)"/>
1693                    </xsl:attribute>
1694                  </fo:wrapper>
1695                </xsl:if>
1696              </xsl:if>
1697              <xsl:variable name="val">
1698                <xsl:call-template name="reference-name">
1699                  <xsl:with-param name="node" select="$node" />
1700                </xsl:call-template>
1701              </xsl:variable>
1702              <xsl:choose>
1703                <xsl:when test="$xref/@format='counter'">
1704                  <!-- remove brackets -->
1705                  <xsl:value-of select="substring($val,2,string-length($val)-2)"/>
1706                </xsl:when>
1707                <xsl:when test="$xref/@format='title'">
1708                  <xsl:value-of select="$node/front/title"/>
1709                </xsl:when>
1710                <xsl:otherwise>
1711                  <xsl:value-of select="$val"/>
1712                </xsl:otherwise>
1713              </xsl:choose>
1714            </fo:basic-link>
1715          </xsl:otherwise>
1716        </xsl:choose>
1717      </xsl:if>
1718
1719      <xsl:if test="$sec!=''">
1720        <xsl:choose>
1721          <xsl:when test="$sfmt='parens'">
1722            <xsl:text> (Section </xsl:text>
1723            <xsl:value-of select="$sec"/>
1724            <xsl:text>)</xsl:text>
1725          </xsl:when>
1726          <xsl:when test="$sfmt='comma'">
1727            <xsl:text>, Section </xsl:text>
1728            <xsl:value-of select="$sec"/>
1729          </xsl:when>
1730          <xsl:otherwise/>
1731        </xsl:choose>
1732      </xsl:if>
1733
1734    </xsl:when>
1735   
1736    <xsl:otherwise>
1737      <xsl:call-template name="error">
1738        <xsl:with-param name="msg" select="concat('xref to unknown element: ',name($node))"/>
1739      </xsl:call-template>
1740    </xsl:otherwise>
1741  </xsl:choose>
1742</xsl:template>
1743
1744<xsl:template match="/">
1745  <xsl:apply-templates />
1746</xsl:template>
1747
1748<xsl:template match="*">
1749  <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>
1750</xsl:template>
1751
1752<xsl:template name="emitheader">
1753  <xsl:param name="lc" />
1754  <xsl:param name="rc" />
1755
1756  <xsl:for-each select="$lc/myns:item | $rc/myns:item">
1757    <xsl:variable name="pos" select="position()" />
1758    <xsl:if test="$pos &lt; count($lc/myns:item) + 1 or $pos &lt; count($rc/myns:item) + 1">
1759      <fo:table-row>
1760        <fo:table-cell>
1761          <fo:block>
1762            <xsl:apply-templates select="$lc/myns:item[$pos]/node()" mode="simple-html" />
1763          </fo:block>
1764        </fo:table-cell>
1765        <fo:table-cell>
1766          <fo:block text-align="right">
1767            <xsl:apply-templates select="$rc/myns:item[$pos]/node()" mode="simple-html" />
1768          </fo:block>
1769        </fo:table-cell>
1770      </fo:table-row>
1771    </xsl:if>
1772  </xsl:for-each>
1773</xsl:template>
1774
1775
1776<xsl:template match="text()" mode="simple-html">
1777  <xsl:apply-templates select="." />
1778</xsl:template>
1779
1780<xsl:template match="a" mode="simple-html">
1781  <fo:basic-link external-destination="url('{@href}')" xsl:use-attribute-sets="external-link">
1782    <xsl:apply-templates />
1783  </fo:basic-link>
1784</xsl:template>
1785
1786
1787<!-- produce back section with author information -->
1788<xsl:template name="insertAuthors">
1789
1790  <xsl:variable name="sectionNumber">
1791    <xsl:call-template name="get-authors-section-number"/>
1792  </xsl:variable>
1793
1794  <xsl:if test="$sectionNumber!='suppress'">
1795    <fo:block id="{$anchor-prefix}.authors" xsl:use-attribute-sets="h1 newpage">
1796      <xsl:if test="$sectionNumber != ''">
1797        <xsl:call-template name="emit-section-number">
1798          <xsl:with-param name="no" select="$sectionNumber"/>
1799        </xsl:call-template>
1800        <xsl:text>&#0160;&#0160;</xsl:text>
1801      </xsl:if>
1802      <xsl:call-template name="get-authors-section-title"/>
1803    </fo:block>
1804   
1805    <xsl:apply-templates select="/rfc/front/author" />
1806  </xsl:if>
1807</xsl:template>
1808
1809
1810<!-- generate the index section -->
1811
1812<xsl:template name="insertIndex">
1813
1814  <fo:block xsl:use-attribute-sets="h1 newpage" id="{$anchor-prefix}.index">
1815    <xsl:text>Index</xsl:text>
1816  </fo:block>
1817
1818  <xsl:variable name="irefs" select="//iref[generate-id(.) = generate-id(key('index-first-letter',translate(substring(@item,1,1),$lcase,$ucase)))]"/>
1819  <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)))]"/>
1820
1821  <xsl:for-each select="$irefs | $xrefs">
1822    <xsl:sort select="translate(concat(@item,/rfc/back/displayreference[@target=current()/@anchor]/@to,@anchor),$lcase,$ucase)" />
1823    <xsl:variable name="letter" select="translate(substring(concat(@item,/rfc/back/displayreference[@target=current()/@anchor]/@to,@anchor),1,1),$lcase,$ucase)"/>
1824           
1825    <xsl:variable name="showit">
1826      <xsl:choose>
1827        <xsl:when test="$xml2rfc-ext-include-references-in-index!='yes'">
1828          <xsl:if test="$irefs[starts-with(translate(@item,$lcase,$ucase),$letter)]">
1829            <xsl:text>yes</xsl:text>
1830          </xsl:if>
1831        </xsl:when>
1832        <xsl:otherwise>
1833          <xsl:text>yes</xsl:text>
1834        </xsl:otherwise>
1835      </xsl:choose>
1836    </xsl:variable>
1837
1838    <xsl:if test="$showit='yes'">
1839      <fo:block space-before="1em" font-weight="bold">
1840        <xsl:value-of select="$letter" />
1841      </fo:block>
1842           
1843      <xsl:for-each select="key('index-first-letter',translate(substring(concat(@item,@anchor),1,1),$lcase,$ucase))">
1844 
1845      <xsl:sort select="translate(concat(@item,/rfc/back/displayreference[@target=current()/@anchor]/@to,@anchor),$lcase,$ucase)" />
1846     
1847        <xsl:choose>
1848          <xsl:when test="self::reference">
1849            <xsl:if test="$xml2rfc-ext-include-references-in-index='yes'">
1850           
1851              <xsl:variable name="entries" select="//xref[@target=current()/@anchor and not(ancestor::ed:del)]" />
1852             
1853              <xsl:if test="$entries">
1854                <fo:block start-indent="1em" hyphenate="true">
1855                  <xsl:variable name="val">
1856                    <xsl:call-template name="reference-name"/>
1857                  </xsl:variable>
1858                  <fo:wrapper font-style="italic"><xsl:value-of select="concat(substring($val,2,string-length($val)-2),' ')" /></fo:wrapper>
1859 
1860                  <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1861                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@anchor,',primary')}" font-weight="bold"/>
1862                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@anchor)}"/>
1863                  </fo:index-page-citation-list>
1864
1865                  <xsl:variable name="rs2" select="$entries[@x:sec|@section]"/>
1866
1867                  <xsl:if test="$rs2">
1868                    <xsl:for-each select="$rs2">
1869                      <xsl:sort select="substring-before(concat(@x:sec,@section,'.'),'.')" data-type="number"/>
1870                      <xsl:sort select="substring(concat(@x:sec,@section),2+string-length(substring-before(concat(@x:sec,@section),'.')))" data-type="number"/>
1871                      <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-sec',concat(@target,'..',@x:sec,@section)))">
1872                        <fo:block start-indent="2em" hyphenate="true">
1873                          <fo:wrapper font-style="italic">
1874                            <xsl:choose>
1875                              <xsl:when test="translate(substring(concat(@x:sec,@section),1,1),$ucase,'')=''">
1876                                <xsl:text>Appendix </xsl:text>
1877                              </xsl:when>
1878                              <xsl:otherwise>
1879                                <xsl:text>Section </xsl:text>
1880                              </xsl:otherwise>
1881                            </xsl:choose>
1882                            <xsl:value-of select="@x:sec|@section"/>
1883                            <xsl:text>&#160;</xsl:text>
1884                          </fo:wrapper>
1885                          <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1886                            <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@target,'#',@x:sec,@section)}"/>
1887                          </fo:index-page-citation-list>
1888                        </fo:block>
1889                      </xsl:if>
1890                    </xsl:for-each>
1891                  </xsl:if>
1892
1893                  <xsl:if test="current()/x:source/@href">
1894                    <xsl:variable name="rs3" select="$entries[not(@x:sec) and @x:rel]"/>
1895                    <xsl:if test="$rs3">
1896                      <xsl:variable name="doc" select="document(current()/x:source/@href)"/>
1897                      <xsl:for-each select="$rs3">
1898                        <xsl:sort select="count($doc//*[@anchor and following::*/@anchor=substring-after(current()/@x:rel,'#')])" order="ascending" data-type="number"/>
1899                        <xsl:if test="generate-id(.) = generate-id(key('index-xref-by-anchor',concat(@target,'..',@x:rel)))">
1900                          <fo:block start-indent="2em" hyphenate="true">
1901                            <xsl:variable name="sec">
1902                              <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
1903                                <xsl:call-template name="get-section-number"/>
1904                              </xsl:for-each>
1905                            </xsl:variable>
1906                            <fo:wrapper font-style="italic">
1907                              <xsl:choose>
1908                                <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
1909                                  <xsl:text>Appendix </xsl:text>
1910                                </xsl:when>
1911                                <xsl:otherwise>
1912                                  <xsl:text>Section </xsl:text>
1913                                </xsl:otherwise>
1914                              </xsl:choose>
1915                              <xsl:value-of select="$sec"/>
1916                              <xsl:text> </xsl:text>
1917                            </fo:wrapper>
1918                            <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1919                              <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('xrefitem=',@target,'#',$sec)}"/>
1920                            </fo:index-page-citation-list>
1921                          </fo:block>
1922                        </xsl:if>
1923                      </xsl:for-each>
1924                    </xsl:if>
1925                  </xsl:if>
1926
1927                </fo:block>
1928              </xsl:if>
1929
1930            </xsl:if>
1931          </xsl:when>
1932          <xsl:otherwise>
1933            <xsl:if test="generate-id(.) = generate-id(key('index-item',@item))">
1934           
1935              <xsl:variable name="item" select="@item"/>
1936              <xsl:variable name="in-artwork" select="count(//iref[@item=$item and @primary='true' and ancestor::artwork])!=0"/>
1937       
1938              <fo:block start-indent="1em" hyphenate="true">
1939                <xsl:choose>
1940                  <xsl:when test="$in-artwork">
1941                    <fo:wrapper font-family="monospace"><xsl:value-of select="concat(@item,' ')" /></fo:wrapper>
1942                  </xsl:when>
1943                  <xsl:otherwise>
1944                    <xsl:value-of select="concat(@item,' ')" />
1945                  </xsl:otherwise>
1946                </xsl:choose>
1947               
1948                <xsl:variable name="entries" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
1949                                       
1950                <xsl:if test="$entries">
1951                  <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1952                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem,',primary')}" font-weight="bold"/>
1953                    <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem)}"/>
1954                  </fo:index-page-citation-list>
1955                </xsl:if>
1956     
1957              </fo:block>
1958                   
1959              <xsl:for-each select="key('index-item',@item)[@subitem and @subitem!='']">
1960              <xsl:sort select="translate(@subitem,$lcase,$ucase)" />
1961           
1962                <xsl:if test="generate-id(.) = generate-id(key('index-item-subitem',concat(@item,'..',@subitem)))">
1963               
1964                  <xsl:variable name="itemsubitem" select="concat(@item,'..',@subitem)"/>
1965                  <xsl:variable name="in-artwork2" select="count(//iref[concat(@item,'..',@subitem)=$itemsubitem and @primary='true' and ancestor::artwork])!=0"/>
1966                             
1967                  <fo:block start-indent="2em" hyphenate="true">
1968                 
1969                    <xsl:choose>
1970                      <xsl:when test="$in-artwork2">
1971                        <fo:wrapper font-family="monospace"><xsl:value-of select="concat(@subitem,' ')" /></fo:wrapper>
1972                      </xsl:when>
1973                      <xsl:otherwise>
1974                        <xsl:value-of select="concat(@subitem,' ')" />
1975                      </xsl:otherwise>
1976                    </xsl:choose>
1977     
1978                    <xsl:variable name="entries2" select="key('index-item-subitem',concat(@item,'..',@subitem))" />
1979                   
1980                    <xsl:if test="$entries2">
1981                      <fo:index-page-citation-list merge-sequential-page-numbers="merge">
1982                        <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem,',primary')}" font-weight="bold"/>
1983                        <fo:index-key-reference page-number-treatment="link" ref-index-key="{concat('item=',@item,',subitem=',@subitem)}" />
1984                      </fo:index-page-citation-list>
1985                    </xsl:if>
1986     
1987                  </fo:block>
1988                </xsl:if>
1989              </xsl:for-each>
1990                     
1991            </xsl:if>
1992          </xsl:otherwise>
1993        </xsl:choose>
1994   
1995                 
1996      </xsl:for-each>           
1997    </xsl:if>
1998  </xsl:for-each>
1999</xsl:template>
2000
2001
2002
2003<xsl:template match="/" mode="toc">
2004  <fo:block xsl:use-attribute-sets="h1 newpage" id="{concat($anchor-prefix,'.toc')}">
2005    <xsl:text>Table of Contents</xsl:text>
2006  </fo:block>
2007
2008  <xsl:apply-templates mode="toc" />
2009</xsl:template>
2010
2011<xsl:template name="back-toc">
2012
2013  <xsl:apply-templates select="references" mode="toc" />
2014
2015  <xsl:if test="$xml2rfc-ext-authors-section='before-appendices'">
2016    <xsl:apply-templates select="/rfc/front" mode="toc" />
2017  </xsl:if>
2018
2019  <xsl:apply-templates select="back/*[not(self::references)]" mode="toc" />
2020
2021  <!-- insert the index if index entries exist -->
2022  <xsl:if test="$has-index">
2023    <xsl:call-template name="insert-toc-line">
2024      <xsl:with-param name="target" select="concat($anchor-prefix,'.index')"/>
2025      <xsl:with-param name="title" select="'Index'"/>
2026    </xsl:call-template>
2027  </xsl:if>
2028
2029  <xsl:if test="$xml2rfc-ext-authors-section='end'">
2030    <xsl:apply-templates select="/rfc/front" mode="toc" />
2031  </xsl:if>
2032
2033  <!-- copyright statements -->
2034  <xsl:if test="$xml2rfc-private='' and not($no-copylong)">
2035    <xsl:call-template name="insert-toc-line">
2036      <xsl:with-param name="target" select="concat($anchor-prefix,'.ipr')"/>
2037      <xsl:with-param name="title" select="'Intellectual Property and Copyright Statements'"/>
2038    </xsl:call-template>
2039  </xsl:if>
2040 
2041</xsl:template>
2042
2043<xsl:template match="front" mode="toc">
2044 
2045  <xsl:variable name="authors-title">
2046    <xsl:call-template name="get-authors-section-title"/>
2047  </xsl:variable>
2048  <xsl:variable name="authors-number">
2049    <xsl:call-template name="get-authors-section-number"/>
2050  </xsl:variable>
2051  <xsl:if test="$authors-number!='suppress'">
2052    <xsl:call-template name="insert-toc-line">
2053      <xsl:with-param name="target" select="concat($anchor-prefix,'.authors')"/>
2054      <xsl:with-param name="title" select="$authors-title"/>
2055      <xsl:with-param name="number" select="$authors-number"/>
2056    </xsl:call-template>
2057  </xsl:if>
2058
2059</xsl:template>
2060
2061<xsl:template name="references-toc">
2062
2063  <!-- distinguish two cases: (a) single references element (process
2064  as toplevel section; (b) multiple references sections (add one toplevel
2065  container with subsection) -->
2066
2067  <xsl:choose>
2068    <xsl:when test="count(/*/back/references) = 0">
2069      <!-- nop -->
2070    </xsl:when>
2071    <xsl:when test="count(/*/back/references) = 1">
2072      <xsl:for-each select="/*/back/references">
2073        <xsl:variable name="title">
2074          <xsl:choose>
2075            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2076            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2077          </xsl:choose>
2078        </xsl:variable>
2079     
2080        <xsl:call-template name="insert-toc-line">
2081          <xsl:with-param name="number">
2082            <xsl:call-template name="get-references-section-number"/>
2083          </xsl:with-param>
2084          <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
2085          <xsl:with-param name="title" select="$title"/>
2086          <xsl:with-param name="name" select="name"/>
2087        </xsl:call-template>
2088      </xsl:for-each>
2089    </xsl:when>
2090    <xsl:otherwise>
2091      <!-- insert pseudo container -->   
2092      <xsl:call-template name="insert-toc-line">
2093        <xsl:with-param name="number">
2094          <xsl:call-template name="get-references-section-number"/>
2095        </xsl:with-param>
2096        <xsl:with-param name="target" select="concat($anchor-prefix,'.references')"/>
2097        <xsl:with-param name="title" select="$xml2rfc-refparent"/>
2098      </xsl:call-template>
2099 
2100      <!-- ...with subsections... -->   
2101      <xsl:for-each select="/*/back/references">
2102        <xsl:variable name="title">
2103          <xsl:choose>
2104            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2105            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2106          </xsl:choose>
2107        </xsl:variable>
2108     
2109        <xsl:variable name="sectionNumber">
2110          <xsl:call-template name="get-section-number" />
2111        </xsl:variable>
2112
2113        <xsl:variable name="num">
2114          <xsl:number/>
2115        </xsl:variable>
2116
2117        <xsl:call-template name="insert-toc-line">
2118          <xsl:with-param name="number" select="$sectionNumber"/>
2119          <xsl:with-param name="target" select="concat($anchor-prefix,'.references','.',$num)"/>
2120          <xsl:with-param name="title" select="$title"/>
2121          <xsl:with-param name="name" select="name"/>
2122        </xsl:call-template>
2123      </xsl:for-each>
2124    </xsl:otherwise>
2125  </xsl:choose>
2126</xsl:template>
2127
2128<xsl:template match="section" mode="toc">
2129  <xsl:variable name="sectionNumber">
2130    <xsl:call-template name="get-section-number" />
2131  </xsl:variable>
2132
2133  <xsl:variable name="target">
2134    <xsl:choose>
2135      <xsl:when test="@anchor"><xsl:value-of select="@anchor" /></xsl:when>
2136       <xsl:otherwise><xsl:value-of select="$anchor-prefix"/>.section.<xsl:value-of select="$sectionNumber" /></xsl:otherwise>
2137    </xsl:choose>
2138  </xsl:variable>
2139
2140  <xsl:call-template name="insert-toc-line">
2141    <xsl:with-param name="number" select="$sectionNumber"/>
2142    <xsl:with-param name="target" select="$target"/>
2143    <xsl:with-param name="title" select="@title"/>
2144    <xsl:with-param name="name" select="name"/>
2145    <xsl:with-param name="tocparam" select="@toc"/>
2146  </xsl:call-template>
2147 
2148  <xsl:if test=".//section">
2149    <xsl:apply-templates mode="toc" />
2150  </xsl:if>
2151</xsl:template>
2152
2153<xsl:template name="insert-toc-line">
2154  <xsl:param name="number" />
2155  <xsl:param name="target" />
2156  <xsl:param name="title" />
2157  <xsl:param name="name" />
2158  <xsl:param name="tocparam" />
2159 
2160  <xsl:variable name="depth">
2161    <!-- count the dots -->
2162    <xsl:value-of select="string-length(translate($number,'.ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890&#167;','.'))"/>
2163  </xsl:variable>
2164 
2165  <!-- handle tocdepth parameter -->
2166  <xsl:choose>
2167    <xsl:when test="(not($tocparam) or $tocparam='' or $tocparam='default') and $depth >= $parsedTocDepth">
2168      <!-- dropped entry because of depth-->
2169    </xsl:when>
2170    <xsl:when test="$tocparam='exclude'">
2171      <!-- dropped entry because excluded -->
2172    </xsl:when>
2173    <xsl:when test="$depth = 0">
2174      <fo:block space-before="1em" font-weight="bold" text-align-last="justify">
2175        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
2176          <xsl:value-of select="$number" />
2177          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2178          <xsl:text>&#0160;&#0160;</xsl:text>
2179        </xsl:if>
2180        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
2181          <xsl:choose>
2182            <xsl:when test="$name">
2183              <xsl:apply-templates select="$name/node()"/>
2184            </xsl:when>
2185            <xsl:otherwise>
2186              <xsl:value-of select="$title"/>
2187            </xsl:otherwise>
2188          </xsl:choose>
2189        </fo:basic-link>
2190        <fo:leader leader-pattern="dots"/>
2191        <fo:page-number-citation ref-id="{$target}"/>
2192      </fo:block>
2193    </xsl:when>
2194    <xsl:when test="$depth = 1">
2195      <fo:block space-before="0.5em" text-align-last="justify">
2196        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
2197          <xsl:value-of select="$number" />
2198          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2199          <xsl:text>&#0160;&#0160;&#0160;&#0160;</xsl:text>
2200        </xsl:if>
2201        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
2202          <xsl:choose>
2203            <xsl:when test="$name">
2204              <xsl:apply-templates select="$name/node()"/>
2205            </xsl:when>
2206            <xsl:otherwise>
2207              <xsl:value-of select="$title"/>
2208            </xsl:otherwise>
2209          </xsl:choose>
2210        </fo:basic-link>
2211        <fo:leader leader-pattern="dots"/>
2212        <fo:page-number-citation ref-id="{$target}"/>
2213      </fo:block>
2214    </xsl:when>
2215    <xsl:otherwise>
2216      <fo:block text-align-last="justify">
2217        <xsl:text>&#0160;&#0160;</xsl:text>
2218        <xsl:if test="$number!='' and not(contains($number,'unnumbered-'))">
2219          <xsl:value-of select="$number" />
2220          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2221          <xsl:text>&#0160;&#0160;&#0160;&#0160;</xsl:text>
2222        </xsl:if>
2223        <fo:basic-link internal-destination="{$target}" xsl:use-attribute-sets="internal-link">
2224          <xsl:choose>
2225            <xsl:when test="$name">
2226              <xsl:apply-templates select="$name/node()"/>
2227            </xsl:when>
2228            <xsl:otherwise>
2229              <xsl:value-of select="$title"/>
2230            </xsl:otherwise>
2231          </xsl:choose>
2232        </fo:basic-link>
2233        <fo:leader leader-pattern="dots"/>
2234        <fo:page-number-citation ref-id="{$target}"/>
2235      </fo:block>
2236    </xsl:otherwise>
2237  </xsl:choose>
2238
2239</xsl:template>
2240
2241
2242<!--
2243<xsl:template name="rfclist">
2244  <xsl:param name="list" />
2245  <xsl:choose>
2246      <xsl:when test="contains($list,',')">
2247          <xsl:variable name="rfcNo" select="substring-before($list,',')" />
2248          <a href="{concat($rfcUrlPrefix,$rfcNo,'.txt')}"><xsl:value-of select="$rfcNo" /></a>,
2249          <xsl:call-template name="rfclist">
2250              <xsl:with-param name="list" select="normalize-space(substring-after($list,','))" />
2251            </xsl:call-template>
2252        </xsl:when>
2253        <xsl:otherwise>
2254          <xsl:variable name="rfcNo" select="$list" />
2255          <a href="{concat($rfcUrlPrefix,$rfcNo,'.txt')}"><xsl:value-of select="$rfcNo" /></a>
2256         </xsl:otherwise>
2257    </xsl:choose>
2258</xsl:template>
2259-->
2260
2261<xsl:template name="insertHeader">
2262  <xsl:variable name="left">
2263    <xsl:call-template name="get-header-left" />
2264  </xsl:variable>
2265  <xsl:variable name="center">
2266    <xsl:call-template name="get-header-center" />
2267  </xsl:variable>
2268  <xsl:variable name="right">
2269    <xsl:call-template name="get-header-right" />
2270  </xsl:variable>
2271
2272  <fo:static-content flow-name="header-right">
2273    <fo:block space-after=".5cm" />
2274    <fo:table width="100%" text-align="center" table-layout="fixed">
2275      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2276      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2277      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2278      <fo:table-body>
2279        <fo:table-row>
2280          <fo:table-cell>
2281            <fo:block text-align="start">
2282              <xsl:value-of select="$left" />
2283             </fo:block>
2284          </fo:table-cell>
2285          <fo:table-cell text-align="center">
2286            <fo:block>
2287              <xsl:value-of select="$center" />
2288             </fo:block>
2289          </fo:table-cell>
2290          <fo:table-cell text-align="end">
2291            <fo:block>
2292              <xsl:value-of select="$right" />
2293             </fo:block>
2294          </fo:table-cell>
2295        </fo:table-row>
2296      </fo:table-body>
2297    </fo:table>
2298  </fo:static-content>
2299
2300  <fo:static-content flow-name="header-left">
2301    <fo:block space-after=".5cm" />
2302    <fo:table width="100%" text-align="center" table-layout="fixed">
2303      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2304      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2305      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2306      <fo:table-body>
2307        <fo:table-row>
2308          <fo:table-cell text-align="start">
2309            <fo:block>
2310              <xsl:value-of select="$right" />
2311             </fo:block>
2312          </fo:table-cell>
2313          <fo:table-cell text-align="center">
2314            <fo:block>
2315              <xsl:value-of select="$center" />
2316             </fo:block>
2317          </fo:table-cell>
2318          <fo:table-cell>
2319            <fo:block text-align="end">
2320              <xsl:value-of select="$left" />
2321             </fo:block>
2322          </fo:table-cell>
2323        </fo:table-row>
2324      </fo:table-body>
2325    </fo:table>
2326  </fo:static-content>
2327
2328</xsl:template>
2329
2330<xsl:template name="insertFooter">
2331  <xsl:variable name="left">
2332    <xsl:call-template name="get-author-summary" />
2333  </xsl:variable>
2334  <xsl:variable name="center">
2335    <xsl:call-template name="get-bottom-center" />
2336  </xsl:variable>
2337  <xsl:variable name="right">[Page 999]</xsl:variable>
2338
2339  <fo:static-content flow-name="footer-right">
2340    <fo:table text-align="center" width="100%" table-layout="fixed">
2341      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2342      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2343      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2344      <fo:table-body>
2345        <fo:table-row>
2346          <fo:table-cell>
2347            <fo:block text-align="start">
2348              <xsl:value-of select="$left" />
2349             </fo:block>
2350          </fo:table-cell>
2351          <fo:table-cell>
2352            <fo:block text-align="center">
2353              <xsl:value-of select="$center" />
2354             </fo:block>
2355          </fo:table-cell>
2356          <fo:table-cell>
2357            <fo:block text-align="end">[Page <fo:page-number />]</fo:block>
2358          </fo:table-cell>
2359        </fo:table-row>
2360      </fo:table-body>
2361    </fo:table>
2362  </fo:static-content>
2363
2364  <fo:static-content flow-name="footer-left">
2365    <fo:table text-align="center" width="100%" table-layout="fixed">
2366      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2367      <fo:table-column column-width="proportional-column-width({string-length($center)})" />
2368      <fo:table-column column-width="proportional-column-width({(string-length($left)+string-length($right)) div 2})" />
2369      <fo:table-body>
2370        <fo:table-row>
2371          <fo:table-cell>
2372            <fo:block text-align="start">[Page <fo:page-number />]</fo:block>
2373          </fo:table-cell>
2374          <fo:table-cell>
2375            <fo:block text-align="center">
2376              <xsl:value-of select="$center" />
2377             </fo:block>
2378          </fo:table-cell>
2379          <fo:table-cell>
2380            <fo:block text-align="end">
2381              <xsl:value-of select="$left" />
2382             </fo:block>
2383          </fo:table-cell>
2384        </fo:table-row>
2385      </fo:table-body>
2386    </fo:table>
2387  </fo:static-content>
2388
2389</xsl:template>
2390
2391<!-- change tracking -->
2392
2393<xsl:template match="ed:annotation" />
2394<xsl:template match="ed:del" />
2395<xsl:template match="ed:issue" />
2396<xsl:template match="ed:ins">
2397  <xsl:apply-templates />
2398</xsl:template>
2399<xsl:template match="ed:issueref">
2400  <xsl:apply-templates />
2401</xsl:template>
2402
2403<xsl:template match="ed:replace">
2404  <!--<xsl:variable name="no">change<xsl:number level="any"/></xsl:variable>
2405  <fo:change-bar-begin change-bar-class="{$no}" change-bar-style="solid" change-bar-color="red" change-bar-offset="2mm"/>-->
2406  <xsl:apply-templates />
2407  <!--<fo:change-bar-end change-bar-class="{$no}"/>-->
2408</xsl:template>
2409
2410<!-- extensions -->
2411
2412<xsl:template match="ed:link" />
2413
2414<xsl:template match="x:feedback" />
2415
2416<xsl:template match="node()" mode="bookmarks">
2417  <xsl:apply-templates mode="bookmarks"/>
2418</xsl:template>
2419
2420<xsl:template match="abstract" mode="bookmarks">
2421  <fo:bookmark internal-destination="{concat($anchor-prefix,'.abstract')}">
2422    <fo:bookmark-title>Abstract</fo:bookmark-title>
2423    <xsl:apply-templates mode="bookmarks"/>
2424  </fo:bookmark>
2425</xsl:template>
2426
2427<xsl:template match="note" mode="bookmarks">
2428  <xsl:variable name="num">
2429    <xsl:number count="note" />
2430  </xsl:variable>
2431  <fo:bookmark internal-destination="{concat($anchor-prefix,'.note.',$num)}">
2432    <fo:bookmark-title><xsl:value-of select="@title"/></fo:bookmark-title>
2433    <xsl:apply-templates mode="bookmarks"/>
2434  </fo:bookmark>
2435</xsl:template>
2436
2437<xsl:template match="section[not(@myns:unnumbered)]" mode="bookmarks">
2438  <xsl:variable name="sectionNumber"><xsl:call-template name="get-section-number" /></xsl:variable>
2439  <fo:bookmark internal-destination="{$anchor-prefix}.section.{$sectionNumber}">
2440    <fo:bookmark-title>
2441      <xsl:if test="$sectionNumber!='' and not(contains($sectionNumber,'unnumbered-'))">
2442        <xsl:value-of select="$sectionNumber"/>
2443        <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2444        <xsl:text> </xsl:text>
2445      </xsl:if>
2446      <xsl:choose>
2447        <xsl:when test="name">
2448          <xsl:variable name="hold">
2449            <xsl:apply-templates select="name/node()"/>
2450          </xsl:variable>
2451          <xsl:value-of select="normalize-space($hold)"/>
2452        </xsl:when>
2453        <xsl:otherwise>
2454          <xsl:value-of select="@title"/>
2455        </xsl:otherwise>
2456      </xsl:choose>
2457    </fo:bookmark-title>
2458    <xsl:apply-templates mode="bookmarks"/>
2459  </fo:bookmark>
2460</xsl:template>
2461
2462<xsl:template match="section[@myns:unnumbered]" mode="bookmarks">
2463  <fo:bookmark internal-destination="{@anchor}">
2464    <fo:bookmark-title><xsl:value-of select="@title"/></fo:bookmark-title>
2465    <xsl:apply-templates mode="bookmarks"/>
2466  </fo:bookmark>
2467</xsl:template>
2468
2469<xsl:template match="back" mode="bookmarks">
2470
2471  <xsl:call-template name="references-bookmarks" />
2472
2473  <xsl:if test="$xml2rfc-ext-authors-section='before-appendices'">
2474    <xsl:apply-templates select="/rfc/front" mode="bookmarks" />
2475  </xsl:if>
2476 
2477  <xsl:apply-templates select="*[not(self::references)]" mode="bookmarks" />
2478
2479  <!-- insert the index if index entries exist -->
2480  <xsl:if test="$has-index">
2481    <fo:bookmark internal-destination="{concat($anchor-prefix,'.index')}">
2482      <fo:bookmark-title>Index</fo:bookmark-title>
2483    </fo:bookmark>
2484  </xsl:if>
2485
2486  <xsl:if test="$xml2rfc-ext-authors-section='end'">
2487    <xsl:apply-templates select="/rfc/front" mode="bookmarks" />
2488  </xsl:if>
2489
2490  <xsl:if test="$xml2rfc-private='' and not($no-copylong)">
2491    <!-- copyright statements -->
2492    <fo:bookmark internal-destination="{concat($anchor-prefix,'.ipr')}">
2493      <fo:bookmark-title>Intellectual Property and Copyright Statements</fo:bookmark-title>
2494    </fo:bookmark>
2495  </xsl:if>
2496 
2497</xsl:template>
2498
2499<xsl:template match="front" mode="bookmarks">
2500
2501  <xsl:variable name="authors-number">
2502    <xsl:call-template name="get-authors-section-number"/>
2503  </xsl:variable>
2504
2505  <xsl:variable name="title">
2506    <xsl:if test="$authors-number!=''">
2507      <xsl:value-of select="$authors-number"/>
2508      <xsl:text> </xsl:text>
2509    </xsl:if>
2510    <xsl:call-template name="get-authors-section-title"/>
2511  </xsl:variable>
2512
2513  <xsl:if test="$authors-number!='suppress'">
2514    <fo:bookmark internal-destination="{concat($anchor-prefix,'.authors')}">
2515      <fo:bookmark-title><xsl:value-of select="$title"/></fo:bookmark-title>
2516    </fo:bookmark>
2517  </xsl:if>
2518</xsl:template>
2519
2520<xsl:template match="middle" mode="bookmarks">
2521  <xsl:apply-templates mode="bookmarks" />
2522</xsl:template>
2523
2524<xsl:template name="references-bookmarks">
2525
2526  <!-- distinguish two cases: (a) single references element (process
2527  as toplevel section; (b) multiple references sections (add one toplevel
2528  container with subsection) -->
2529
2530  <xsl:choose>
2531    <xsl:when test="count(/*/back/references) = 0">
2532      <!-- nothing to do -->
2533    </xsl:when>
2534    <xsl:when test="count(/*/back/references) = 1">
2535      <xsl:for-each select="/*/back/references">
2536        <xsl:variable name="title">
2537          <xsl:choose>
2538            <xsl:when test="name"><xsl:apply-templates select="name/node()"/></xsl:when>
2539            <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2540            <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2541          </xsl:choose>
2542        </xsl:variable>
2543     
2544        <fo:bookmark internal-destination="{$anchor-prefix}.references">
2545          <fo:bookmark-title>
2546            <xsl:call-template name="get-references-section-number"/>
2547            <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2548            <xsl:text> </xsl:text>
2549            <xsl:value-of select="normalize-space($title)"/>
2550          </fo:bookmark-title>
2551        </fo:bookmark>
2552      </xsl:for-each>
2553    </xsl:when>
2554    <xsl:otherwise>
2555      <!-- insert pseudo container -->   
2556      <fo:bookmark internal-destination="{$anchor-prefix}.references">
2557        <fo:bookmark-title>
2558          <xsl:call-template name="get-references-section-number"/>
2559          <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2560          <xsl:text> </xsl:text>
2561          <xsl:value-of select="$xml2rfc-refparent"/>
2562        </fo:bookmark-title>
2563
2564        <!-- ...with subsections... -->   
2565        <xsl:for-each select="/*/back/references">
2566          <xsl:variable name="title">
2567            <xsl:choose>
2568              <xsl:when test="name"><xsl:apply-templates select="name/node()"/></xsl:when>
2569              <xsl:when test="@title!=''"><xsl:value-of select="@title" /></xsl:when>
2570              <xsl:otherwise><xsl:value-of select="$xml2rfc-refparent"/></xsl:otherwise>
2571            </xsl:choose>
2572          </xsl:variable>
2573       
2574          <xsl:variable name="sectionNumber">
2575            <xsl:call-template name="get-section-number" />
2576            <xsl:if test="$xml2rfc-ext-sec-no-trailing-dots='yes'">.</xsl:if>
2577          </xsl:variable>
2578 
2579          <xsl:variable name="num">
2580            <xsl:number/>
2581          </xsl:variable>
2582 
2583          <fo:bookmark internal-destination="{$anchor-prefix}.references.{$num}">
2584            <fo:bookmark-title><xsl:value-of select="concat($sectionNumber,' ',normalize-space($title))"/></fo:bookmark-title>
2585          </fo:bookmark>
2586        </xsl:for-each>
2587      </fo:bookmark>
2588
2589    </xsl:otherwise>
2590  </xsl:choose>
2591</xsl:template>
2592
2593<xsl:template match="rfc" mode="bookmarks">
2594  <xsl:if test="$xml2rfc-private='' and not($abstract-first)">
2595    <xsl:call-template name="emit-ietf-preamble-bookmarks"/>   
2596  </xsl:if>
2597 
2598  <xsl:apply-templates select="front/abstract" mode="bookmarks"/>
2599  <xsl:apply-templates select="front/note[@title!='IESG Note' or $xml2rfc-private!='']" mode="bookmarks"/>
2600
2601  <xsl:if test="$xml2rfc-private='' and $abstract-first">
2602    <xsl:call-template name="emit-ietf-preamble-bookmarks"/>   
2603  </xsl:if>
2604
2605  <xsl:if test="$xml2rfc-toc='yes'">
2606    <fo:bookmark internal-destination="{concat($anchor-prefix,'.toc')}">
2607      <fo:bookmark-title>Table of Contents</fo:bookmark-title>
2608    </fo:bookmark>
2609  </xsl:if>
2610 
2611  <xsl:apply-templates select="middle|back" mode="bookmarks"/>
2612</xsl:template>
2613
2614<xsl:template name="emit-ietf-preamble-bookmarks">
2615  <!-- Get status info formatted as per RFC2629-->
2616  <xsl:variable name="preamble"><xsl:call-template name="insertPreamble" /></xsl:variable>
2617 
2618  <!-- emit it -->
2619  <xsl:choose>
2620    <xsl:when test="function-available('exslt:node-set')">
2621      <xsl:apply-templates select="exslt:node-set($preamble)/node()" mode="bookmarks"/>
2622    </xsl:when>
2623    <xsl:otherwise>
2624      <xsl:variable name="temp" select="$preamble"/>
2625      <xsl:apply-templates select="$temp/node()" mode="bookmarks"/>
2626    </xsl:otherwise>
2627  </xsl:choose>
2628</xsl:template>
2629
2630<!-- experimental table formatting -->
2631
2632<xsl:template name="sum-widths">
2633  <xsl:param name="list"/>
2634  <xsl:choose>
2635    <xsl:when test="count($list)=0">
2636      <xsl:value-of select="0"/>
2637    </xsl:when>
2638    <xsl:when test="count($list)=1">
2639      <xsl:value-of select="number(substring-before($list[1],'%'))"/>
2640    </xsl:when>
2641    <xsl:otherwise>
2642      <xsl:variable name="remainder">
2643        <xsl:call-template name="sum-widths">
2644          <xsl:with-param name="list" select="$list[position()>1]" />
2645        </xsl:call-template>
2646      </xsl:variable>
2647      <xsl:value-of select="$remainder + number(substring-before($list[1],'%'))" />
2648    </xsl:otherwise>
2649  </xsl:choose>
2650</xsl:template>
2651
2652<!--
2653<xsl:attribute-set name="all-borders-solid">
2654  <xsl:attribute name="border-left-style">solid</xsl:attribute>
2655  <xsl:attribute name="border-right-style">solid</xsl:attribute>
2656  <xsl:attribute name="border-top-style">solid</xsl:attribute>
2657  <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2658  <xsl:attribute name="border-left-width">thin</xsl:attribute>
2659  <xsl:attribute name="border-right-width">thin</xsl:attribute>
2660  <xsl:attribute name="border-top-width">thin</xsl:attribute>
2661  <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2662  <xsl:attribute name="padding-left">0.5em</xsl:attribute>
2663  <xsl:attribute name="padding-right">0.5em</xsl:attribute>
2664</xsl:attribute-set>
2665
2666-->
2667
2668<xsl:template match="texttable">
2669
2670  <xsl:variable name="style">
2671    <xsl:choose>
2672      <xsl:when test="@style!=''">
2673        <xsl:value-of select="@style"/>
2674      </xsl:when>
2675      <xsl:otherwise>full</xsl:otherwise>
2676    </xsl:choose>
2677  </xsl:variable>
2678
2679  <xsl:variable name="anch">
2680    <xsl:call-template name="get-table-anchor"/>
2681  </xsl:variable>
2682
2683  <fo:block space-before=".5em" space-after=".5em" start-indent="2em" id="{$anch}">
2684    <xsl:call-template name="add-anchor"/>
2685    <xsl:apply-templates select="preamble" />
2686    <fo:table>
2687      <xsl:variable name="total-specified">
2688        <xsl:call-template name="sum-widths">
2689          <xsl:with-param name="list" select="ttcol/@width" />
2690        </xsl:call-template>
2691      </xsl:variable>
2692      <xsl:for-each select="ttcol">
2693        <fo:table-column>
2694          <xsl:choose>
2695            <xsl:when test="@width">
2696              <xsl:attribute name="column-width">proportional-column-width(<xsl:value-of select="substring-before(@width,'%')" />)</xsl:attribute>
2697            </xsl:when>
2698            <xsl:otherwise>
2699              <xsl:attribute name="column-width">proportional-column-width(<xsl:value-of select="(100 - number($total-specified)) div count(../ttcol[not(@width)])" />)</xsl:attribute>
2700            </xsl:otherwise>
2701          </xsl:choose>
2702        </fo:table-column>
2703      </xsl:for-each>
2704      <xsl:if test="ttcol!=''">
2705        <!-- skip header when all column titles are empty -->
2706        <fo:table-header start-indent="0em" space-after=".5em">
2707          <fo:table-row>
2708            <xsl:apply-templates select="ttcol" />
2709          </fo:table-row>
2710        </fo:table-header>
2711      </xsl:if>
2712      <fo:table-body start-indent="0em">
2713        <xsl:if test="$style='all' or $style='full'">
2714          <xsl:attribute name="border-left-style">solid</xsl:attribute>
2715          <xsl:attribute name="border-right-style">solid</xsl:attribute>
2716          <xsl:attribute name="border-top-style">solid</xsl:attribute>
2717          <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2718          <xsl:attribute name="border-left-width">thin</xsl:attribute>
2719          <xsl:attribute name="border-right-width">thin</xsl:attribute>
2720          <xsl:attribute name="border-top-width">thin</xsl:attribute>
2721          <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2722        </xsl:if>
2723        <xsl:variable name="columns" select="count(ttcol)" />
2724        <xsl:choose>
2725          <xsl:when test="not(c)">
2726            <!-- special case: empty body -->
2727            <fo:table-cell><fo:block/></fo:table-cell>
2728          </xsl:when>
2729          <xsl:otherwise>
2730            <xsl:for-each select="c[$columns=1 or (position() mod $columns) = 1]">
2731              <fo:table-row>
2732                <xsl:for-each select=". | following-sibling::c[position() &lt; $columns]">
2733                  <fo:table-cell padding-left="0.5em" padding-right="0.5em">
2734                    <xsl:if test="$style='all' or $style='full'">
2735                      <xsl:attribute name="border-left-style">solid</xsl:attribute>
2736                      <xsl:attribute name="border-right-style">solid</xsl:attribute>
2737                      <xsl:attribute name="border-left-width">thin</xsl:attribute>
2738                      <xsl:attribute name="border-right-width">thin</xsl:attribute>
2739                    </xsl:if>
2740                    <xsl:if test="$style='all'">
2741                      <xsl:attribute name="border-top-style">solid</xsl:attribute>
2742                      <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2743                      <xsl:attribute name="border-top-width">thin</xsl:attribute>
2744                      <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2745                    </xsl:if>
2746                    <fo:block>
2747                      <xsl:variable name="pos" select="position()" />
2748                      <xsl:variable name="col" select="../ttcol[position() = $pos]" />
2749                      <xsl:if test="$col/@align">
2750                        <xsl:attribute name="text-align"><xsl:value-of select="$col/@align" /></xsl:attribute>
2751                      </xsl:if>
2752                      <xsl:apply-templates select="node()" />
2753                    </fo:block>
2754                  </fo:table-cell>
2755                </xsl:for-each>
2756              </fo:table-row>
2757            </xsl:for-each>
2758          </xsl:otherwise>
2759        </xsl:choose>
2760      </fo:table-body>
2761    </fo:table>
2762    <xsl:apply-templates select="postamble" />
2763    <xsl:if test="(@title!='') or (@anchor!='' and not(@suppress-title='true'))">
2764      <xsl:variable name="n"><xsl:call-template name="get-table-number"/></xsl:variable>
2765      <fo:block text-align="center" space-before="1em" space-after="1em">
2766        <xsl:if test="not(starts-with($n,'u'))">
2767          <xsl:text>Table </xsl:text>
2768          <xsl:value-of select="$n"/>
2769          <xsl:if test="@title!=''">: </xsl:if>
2770        </xsl:if>
2771        <xsl:if test="@title!=''">
2772          <xsl:value-of select="@title" />
2773        </xsl:if>
2774      </fo:block>
2775    </xsl:if>
2776  </fo:block>
2777</xsl:template>
2778
2779<xsl:template match="ttcol">
2780  <xsl:variable name="style">
2781    <xsl:choose>
2782      <xsl:when test="../@style!=''">
2783        <xsl:value-of select="../@style"/>
2784      </xsl:when>
2785      <xsl:otherwise>full</xsl:otherwise>
2786    </xsl:choose>
2787  </xsl:variable>
2788
2789  <fo:table-cell padding-left="0.5em" padding-right="0.5em">
2790    <xsl:if test="$style='all' or $style='full' or $style='headers'">
2791      <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
2792      <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
2793    </xsl:if>
2794    <xsl:if test="$style='all' or $style='full'">
2795      <xsl:attribute name="border-left-style">solid</xsl:attribute>
2796      <xsl:attribute name="border-right-style">solid</xsl:attribute>
2797      <xsl:attribute name="border-top-style">solid</xsl:attribute>
2798      <xsl:attribute name="border-left-width">thin</xsl:attribute>
2799      <xsl:attribute name="border-right-width">thin</xsl:attribute>
2800      <xsl:attribute name="border-top-width">thin</xsl:attribute>
2801    </xsl:if>
2802<!--    <xsl:if test="@width">
2803      <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
2804    </xsl:if> -->
2805    <xsl:choose>
2806      <xsl:when test="@align">
2807        <xsl:attribute name="text-align"><xsl:value-of select="@align" /></xsl:attribute>
2808      </xsl:when>
2809      <xsl:otherwise>
2810        <xsl:attribute name="text-align">left</xsl:attribute>
2811      </xsl:otherwise>
2812    </xsl:choose>
2813    <fo:block font-weight="bold">
2814      <xsl:apply-templates />
2815    </fo:block>
2816  </fo:table-cell>
2817</xsl:template>
2818
2819<xsl:template name="add-anchor">
2820  <xsl:if test="@anchor">
2821    <fo:block id="{@anchor}" />
2822  </xsl:if>
2823</xsl:template>
2824
2825<!-- cref support -->
2826
2827<xsl:template match="cref">
2828  <xsl:if test="$xml2rfc-comments!='no'">
2829    <xsl:variable name="cid">
2830      <xsl:call-template name="get-comment-name"/>
2831    </xsl:variable>
2832   
2833    <xsl:choose>
2834      <xsl:when test="$xml2rfc-inline!='yes'">
2835        <fo:footnote>
2836          <fo:inline>
2837            <fo:basic-link font-size="8pt" vertical-align="super" internal-destination="{$cid}">[<xsl:value-of select="$cid"/>]</fo:basic-link>
2838          </fo:inline>
2839          <fo:footnote-body>
2840            <fo:block font-size="10pt" start-indent="2em" text-align="left" id="{$cid}">
2841              <fo:inline font-size="8pt" vertical-align="super">[<xsl:value-of select="$cid"/>]</fo:inline>
2842              <xsl:text> </xsl:text>
2843              <xsl:apply-templates select="node()"/>
2844              <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
2845            </fo:block>
2846          </fo:footnote-body>
2847        </fo:footnote>
2848      </xsl:when>
2849      <xsl:otherwise>
2850        <fo:inline xsl:use-attribute-sets="comment">
2851          <xsl:text>[</xsl:text>
2852          <xsl:value-of select="$cid"/>
2853          <xsl:text>: </xsl:text>
2854          <xsl:apply-templates select="node()"/>
2855          <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
2856          <xsl:text>]</xsl:text>
2857        </fo:inline>
2858      </xsl:otherwise>
2859    </xsl:choose>   
2860  </xsl:if>
2861</xsl:template>
2862
2863
2864
2865<xsl:template name="insert-justification">
2866  <xsl:if test="$xml2rfc-ext-justification='always' or $xml2rfc-ext-justification='print'">
2867    <xsl:attribute name="text-align">justify</xsl:attribute>
2868  </xsl:if>
2869</xsl:template>
2870
2871<!-- Extensions -->
2872
2873<!-- Nothing to do for PDF output -->
2874<xsl:template match="x:assign-section-number" />
2875<xsl:template match="x:link" />
2876
2877<!-- Nothing to do here -->
2878<xsl:template match="x:anchor-alias" />
2879
2880<!-- internal ref support -->
2881<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"/>
2882
2883<xsl:template match="x:ref">
2884  <xsl:variable name="val" select="normalize-space(.)"/>
2885  <xsl:variable name="target" select="key('anchor-item',$val) | key('anchor-item-alias',$val) | //reference/x:source[x:defines=$val]"/>
2886  <xsl:variable name="irefs" select="//iref[@x:for-anchor=$val]"/>
2887  <xsl:if test="count($target)>1">
2888    <xsl:call-template name="warning">
2889      <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' is ambiguous; picking first.</xsl:with-param>
2890    </xsl:call-template>
2891  </xsl:if>
2892  <xsl:choose>
2893    <xsl:when test="$target[1]/@anchor">
2894      <fo:basic-link internal-destination="{$target[1]/@anchor}" xsl:use-attribute-sets="internal-link">
2895        <xsl:call-template name="copy-anchor"/>
2896        <xsl:apply-templates/>
2897      </fo:basic-link>
2898    </xsl:when>
2899    <xsl:when test="$target[1]/self::x:source">
2900      <xsl:variable name="extdoc" select="document($target[1]/@href)"/>
2901      <xsl:variable name="nodes" select="$extdoc//*[@anchor and (x:anchor-alias/@value=$val)]"/>
2902      <xsl:if test="not($nodes)">
2903        <xsl:call-template name="error">
2904          <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>
2905        </xsl:call-template>
2906      </xsl:if>
2907      <!-- we know the external target, but for now we won't use it (what should the PDF link to?) -->
2908      <fo:inline>
2909        <xsl:call-template name="copy-anchor"/>
2910        <xsl:value-of select="."/>
2911      </fo:inline>
2912    </xsl:when>
2913    <xsl:otherwise>
2914      <xsl:call-template name="warning">
2915        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:with-param>
2916      </xsl:call-template>
2917      <xsl:value-of select="."/>
2918    </xsl:otherwise>
2919  </xsl:choose>
2920</xsl:template>
2921
2922<!-- BCP14 keywords -->
2923<xsl:template match="x:bcp14|bcp14">
2924  <!-- TODO: figure out something that prints well -->
2925  <xsl:apply-templates/>
2926</xsl:template>
2927
2928<!-- Notes -->
2929<xsl:template match="x:note|aside">
2930  <xsl:apply-templates/>
2931</xsl:template>
2932
2933<!-- Quotes -->
2934<xsl:template match="x:blockquote|blockquote">
2935  <fo:block font-style="italic" space-before=".5em" space-after=".5em" start-indent="3em"
2936      border-left-style="solid" border-left-color="gray" border-left-width=".25em" padding-left=".5em">
2937    <xsl:apply-templates/>
2938  </fo:block>
2939</xsl:template>
2940
2941<xsl:template match="x:q">
2942  <fo:wrapper font-style="italic">
2943    <xsl:text>&#8220;</xsl:text>
2944    <xsl:apply-templates/>
2945    <xsl:text>&#8221;</xsl:text>
2946  </fo:wrapper>
2947</xsl:template>
2948
2949<!-- Definitions -->
2950<xsl:template match="x:dfn">
2951  <fo:wrapper font-style="italic">
2952    <xsl:if test="not(preceding-sibling::x:dfn) and count(following-sibling::list)=1">
2953      <xsl:attribute name="keep-with-next">always</xsl:attribute>
2954    </xsl:if>
2955    <xsl:apply-templates/>
2956  </fo:wrapper>
2957</xsl:template>
2958
2959<!-- Headings -->
2960<xsl:template match="x:h">
2961  <fo:wrapper font-weight="bold">
2962    <xsl:apply-templates/>
2963  </fo:wrapper>
2964</xsl:template>
2965
2966<!-- Highlightinghing -->
2967<xsl:template match="x:highlight">
2968  <fo:wrapper font-weight="bold">
2969    <xsl:apply-templates/>
2970  </fo:wrapper>
2971</xsl:template>
2972
2973<!-- Superscripts -->
2974<xsl:template match="x:sup|sup">
2975  <fo:inline font-size="6pt" vertical-align="super">
2976    <xsl:apply-templates/>
2977  </fo:inline>
2978</xsl:template>
2979
2980<!-- Superscripts -->
2981<xsl:template match="sub">
2982  <fo:inline font-size="6pt" vertical-align="sub">
2983    <xsl:apply-templates/>
2984  </fo:inline>
2985</xsl:template>
2986
2987<!-- measuring lengths -->
2988<xsl:template match="x:length-of">
2989  <xsl:variable name="target" select="//*[@anchor=current()/@target]"/>
2990  <xsl:if test="count($target)!=1">
2991    <xsl:call-template name="error">
2992      <xsl:with-param name="msg" select="concat('@target ',@target,' defined ',count($target),' times.')"/>
2993    </xsl:call-template>
2994  </xsl:if>
2995  <xsl:variable name="content">
2996    <xsl:apply-templates select="$target"/>
2997  </xsl:variable>
2998  <xsl:variable name="lineends" select="string-length($content) - string-length(translate($content,'&#10;',''))"/>
2999  <xsl:variable name="indents">
3000    <xsl:choose>
3001      <xsl:when test="@indented">
3002        <xsl:value-of select="number(@indented) * $lineends"/>
3003      </xsl:when>
3004      <xsl:otherwise>0</xsl:otherwise>
3005    </xsl:choose>
3006  </xsl:variable>
3007  <xsl:value-of select="string-length($content) + $lineends - $indents"/>
3008</xsl:template>
3009
3010<!-- Nop -->
3011<xsl:template match="x:span">
3012  <xsl:apply-templates/>
3013</xsl:template>
3014
3015<!-- XML checking -->
3016<xsl:template match="x:parse-xml">
3017  <xsl:apply-templates/>
3018</xsl:template>
3019
3020<xsl:template match="x:abnf-char-sequence">
3021  <xsl:choose>
3022    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
3023      <xsl:call-template name="error">
3024        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
3025      </xsl:call-template>
3026    </xsl:when>
3027    <xsl:otherwise>
3028      <xsl:text>%x</xsl:text>
3029      <xsl:call-template name="to-abnf-char-sequence">
3030        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
3031      </xsl:call-template>
3032    </xsl:otherwise>
3033  </xsl:choose>
3034</xsl:template>
3035
3036<!-- inlined RDF support -->
3037<xsl:template match="rdf:Description">
3038  <!-- ignore -->
3039</xsl:template>
3040
3041<!-- box drawing -->
3042
3043<!-- nop for alignment -->
3044<xsl:template match="x:x"/>
3045
3046<!-- box -->
3047<xsl:template match="x:bt|x:bc|x:bb">
3048  <xsl:apply-templates />
3049</xsl:template>
3050
3051<!-- author handling extensions -->
3052<xsl:template match="x:include-author">
3053  <xsl:for-each select="/*/front/author[@anchor=current()/@target]">
3054    <xsl:apply-templates select="."/>
3055  </xsl:for-each>
3056</xsl:template>
3057
3058<!-- boilerplate -->
3059<xsl:template match="x:boilerplate">
3060  <xsl:apply-templates/>
3061</xsl:template>
3062
3063  <!-- experimental: format URI with zero-width spaces to ease line breaks -->
3064 
3065  <xsl:template name="format-uri">
3066    <xsl:param name="s"/>
3067    <xsl:param name="mode"/>
3068   
3069    <xsl:choose>
3070      <!-- optimization for not hypenating the scheme name -->
3071      <xsl:when test="$mode!='after-scheme' and string-length(substring-before($s,':')) > 2">
3072        <xsl:value-of select="concat(substring-before($s,':'),':&#x200b;')"/>
3073        <xsl:call-template name="format-uri">
3074          <xsl:with-param name="s" select="substring-after($s,':')"/>
3075          <xsl:with-param name="mode" select="'after-scheme'"/>
3076        </xsl:call-template>
3077      </xsl:when>
3078      <!-- do no insert break points after hyphens -->
3079      <xsl:when test="starts-with($s,'-')">
3080        <xsl:text>-</xsl:text>
3081        <xsl:call-template name="format-uri">
3082          <xsl:with-param name="s" select="substring($s,2)"/>
3083          <xsl:with-param name="mode" select="'after-scheme'"/>
3084        </xsl:call-template>
3085      </xsl:when>
3086      <!-- last char?-->
3087      <xsl:when test="string-length($s)=1">
3088        <xsl:value-of select="$s"/>
3089      </xsl:when>
3090      <!-- add one zwsp after each character -->
3091      <xsl:when test="$s!=''">
3092        <xsl:value-of select="concat(substring($s,1,1),'&#x200b;')"/>
3093        <xsl:call-template name="format-uri">
3094          <xsl:with-param name="s" select="substring($s,2)"/>
3095          <xsl:with-param name="mode" select="'after-scheme'"/>
3096        </xsl:call-template>
3097      </xsl:when>
3098      <xsl:otherwise>
3099        <!-- done -->
3100      </xsl:otherwise>
3101    </xsl:choose>
3102   
3103  </xsl:template>
3104
3105</xsl:transform>
Note: See TracBrowser for help on using the repository browser.