source: trunk/gsdl-documentation/manuals/processing/fo-common.xsl@ 13632

Last change on this file since 13632 was 13632, checked in by lh92, 17 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 16.5 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
3
4<xsl:variable name="font" select="Cyrillic"/>
5
6<!-- display title in different formats -->
7<xsl:template match="Title">
8<xsl:choose>
9<!-- manual title -->
10<xsl:when test="parent::Manual">
11 <fo:block font-size="24.0pt" line-height="24pt" space-after.optimum="25pt" text-align="right" padding-top="3pt"><xsl:apply-templates/></fo:block>
12</xsl:when>
13
14<!-- chapter title -->
15<xsl:when test="parent::Chapter">
16<fo:block font-size="24.0pt" line-height="24pt" text-align="right" padding-top="3pt" id="Chapter_{../@id}">
17<xsl:if test="not(starts-with(@id, 'appendix')) and not(starts-with(@id, 'biblio'))"><xsl:number count="Chapter" format="1"/></xsl:if>
18</fo:block>
19<fo:block font-size="24.0pt" line-height="24pt" space-before.optimum="25pt" text-align="right" padding-top="3pt" text-indent="3cm"><xsl:apply-templates/></fo:block>
20</xsl:when>
21
22<!-- sections' title, with section number -->
23<xsl:when test="parent::Section and not(../Manual)">
24<fo:block font-size="12.0pt" text-align="left" padding-top="3pt" space-before.optimum="25pt" id="Section_{../@id}">
25<xsl:if test="not(starts-with(../../../@id, 'appendix'))"><xsl:number level="multiple" count="Chapter|Chapter/Content/Section" format="1.1"/>&#160;&#160;</xsl:if>
26<xsl:apply-templates select="Text"/>
27</fo:block>
28</xsl:when>
29
30<!-- tables(not hidden) title, in grey background and with unique number -->
31<xsl:when test="parent::Table">
32<fo:block id="Table_{../@id}" font-size="10.0pt" font-weight="bold" line-height="15pt" background-color="grey" margin-left="25pt" space-before="10pt" space-after="3pt">
33Table&#160;<xsl:number level="any" count="Table[not(@class='hidden')]"/>&#160;&#160;<xsl:apply-templates select="Text"/><xsl:value-of select="SubTitle"/>
34</fo:block>
35</xsl:when>
36
37<!-- title of subsections -->
38<xsl:when test="parent::Subsection">
39<fo:block font-size="10pt" font-weight="bold" text-align="left" id="{../@id}" space-before.optimum="25pt">
40<xsl:apply-templates select="Text"/>
41</fo:block>
42</xsl:when>
43
44<!-- title of parts -->
45<xsl:when test="parent::Part">
46<fo:block font-size="10pt" font-weight="bold" text-align="left" id="{../@id}" space-before.optimum="15pt">
47<xsl:apply-templates select="Text"/>
48</fo:block>
49</xsl:when>
50</xsl:choose>
51</xsl:template>
52
53
54
55<xsl:template match="Title" mode="Figure">
56<xsl:param name="no"/>
57<fo:block id="Figure_{../@id}" font-size="10.0pt" font-weight="bold" line-height="15pt" background-color="grey" margin-left="25pt" space-before="10pt" space-after="3pt">
58Figure&#160;<xsl:value-of select="$no"/><xsl:if test="SubTitle"><xsl:value-of select="SubTitle"/></xsl:if>&#160;<xsl:apply-templates select="Text"/>
59</fo:block>
60</xsl:template>
61
62
63
64<!-- deal with various text paragraph formats -->
65<xsl:template match="Text">
66<xsl:choose>
67<!-- these text display directly -->
68<xsl:when test="parent::Title|parent::Author|parent::Affiliation|parent::Version|parent::Date|parent::Bullet|parent::Footnote"><xsl:apply-templates/></xsl:when>
69
70<!-- text in table cells display with 11pt font size -->
71<xsl:when test="parent::th">
72<fo:block font-size="11.0pt"><xsl:apply-templates select="node()"/></fo:block>
73</xsl:when>
74
75<!-- indented text -->
76<xsl:when test="parent::Indented">
77<fo:block font-size="11.0pt" color="black" text-align="justify" space-before.optimum="15pt" margin-left="35pt">
78<xsl:apply-templates/>
79</fo:block>
80</xsl:when>
81
82<!-- normal text paragraphs -->
83<xsl:otherwise>
84<fo:block font-size="11.0pt" color="black" text-align="justify" space-before.optimum="15pt" margin-left="25pt">
85<xsl:apply-templates/>
86</fo:block>
87</xsl:otherwise>
88</xsl:choose>
89</xsl:template>
90
91
92
93<xsl:template match="Section|Content"><xsl:apply-templates/></xsl:template>
94
95
96<xsl:template match="Version">
97<fo:block font-size="12.0pt" font-weight="bold" color="gray" space-before.optimum="15pt" padding-top="3pt" margin-left="25pt" text-align-last="justify">
98<xsl:apply-templates/><fo:leader leader-pattern="space"/><xsl:value-of select="following-sibling::Date"/>
99</fo:block>
100</xsl:template>
101
102
103<xsl:template match="BulletList">
104<xsl:if test="not(parent::Bullet)">
105<fo:list-block start-indent="2cm" provisional-distance-between-starts="12pt" font-family="{$font}" space-before.optimum="15pt">
106<xsl:for-each select="Bullet">
107<fo:list-item><fo:list-item-label end-indent="label-end()">
108<fo:block><fo:inline font-family="Symbol">&#x2022;</fo:inline></fo:block>
109</fo:list-item-label>
110<fo:list-item-body start-indent="body-start()">
111<fo:block><xsl:apply-templates/></fo:block>
112
113<!-- if contains a child BulletList node -->
114<xsl:if test="BulletList">
115<xsl:for-each select="BulletList">
116<fo:list-block start-indent="3cm" provisional-distance-between-starts="12pt" font-family="{$font}" space-before.optimum="5pt">
117<xsl:for-each select="Bullet">
118<fo:list-item><fo:list-item-label end-indent="label-end()">
119<fo:block><fo:inline font-family="Symbol">&#x2022;</fo:inline></fo:block>
120</fo:list-item-label>
121<fo:list-item-body start-indent="body-start()">
122<fo:block><xsl:apply-templates/></fo:block>
123</fo:list-item-body>
124</fo:list-item>
125</xsl:for-each>
126</fo:list-block>
127</xsl:for-each>
128</xsl:if>
129
130</fo:list-item-body>
131</fo:list-item>
132</xsl:for-each>
133</fo:list-block>
134</xsl:if>
135</xsl:template>
136
137
138
139<xsl:template match="NumberedList">
140<fo:list-block start-indent="2cm" provisional-distance-between-starts="12pt" font-family="{$font}" space-before.optimum="15pt">
141<xsl:for-each select="NumberedItem">
142<fo:list-item><fo:list-item-label end-indent="label-end()">
143<fo:block><fo:inline font-family="Symbol"><xsl:number/>.</fo:inline></fo:block>
144</fo:list-item-label>
145<fo:list-item-body start-indent="body-start()">
146<xsl:choose>
147<!-- does not contain child (indented) Text or CodeLines -->
148<xsl:when test="(count(Text)+count(CodeLine))=1">
149<fo:block><xsl:apply-templates select="Text/node()"/></fo:block>
150</xsl:when>
151
152<!-- contains child (indented) Text or CodeLines -->
153<xsl:otherwise>
154<fo:block><xsl:apply-templates select="Text[1]/node()"/></fo:block>
155<fo:list-block start-indent="3cm" provisional-distance-between-starts="12pt" font-family="{$font}" space-before.optimum="15pt" space-after.optimum="15pt">
156<xsl:for-each select="child::*[position()>1]">
157<fo:list-item><fo:list-item-label end-indent="label-end()"><fo:block/></fo:list-item-label>
158<fo:list-item-body><fo:block><xsl:apply-templates/></fo:block></fo:list-item-body>
159</fo:list-item>
160</xsl:for-each>
161</fo:list-block>
162</xsl:otherwise>
163</xsl:choose>
164</fo:list-item-body>
165</fo:list-item>
166</xsl:for-each>
167</fo:list-block>
168</xsl:template>
169
170
171
172<xsl:template match="b"><fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline></xsl:template>
173
174<xsl:template match="i"><fo:inline font-style="italic"><xsl:apply-templates/></fo:inline></xsl:template>
175
176<xsl:template match="u"><fo:inline text-decoration="underline" color="blue"><xsl:apply-templates/></fo:inline></xsl:template>
177
178<xsl:template match="CodeLine">
179<fo:block font-size="8.0pt" font-family="Courier" color="black" text-align="left">
180<xsl:choose>
181<xsl:when test="parent::NumberedItem or parent::Bullet"/>
182<!-- normal code lines -->
183<xsl:when test="not(parent::Figure) and not(parent::th)">
184<xsl:attribute name="margin-left">50pt</xsl:attribute>
185<xsl:if test="not(name(preceding-sibling::*[position()=1])='CodeLine')">
186<xsl:attribute name="space-before.optimum">8pt</xsl:attribute>
187</xsl:if>
188</xsl:when>
189
190<!-- codeline in a hidden table -->
191<xsl:when test="parent::th and ../../../../@class='hidden'">
192<xsl:attribute name="margin-left">10pt</xsl:attribute>
193<xsl:attribute name="space-before.optimum">8pt</xsl:attribute>
194<xsl:attribute name="space-after.optimum">8pt</xsl:attribute>
195</xsl:when>
196<!-- normal table -->
197<xsl:otherwise>
198<xsl:if test="not(parent::th)">
199<xsl:attribute name="space-before.optimum">3pt</xsl:attribute>
200</xsl:if>
201</xsl:otherwise>
202</xsl:choose>
203
204<xsl:apply-templates/>
205</fo:block>
206
207<!--
208<xsl:param name="withLineNumber">n</xsl:param>
209<xsl:choose>
210<xsl:when test="not(parent::Figure) and not(parent::th)">
211<fo:block font-size="8.0pt" font-family="Courier" color="black" text-align="left" margin-left="50pt">
212<xsl:if test="not(name(preceding-sibling::*[position()=1])='CodeLine')">
213<xsl:attribute name="space-before.optimum">8pt</xsl:attribute>
214</xsl:if>
215<xsl:apply-templates/>
216</fo:block>
217</xsl:when>
218
219<xsl:when test="parent::th and ../../../../@class='hidden'">
220<fo:block font-size="8.0pt" font-family="Courier" color="black"
221text-align="left" margin-left="10pt" space-before.optimum="8pt" space-after.optimum="8pt">
222<xsl:apply-templates/>
223</fo:block>
224</xsl:when>
225
226<xsl:otherwise>
227<fo:block font-size="8.0pt" font-family="Courier" color="black" text-align="left">
228<xsl:if test="not(parent::th)">
229<xsl:attribute name="space-before.optimum">3pt</xsl:attribute>
230</xsl:if>
231<xsl:if test="$withLineNumber='y'"><xsl:number/></xsl:if>
232<xsl:apply-templates/>
233</fo:block>
234</xsl:otherwise>
235</xsl:choose>
236-->
237</xsl:template>
238
239
240
241
242
243<!-- table -->
244<xsl:template match="Table">
245<fo:table table-layout="fixed" width="100%">
246<fo:table-column column-width="proportional-column-width(1)"/>
247<fo:table-body>
248
249<!-- table title -->
250
251<fo:table-row>
252<!-- always keep the table title with the table -->
253<xsl:if test="not(normalize-space(Title/Text)='')"><xsl:attribute name="keep-with-next">always</xsl:attribute></xsl:if>
254<fo:table-cell>
255<fo:block>
256<xsl:if test="not(normalize-space(Title/Text)='')"><xsl:apply-templates select="Title"/></xsl:if>
257</fo:block>
258</fo:table-cell>
259</fo:table-row>
260
261<!-- table content -->
262
263<fo:table-row>
264<fo:table-cell>
265<fo:block>
266<!-- use nested table to center-align the table -->
267<fo:table table-layout="fixed" width="100%">
268<fo:table-column column-width="25pt"/>
269<fo:table-column column-width="60pt"/>
270<fo:table-body>
271<fo:table-row>
272<fo:table-cell column-number="1"/>
273<fo:table-cell column-number="2">
274<fo:table table-layout="fixed">
275<xsl:for-each select="TableContent/tr[1]/th">
276<fo:table-column>
277
278<!-- calculate the column width based on the width in the original html file -->
279
280<xsl:attribute name="column-width">
281<xsl:value-of select="concat(number(@width) * 0.8, 'px')"/>
282</xsl:attribute>
283</fo:table-column>
284</xsl:for-each>
285<fo:table-body>
286<xsl:for-each select="TableContent/tr">
287
288<!-- this is to ensure no breaks in the table -->
289
290<fo:table-row keep-with-next="always">
291<xsl:for-each select="th">
292<xsl:choose>
293
294<!-- when the cell contains only text -->
295
296<xsl:when test="not(../../../@class='hidden') and not(File)">
297<fo:table-cell column-number="{position()}" vertical-align="top" padding="2pt" border="0.5pt" border-color="black" border-style="solid">
298<xsl:if test="position()=1 and normalize-space(../../tr[1]/th[1])=''"><xsl:attribute name="text-align">right</xsl:attribute></xsl:if>
299<xsl:if test="position()>1 and not(last())"><xsl:attribute name="text-align">left</xsl:attribute></xsl:if>
300<xsl:if test="last()"><xsl:attribute name="text-align">justify</xsl:attribute></xsl:if>
301<xsl:apply-templates/>
302</fo:table-cell>
303</xsl:when>
304
305<!-- when the cell is an image -->
306
307<xsl:when test="not(../../../@class='hidden') and File">
308<fo:table-cell column-number="{position()}" vertical-align="top" text-align="right" padding="2pt" border="0.5pt" border-color="black" border-style="solid">
309<xsl:apply-templates/>
310</fo:table-cell>
311</xsl:when>
312
313<!-- deal with hidden table -->
314
315<xsl:when test="../../../@class='hidden'">
316<fo:table-cell column-number="{position()}" vertical-align="top" padding="2pt">
317<xsl:if test="position()=1"><xsl:attribute name="text-align">left</xsl:attribute></xsl:if>
318<xsl:if test="position()>1"><xsl:attribute name="text-align">justify</xsl:attribute></xsl:if>
319<xsl:apply-templates/>
320</fo:table-cell></xsl:when></xsl:choose></xsl:for-each></fo:table-row></xsl:for-each></fo:table-body></fo:table></fo:table-cell>
321</fo:table-row></fo:table-body></fo:table></fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table>
322</xsl:template>
323
324
325
326<!-- Figure -->
327<xsl:template match="Figure">
328<fo:table table-layout="fixed" width="100%">
329<fo:table-column column-width="proportional-column-width(1)"/>
330<fo:table-body>
331
332<!-- figure title -->
333<!-- number of current figure = total_number_of_previous_figure - total_number_of_previous_sub_figures-->
334<xsl:variable name="temp_total_figs"><xsl:number count="Figure" level="any"/></xsl:variable>
335<xsl:variable name="temp_num_of_sub_figs">
336 <xsl:number count="Figure[Title/SubTitle and substring(translate(@id, '_0123456789', '99999999999'), string-length(@id)-1, string-length(@id))='99']" level="any"/>
337</xsl:variable>
338<xsl:variable name="no"><xsl:value-of select="$temp_total_figs - $temp_num_of_sub_figs"/></xsl:variable>
339
340<fo:table-row keep-with-next="always"><fo:table-cell><fo:block>
341<xsl:apply-templates select="Title" mode="Figure"><xsl:with-param name="no" select="$no"/></xsl:apply-templates>
342</fo:block></fo:table-cell></fo:table-row>
343
344
345<fo:table-row><fo:table-cell>
346<xsl:if test="File"><xsl:apply-templates select="File"/></xsl:if>
347<xsl:if test="CodeLine">
348<fo:block text-align="left">
349<fo:table start-indent="3pt" table-layout="fixed" width="100%" border-spacing="3pt">
350<fo:table-column column-width="proportional-column-width(1)"/>
351<fo:table-column column-width="100mm"/>
352<fo:table-column column-width="proportional-column-width(1)"/>
353<fo:table-body>
354<fo:table-row>
355<fo:table-cell column-number="2">
356
357<xsl:if test="not(@calss='withLineNumber')">
358<xsl:attribute name="border-width">0.1pt</xsl:attribute><xsl:attribute name="border-style">solid</xsl:attribute>
359<xsl:attribute name="border-color">black</xsl:attribute><xsl:attribute name="border-collapse">separate</xsl:attribute>
360</xsl:if>
361
362<xsl:choose>
363<!-- display the codeline number besides each codeline using nested table -->
364<xsl:when test="@class='withLineNumber'">
365<fo:table start-indent="3pt" table-layout="fixed" width="100%" border-spacing="3pt">
366<fo:table-column column-width="28pt"/>
367<fo:table-column column-width="proportional-column-width(1)" border-width="0.1pt" border-style="solid" border-color="black" border-collapse="separate"/>
368<fo:table-body>
369<xsl:for-each select="CodeLine">
370<fo:table-row>
371<fo:table-cell column-number="1">
372<fo:block font-size="8pt" font-family="Courier" space-before.optimum="3pt" text-align="right"><xsl:number/></fo:block>
373</fo:table-cell>
374<fo:table-cell column-number="2"><xsl:apply-templates select="."/></fo:table-cell>
375</fo:table-row>
376</xsl:for-each>
377</fo:table-body>
378</fo:table>
379</xsl:when>
380
381<xsl:otherwise><xsl:apply-templates select="CodeLine"/></xsl:otherwise>
382</xsl:choose></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block></xsl:if>
383</fo:table-cell></fo:table-row></fo:table-body></fo:table>
384</xsl:template>
385
386
387
388
389<xsl:template match="File">
390<xsl:variable name="height"><xsl:value-of select="@height"/>em</xsl:variable>
391<xsl:variable name="width"><xsl:value-of select="@width"/>em</xsl:variable>
392<fo:block display-align="center" text-align="center" space-after.optimum="15pt" space-before.optimum="3pt">
393<fo:external-graphic display-align="center" src="{@url}" content-height="{$height}" content-width="{$width}"/>
394</fo:block>
395</xsl:template>
396
397
398
399<!-- reference in the text to a footnote -->
400<xsl:template match="FootnoteRef">
401<xsl:variable name="no"><xsl:value-of select="@id"/></xsl:variable>
402<fo:footnote>
403<fo:inline baseline-shift="super" font-size="smaller">(<xsl:value-of select="$no"/>)</fo:inline>
404<fo:footnote-body>
405<fo:list-block provisional-label-separation="0pt" provisional-distance-between-starts="18pt" space-after.optimum="6pt">
406<fo:list-item>
407<fo:list-item-label end-indent="label-end()">
408<fo:block>(<xsl:number count="//FootnoteRef" level="any"/>)</fo:block>
409</fo:list-item-label>
410<fo:list-item-body start-indent="body-start()">
411<fo:block><xsl:apply-templates select="//Footnote[@id=$no]"/></fo:block>
412</fo:list-item-body>
413</fo:list-item>
414</fo:list-block>
415</fo:footnote-body>
416</fo:footnote>
417</xsl:template>
418
419
420<xsl:template match="Footnote"><xsl:apply-templates/></xsl:template>
421
422
423<xsl:template match="BibItem">
424<fo:block font-size="11.0pt" color="black" text-align="justify" space-before.optimum="15pt" margin-left="25pt"><xsl:apply-templates/></fo:block>
425</xsl:template>
426
427
428<xsl:template match="Author">
429<fo:block font-size="15pt" color="black" text-align="right" space-before.optimum="25pt"><xsl:apply-templates/></fo:block>
430</xsl:template>
431
432
433<xsl:template match="Affiliation">
434<fo:block font-size="10.0pt" color="black" text-align="right" space-after.optimum="125pt" space-before.optimum="25pt"><xsl:apply-templates/></fo:block>
435</xsl:template>
436
437
438<xsl:template match="Text" mode="heading"><fo:block font-size="18.0pt" color="gray" text-align="right"><xsl:apply-templates/></fo:block></xsl:template>
439
440
441<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>
442
443<xsl:template match="br"><fo:block/></xsl:template>
444</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.