source: rfc2629xslt/rfc2629toFO.xslt @ 285

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

Upgrade to latest version of rfc2629.xslt

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