source: rfc2629xslt/rfc2629toFO.xslt @ 448

Last change on this file since 448 was 446, checked in by julian.reschke@…, 11 years ago

Update to latest version of rfc2629.xslt, and add experimental version of xml2rfc.tcl (supporting the new IPR escape clause), use that clause in P1..P7 (but not for the method registrations).

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