stylesheet to translate CDM exports (xml) to mediawiki pages
[cdmlib.git] / cdmlib-print / src / main / resources / stylesheets / pdf / flora-malesiana.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3
4 CDM XSL Transformation
5 Target Format: Flora Malesiana
6
7 -->
8 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.1" exclude-result-prefixes="fo">
9 <!-- ############### Constants and definitions ################### -->
10 <!-- **********************************
11 ** global definitions
12 *********************************** -->
13 <xsl:param name="global-family-font">Times</xsl:param>
14 <xsl:param name="global-size-font">12pt</xsl:param>
15 <xsl:param name="global-line-height">1.2em</xsl:param>
16 <xsl:param name="global-height-page">297mm</xsl:param>
17 <xsl:param name="global-width-page">210mm</xsl:param>
18 <xsl:param name="global-indentation">8mm</xsl:param>
19 <!-- **********************************
20 ** definitions for taxon pages
21 *********************************** -->
22 <xsl:param name="taxon-page-top-margin">0mm</xsl:param>
23 <xsl:param name="taxon-page-right-margin">32mm</xsl:param>
24 <xsl:param name="taxon-page-bottom-margin">0mm</xsl:param>
25 <xsl:param name="taxon-page-left-margin">32mm</xsl:param>
26 <xsl:param name="taxon-region-body-top-margin">26mm</xsl:param>
27 <xsl:param name="taxon-region-body-bottom-margin">28mm</xsl:param>
28 <xsl:param name="taxon-region-before-extent">0mm</xsl:param>
29 <xsl:param name="taxon-region-after-extent">0mm</xsl:param>
30 <xsl:param name="taxon-header-family-font">Times</xsl:param>
31 <xsl:param name="taxon-header-before-bg-color">white</xsl:param>
32 <xsl:param name="content-bg-color">white</xsl:param>
33 <xsl:param name="taxon-header-after-bg-color">white</xsl:param>
34 <xsl:param name="taxon-header-size-font">9pt</xsl:param>
35 <xsl:param name="taxon-header-style-font">italic</xsl:param>
36 <xsl:param name="taxon-header-page-number-size-font">8pt</xsl:param>
37 <xsl:param name="taxon-header-page-number-align-text">end</xsl:param>
38 <xsl:param name="taxon-page-number-initial">1</xsl:param>
39 <xsl:param name="uuidFamily">210a8214-4e69-401a-8e47-c7940d990bdd</xsl:param>
40 <xsl:param name="uuidGenus">1b11c34c-48a8-4efa-98d5-84f7f66ef43a</xsl:param>
41 <xsl:param name="uuidSubgenus">78786e16-2a70-48af-a608-494023b91904</xsl:param>
42 <!-- **********************************
43 ** html support
44 *********************************** -->
45 <!-- format html i tags in text as italic -->
46 <xsl:template match="i">
47 <fo:inline font-style="italic">
48 <xsl:value-of select="."/>
49 </fo:inline>
50 </xsl:template>
51 <!-- format html b tags in text as bold -->
52 <xsl:template match="b">
53 <fo:inline font-weight="bold">
54 <xsl:apply-templates/>
55 </fo:inline>
56 </xsl:template>
57 <!-- ########################################################################## -->
58 <!-- start xsl output -->
59 <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="no"/>
60 <xsl:param name="versionParam" select="'1.0'"/>
61 <!-- root element: root -->
62 <xsl:template match="root">
63 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
64 <!-- defines page layout -->
65 <fo:layout-master-set>
66 <!-- layout for odd taxon pages -->
67 <fo:simple-page-master master-name="taxon_page_odd" page-height="{$global-height-page}" page-width="{$global-width-page}" margin-top="{$taxon-page-top-margin}" margin-bottom="{$taxon-page-bottom-margin}" margin-left="{$taxon-page-left-margin}" margin-right="{$taxon-page-right-margin}">
68 <fo:region-body margin-top="{$taxon-region-body-top-margin}" margin-bottom="{$taxon-region-body-bottom-margin}"/>
69 <fo:region-before extent="{$taxon-region-before-extent}" region-name="odd-before"/>
70 <fo:region-after extent="{$taxon-region-after-extent}" region-name="odd-after"/>
71 </fo:simple-page-master>
72 <!-- layout for even taxon pages -->
73 <fo:simple-page-master master-name="taxon_page_even" page-height="{$global-height-page}" page-width="{$global-width-page}" margin-top="{$taxon-page-top-margin}" margin-bottom="{$taxon-page-bottom-margin}" margin-left="{$taxon-page-left-margin}" margin-right="{$taxon-page-right-margin}">
74 <fo:region-body margin-top="{$taxon-region-body-top-margin}" margin-bottom="{$taxon-region-body-bottom-margin}"/>
75 <fo:region-before extent="{$taxon-region-before-extent}" region-name="even-before"/>
76 <fo:region-after extent="{$taxon-region-after-extent}" region-name="even-after"/>
77 </fo:simple-page-master>
78 <!-- defines repeatable page-sequence for layout of taxa -->
79 <fo:page-sequence-master master-name="taxon_page">
80 <fo:repeatable-page-master-alternatives>
81 <fo:conditional-page-master-reference master-reference="taxon_page_odd" page-position="first"/>
82 <fo:conditional-page-master-reference master-reference="taxon_page_odd" page-position="rest" odd-or-even="even"/>
83 <fo:conditional-page-master-reference master-reference="taxon_page_even" page-position="rest" odd-or-even="odd"/>
84 <!-- <fo:conditional-page-master-reference master-reference="mclBoook_taxon_page_even"
85 page-position="last"/>-->
86 </fo:repeatable-page-master-alternatives>
87 </fo:page-sequence-master>
88 </fo:layout-master-set>
89 <!-- end: defines page layout -->
90 <!-- page sequence for taxon view -->
91 <fo:page-sequence master-reference="taxon_page" initial-page-number="{$taxon-page-number-initial}" force-page-count="no-force">
92 <fo:static-content flow-name="odd-before">
93 <xsl:call-template name="odd-before-header"/>
94 </fo:static-content>
95 <fo:static-content flow-name="even-before">
96 <xsl:call-template name="even-before-header"/>
97 </fo:static-content>
98 <fo:static-content flow-name="odd-after">
99 <xsl:call-template name="odd-after-header"/>
100 </fo:static-content>
101 <fo:static-content flow-name="even-after">
102 <xsl:call-template name="even-after-header"/>
103 </fo:static-content>
104 <!-- format taxa -->
105 <fo:flow flow-name="xsl-region-body">
106 <fo:block font-family="{$global-family-font}" font-size="{$global-size-font}" line-height="{$global-line-height}">
107 <xsl:for-each select="//TaxonNode">
108 <xsl:apply-templates select="."/>
109 </xsl:for-each>
110 </fo:block>
111 </fo:flow>
112 </fo:page-sequence>
113 </fo:root>
114 </xsl:template>
115 <!-- HEADER -->
116 <xsl:template name="odd-before-header">
117 <fo:block font-family="{$taxon-header-family-font}" font-style="{$taxon-header-style-font}" font-size="{$taxon-header-size-font}">
118 <!-- No pagination at the moment
119 <fo:block font-size="{$taxon-header-page-number-size-font}"
120 text-align="{$taxon-header-page-number-align-text}"> &#x2014; <fo:page-number/> &#x2014; </fo:block>
121 <fo:block color="white">-</fo:block> -->
122 <fo:block>
123 <fo:retrieve-marker retrieve-class-name="pageTitleMarker" retrieve-position="first-starting-within-page" retrieve-boundary="document"/>
124 <xsl:text> </xsl:text>
125 <fo:retrieve-marker retrieve-class-name="pageTitleSectionMarker" retrieve-position="first-starting-within-page" retrieve-boundary="document"/>
126 </fo:block>
127 </fo:block>
128 </xsl:template>
129 <xsl:template name="odd-before-header-endnote">
130 <fo:block font-family="{$taxon-header-family-font}" font-style="{$taxon-header-style-font}" font-size="{$taxon-header-size-font}">
131 <!-- No pagination at the moment
132 <fo:block font-size="{$taxon-header-page-number-size-font}"
133 text-align="{$taxon-header-page-number-align-text}"> &#x2014; <fo:page-number/> &#x2014;
134 </fo:block> -->
135 </fo:block>
136 </xsl:template>
137 <xsl:template name="odd-after-header">
138 <fo:block font-family="{$taxon-header-family-font}" font-style="{$taxon-header-style-font}" font-size="{$taxon-header-size-font}">
139 <fo:block>
140 <fo:inline>
141 <fo:retrieve-marker retrieve-class-name="pageTitleMarker" retrieve-position="last-starting-within-page" retrieve-boundary="document"/>
142 <fo:retrieve-marker retrieve-class-name="pageTitleSectionMarker" retrieve-position="last-starting-within-page" retrieve-boundary="document"/>
143 </fo:inline>
144 </fo:block>
145 </fo:block>
146 </xsl:template>
147 <xsl:template name="even-before-header">
148 <fo:block font-family="{$taxon-header-family-font}" font-style="{$taxon-header-style-font}" font-size="{$taxon-header-size-font}">
149 <!--
150 No pagination at the moment
151 <fo:block color="white" font-size="{$taxon-header-page-number-size-font}">-</fo:block>
152 <fo:block color="white">-</fo:block>-->
153 <fo:block>
154 <fo:inline>
155 <fo:retrieve-marker retrieve-class-name="pageTitleMarker" retrieve-position="first-starting-within-page" retrieve-boundary="document"/>
156 <fo:retrieve-marker retrieve-class-name="pageTitleSectionMarker" retrieve-position="first-starting-within-page" retrieve-boundary="document"/>
157 </fo:inline>
158 </fo:block>
159 </fo:block>
160 </xsl:template>
161 <xsl:template name="even-after-header">
162 <fo:block font-family="{$taxon-header-family-font}" font-style="{$taxon-header-style-font}" font-size="{$taxon-header-size-font}">
163 <fo:block>
164 <fo:inline>
165 <fo:retrieve-marker retrieve-class-name="pageTitleMarker" retrieve-position="last-starting-within-page" retrieve-boundary="document"/>
166 <fo:retrieve-marker retrieve-class-name="pageTitleSectionMarker" retrieve-position="last-starting-within-page" retrieve-boundary="document"/>
167 </fo:inline>
168 </fo:block>
169 <!-- No pagination at the moment
170 <fo:block color="white">-</fo:block>
171 <fo:block font-size="{$taxon-header-page-number-size-font}"
172 text-align="{$taxon-header-page-number-align-text}"> &#x2014; <fo:page-number/> &#x2014;
173 </fo:block> -->
174 </fo:block>
175 </xsl:template>
176 <!-- GENERAL -->
177 <xsl:template match="TaxonNode" name="TaxonNode">
178 <xsl:apply-templates select="Taxon"/>
179 </xsl:template>
180 <xsl:template match="Taxon" name="Taxon">
181 <xsl:call-template name="title"/>
182 <xsl:apply-templates select="synonymy"/>
183 <xsl:apply-templates select="descriptions"/>
184 </xsl:template>
185 <xsl:template name="title">
186 <fo:block margin-bottom="5mm">
187 <!-- we need to find a way to store the uuid in a variable xsl:parameter did not work or i was using it wrong -->
188 <xsl:choose>
189 <!-- family -->
190 <xsl:when test="name/rank/uuid='af5f2481-3192-403f-ae65-7c957a0f02b6'">
191 <fo:block text-align="center" text-transform="uppercase">
192 <xsl:apply-templates select="name/genusOrUninomial"/>
193 </fo:block>
194 </xsl:when>
195 <!-- genus -->
196 <xsl:when test="name/rank/uuid='1b11c34c-48a8-4efa-98d5-84f7f66ef43a'">
197 <fo:block font-weight="bold" text-align="center" text-transform="uppercase">
198 <xsl:apply-templates select="name/genusOrUninomial"/>
199 </fo:block>
200 </xsl:when>
201 <!-- subgenus -->
202 <xsl:when test="name/rank/uuid='78786e16-2a70-48af-a608-494023b91904'">
203 <fo:block font-weight="bold" text-align="center">
204 <xsl:apply-templates select="name/rank/representation_L10n"/>
205 <xsl:text> </xsl:text>
206 <xsl:apply-templates select="name/genusOrUninomial"/>
207 </fo:block>
208 </xsl:when>
209 <!-- species -->
210 <xsl:when test="name/rank/uuid='b301f787-f319-4ccc-a10f-b4ed3b99a86d'">
211 <fo:block>
212 <fo:inline font-weight="bold">
213 <xsl:apply-templates select="name/genusOrUninomial"/>
214 <xsl:text> </xsl:text>
215 <xsl:apply-templates select="name/specificEpithet"/>
216 </fo:inline>
217 <xsl:text> </xsl:text>
218 <xsl:call-template name="authorFromTaggedName"/>
219 </fo:block>
220 </xsl:when>
221 <!-- infraspecific -->
222 <xsl:otherwise>
223 <fo:block>
224 <xsl:apply-templates select="name/rank/abbreviation"/>
225 <xsl:text> </xsl:text>
226 <fo:inline font-weight="bold">
227 <xsl:apply-templates select="name/infraSpecificEpithet"/>
228 </fo:inline>
229 <xsl:if test="name/specificEpithet != name/infraSpecificEpithet">
230 <xsl:text> </xsl:text>
231 <xsl:call-template name="authorFromTaggedName"/>
232 </xsl:if>
233 </fo:block>
234 </xsl:otherwise>
235 </xsl:choose>
236 </fo:block>
237 </xsl:template>
238 <!-- NAME -->
239 <xsl:template match="name">
240 <xsl:apply-templates select="taggedName"/>
241 <xsl:apply-templates select="nomenclaturalReference"/>
242 </xsl:template>
243 <xsl:template match="taggedName">
244 <xsl:for-each select="e">
245 <xsl:choose>
246 <xsl:when test="type='name'">
247 <fo:inline font-style="italic">
248 <xsl:value-of select="text"/>
249 </fo:inline>
250 <xsl:text> </xsl:text>
251 </xsl:when>
252 <xsl:when test="type='authors'">
253 <xsl:value-of select="text"/>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:value-of select="text"/>
257 </xsl:otherwise>
258 </xsl:choose>
259 <xsl:if test="not(position() = last())">
260 <xsl:text> </xsl:text>
261 </xsl:if>
262 </xsl:for-each>
263 </xsl:template>
264 <!-- AUTHOR -->
265 <xsl:template name="authorFromTaggedName">
266 <xsl:for-each select="name/taggedName/e">
267 <xsl:choose>
268 <xsl:when test="type='authors'">
269 <xsl:value-of select="text"/>
270 </xsl:when>
271 </xsl:choose>
272 </xsl:for-each>
273 </xsl:template>
274
275 <xsl:template match="nomenclaturalReference">
276 <fo:inline>
277 <xsl:value-of select="substring-after(titleCache, ../taggedName/e[last()]/text)"/>
278 </fo:inline>
279 <xsl:text> </xsl:text>
280 <fo:inline>
281 <xsl:value-of select="../nomenclaturalMicroReference"/>
282 </fo:inline>
283 </xsl:template>
284 <!-- DESCRIPTIONS -->
285 <xsl:template match="descriptions">
286 <fo:block margin-bottom="5mm">
287 <xsl:for-each select="features/feature">
288 <fo:block text-indent="{$global-indentation}" text-align="justify">
289 <xsl:choose>
290 <xsl:when test="count(feature)!=0">
291 <xsl:call-template name="secondLevelDescriptionElements"/>
292 </xsl:when>
293 <xsl:otherwise>
294 <!-- everything except Citation -->
295 <xsl:if test="uuid!='99b2842f-9aa7-42fa-bd5f-7285311e0101'"><xsl:value-of select="representation_L10n"/> - <xsl:call-template name="descriptionElements"/>
296 </xsl:if>
297 </xsl:otherwise>
298 </xsl:choose>
299 </fo:block>
300 </xsl:for-each>
301 </fo:block>
302 </xsl:template>
303 <xsl:template name="descriptionElements">
304 <!--xsl:choose>
305 <xsl:when test="supportsDistribution='true'">
306 <xsl:call-template name="distribution"/>
307 </xsl:when>
308 <xsl:when test="supportsCommonTaxonName='true'">
309 <xsl:call-template name="commonTaxonName"/>
310 </xsl:when>
311 <xsl:otherwise-->
312 <xsl:call-template name="textData"/>
313 <!--/xsl:otherwise>
314 </xsl:choose-->
315 </xsl:template>
316 <xsl:template name="secondLevelDescriptionElements">
317 <xsl:for-each select="feature">
318 <fo:inline>
319 <xsl:text> </xsl:text>
320 <xsl:choose>
321 <!-- Lifeform -->
322 <!-- should not show the feature name -->
323 <xsl:when test="uuid='db9228d3-8bbf-4460-abfe-0b1326c82f8e'">
324 <xsl:for-each select="descriptionelements/descriptionelement">
325 <fo:inline>
326 <xsl:value-of select="multilanguageText_L10n/text"/>
327 </fo:inline>
328 </xsl:for-each>
329 </xsl:when>
330 <xsl:otherwise>
331 <fo:inline font-style="italic">
332 <xsl:value-of select="representation_L10n"/>
333 </fo:inline>
334 <xsl:for-each select="descriptionelements/descriptionelement">
335 <fo:inline>
336 <xsl:value-of select="substring-after(multilanguageText_L10n/text, ../../representation_L10n)"/>
337 </fo:inline>
338 </xsl:for-each>
339 </xsl:otherwise>
340 </xsl:choose>
341 </fo:inline>
342 </xsl:for-each>
343 </xsl:template>
344 <xsl:template name="commonTaxonName">
345 <xsl:for-each select="descriptionelements/descriptionelement">
346 <fo:inline><xsl:value-of select="language/representation_L10n"/> (<xsl:value-of select="area/representation_L10n"/>), </fo:inline>
347 </xsl:for-each>
348 </xsl:template>
349 <xsl:template name="distribution">
350 <xsl:for-each select="descriptionelements/descriptionelement">
351 <fo:inline><xsl:value-of select="area/representation_L10n"/> (<xsl:value-of select="status/representation_L10n"/>), </fo:inline>
352 </xsl:for-each>
353 </xsl:template>
354 <xsl:template name="textData">
355 <xsl:for-each select="descriptionelements/descriptionelement">
356 <fo:inline>
357 <xsl:apply-templates select="multilanguageText_L10n/text"/>
358 </fo:inline>
359 </xsl:for-each>
360 </xsl:template>
361 <!-- SYNONYMY BLOCK -->
362 <xsl:template match="synonymy" name="synonymy">
363 <fo:block margin-bottom="5mm">
364 <fo:block line-height="{$global-line-height}" text-align="justify" text-indent="-{$global-indentation}" start-indent="{$global-indentation}">
365 <xsl:apply-templates select="../name"/>
366 <xsl:call-template name="citations"/>
367 <xsl:apply-templates select="homotypicSynonymsByHomotypicGroup"/>
368 <xsl:apply-templates select="../name/typeDesignations"/>
369 </fo:block>
370 <xsl:apply-templates select="heterotypicSynonymyGroups"/>
371 </fo:block>
372 </xsl:template>
373 <xsl:template match="homotypicSynonymsByHomotypicGroup">
374 <xsl:for-each select="e">
375 <xsl:text> - </xsl:text>
376 <xsl:apply-templates select="name"/>
377 </xsl:for-each>
378 </xsl:template>
379 <xsl:template match="heterotypicSynonymyGroups">
380 <xsl:for-each select="e">
381 <fo:block line-height="{$global-line-height}" text-align="start" text-indent="-{$global-indentation}" start-indent="{$global-indentation}">
382 <xsl:for-each select="e">
383 <xsl:apply-templates select="name"/>
384 </xsl:for-each>
385 <xsl:apply-templates select="e[1]/name/typeDesignations"/>
386 </fo:block>
387 </xsl:for-each>
388 </xsl:template>
389 <xsl:template name="citations">
390 <xsl:for-each select="../descriptions/features/feature[uuid='99b2842f-9aa7-42fa-bd5f-7285311e0101']/descriptionelements/descriptionelement">
391 <!-- TODO sorting only works for the first citation, implement correctly -->
392 <xsl:sort select="sources/e[1]/citation/datePublished/start"/>
393 <xsl:for-each select="sources/e">
394 <xsl:text>; </xsl:text>
395 <fo:inline>
396 <xsl:value-of select="substring-before(citation/titleCache, citation/datePublished/start)"/>
397 <xsl:value-of select="concat('(', citation/datePublished/start, ')')"/>
398 <xsl:text> </xsl:text>
399 <xsl:value-of select="citationMicroReference"/>
400 </fo:inline>
401 </xsl:for-each>
402 </xsl:for-each>
403 </xsl:template>
404 <xsl:template match="typeDesignations">
405 <!-- DISABLING, BECAUSE IT IS CURRENTLY BROKEN IN REST SERVICE
406 <xsl:for-each select="child::*">
407 <fo:inline>
408 <xsl:text> - Type: </xsl:text>
409 <xsl:choose>
410 <xsl:when test="class='SpecimenTypeDesignation'">
411 <xsl:value-of select="typeSpecimen/titleCache"/>
412 </xsl:when>
413 </xsl:choose>
414 </fo:inline>
415 </xsl:for-each>
416 -->
417 </xsl:template>
418 </xsl:stylesheet>