source: rfc2629xslt/rfc2629toFO.xslt @ 10

Last change on this file since 10 was 6, checked in by fielding@…, 15 years ago

XSLT stylesheet for enhanced RFC2629 xml2rfc output as HTML.
By Julian Reschke

Obtained from: wget -N http://www.greenbytes.de/tech/webdav/rfc2629xslt.zip

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