root/OOo/ooo2dbk/trunk/ooo2dbk.odf.xsl

Revision 50505, 161.1 kB (checked in by lgodard, 2 years ago)

- add ommitted tags <phrase>

Line 
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY nbsp "&#160;">
4 ]>
5 <!--
6 Copyright (c) 2004-2006 Nuxeo SARL <http://nuxeo.com>
7 Copyright (c) 2003 Stefan Rinke <stefan@stefan-rinke.de>
8 Copyright (c) 2002 Eric Bellot <ebellot@netcourrier.com>
9
10 Authors:
11 M.-A. Darche (Nuxeo)
12 Stefan Rinke <stefan@stefan-rinke.de>
13 Eric Bellot <ebellot@netcourrier.com>
14 Laurent Godard <lgodard@indesko.com>
15 Maurice TARDELLI - CERTU/SYS/ITS <Maurice.Tardelli@equipement.gouv.fr> for ODF
16
17 This script is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Lesser General Public
19 License as published by the Free Software Foundation; either
20 version 2.1 of the License, or (at your option) any later version.
21
22 This script is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25 Lesser General Public License for more details.
26
27 You should have received a copy of the GNU Lesser General Public
28 License along with this library; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
31 See ``COPYING`` for more information.
32
33 $Id: ooo2dbk.xsl 28486 2005-10-21 13:10:18Z madarche $
34 -->
35 <xsl:stylesheet version="1.0"
36   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37     xmlns:office= "urn:oasis:names:tc:opendocument:xmlns:office:1.0"
38     xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
39     xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
40     xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
41     xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
42     xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
43     xmlns:xlink="http://www.w3.org/1999/xlink"
44     xmlns:dc="http://purl.org/dc/elements/1.1/"
45     xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
46     xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
47     xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
48     xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
49     xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
50     xmlns:math="http://www.w3.org/1998/Math/MathML"
51     xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
52     xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
53     xmlns:ooo="http://openoffice.org/2004/office"
54     xmlns:ooow="http://openoffice.org/2004/writer"
55     xmlns:oooc="http://openoffice.org/2004/calc"
56     xmlns:dom="http://www.w3.org/2001/xml-events"
57     xmlns:xforms="http://www.w3.org/2002/xforms"
58     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
59     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
60   exclude-result-prefixes="office style text table draw
61   fo xlink number svg chart dr3d math form script dc meta ooo ooow oooc dom xforms xsd xsi">
62
63   <xsl:output method="xml" indent="yes" omit-xml-declaration="no"
64     doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"
65     doctype-system="http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"/>
66    
67   <!--
68   Parameter used to determine which top element the resulting tree will have.
69   This parameter can be overridden by passing a parameter to the XSLT processor.
70   Supported DocBook top elements are: article, book.
71   It defaults to "article".
72   -->
73 <xsl:param name="topElementName">book</xsl:param>
74 <xsl:param name="topElementMetainfoName">
75     <xsl:value-of select="concat($topElementName, 'info')"/>
76 </xsl:param>
77
78 <!-- Which unit to use -->
79 <xsl:param name="measureUnit">
80     <xsl:choose>
81         <xsl:when test="//table:table">
82             <xsl:call-template name="measureUnit"/>
83         </xsl:when>
84         <xsl:otherwise>
85             <xsl:value-of select="'unknown'"/>
86         </xsl:otherwise>
87     </xsl:choose>
88 </xsl:param>
89  
90 <xsl:variable name="oooGenerator" select="/office:document/office:meta/meta:generator"/>
91 <xsl:variable name="oooVersion">
92     <xsl:value-of select="substring-before(substring-after($oooGenerator, 'org/'), ' ')"/>
93 </xsl:variable>
94
95 <xsl:template name="measureUnit">
96     <xsl:param name="firstValue" select="//style:page-layout-properties[1]/@fo:page-width"/>
97     <xsl:if test="contains(string($firstValue), 'mm')">
98       <xsl:value-of select="'mm'"/>
99     </xsl:if>
100     <xsl:if test="contains(string($firstValue), 'cm')">
101       <xsl:value-of select="'cm'"/>
102     </xsl:if>
103     <xsl:if test="contains(string($firstValue), 'inch')">
104       <xsl:value-of select="'inch'"/>
105     </xsl:if>
106     <xsl:if test="contains(string($firstValue), 'pi')">
107       <xsl:value-of select="'pi'"/>
108     </xsl:if>
109     <xsl:if test="contains(string($firstValue), 'pt')">
110       <xsl:value-of select="'pt'"/>
111     </xsl:if>
112     <xsl:if test="contains(string($firstValue), '%')">
113       <xsl:value-of select="'%'"/>
114     </xsl:if>
115   </xsl:template>
116
117   <!--
118   When called with the right parameters this template ouputs a
119   processing-instruction specifying the print-orientation for the element that
120   has the given style.
121
122   Examples:
123   <?print-orientation portrait?>
124   <?print-orientation landscape?>
125
126   Details given in the getPrintOrientation template.
127   -->
128   <xsl:template name="outputPrintOrientation">
129     <!-- Mandatory param -->
130     <xsl:param name="styleName"/>
131     <!-- Optional param -->
132     <xsl:param name="parentStyleName" select="''"/>
133
134     <xsl:variable name="printOrientation">
135       <xsl:call-template name="getPrintOrientation">
136     <xsl:with-param name="styleName" select="$styleName"/>
137     <xsl:with-param name="parentStyleName" select="$parentStyleName"/>
138       </xsl:call-template>
139     </xsl:variable>
140     <xsl:if test="string($printOrientation)">
141       <xsl:processing-instruction name="print-orientation">
142     <xsl:value-of select="$printOrientation"/>
143       </xsl:processing-instruction>
144     </xsl:if>
145   </xsl:template>
146
147
148   <!--
149   Return a string of styles having page orientation information.
150   Example of output of this template:
151   P1,portrait;P9,portrait;P14,portrait;P19,landscape;P20,landscape;P21,portrait;
152   -->
153   <xsl:variable name="styleNamesPrintOrientations">
154     <xsl:for-each select="/office:document/office:automatic-styles/style:page-layout">
155       <xsl:variable name="printOrientation" select="style:page-layout-properties/@style:print-orientation"/>
156       <xsl:variable name="pageMasterName" select="@style:name"/>
157
158         <!--<DEBUG><xsl:value-of select="$printOrientation"/></DEBUG>
159         <DEBUG><xsl:value-of select="$pageMasterName"/></DEBUG> -->
160
161       <xsl:for-each select="//style:master-page[@style:page-layout-name = $pageMasterName]">
162             <xsl:variable name="masterPageName" select="@style:name"/>
163             <!--<DEBUG><xsl:value-of select="$masterPageName"/></DEBUG>-->
164
165             <xsl:for-each select="//style:style[@style:master-page-name = $masterPageName]">
166                 <xsl:value-of select="concat(@style:name, ',')"/>
167                 <xsl:value-of select="concat($printOrientation, ';')"/>
168             </xsl:for-each>
169       </xsl:for-each>
170     </xsl:for-each>
171   </xsl:variable>
172
173   <!--
174   When called with the right parameters this template returns the
175   print-orientation for the element that has the given style.
176
177   Details:
178   The style given to this template should be used the style of a text:h element
179   used for defining a part (not in the DocBook or OOo sense) of the OOo
180   document. So for example the style could be the one of the title (text:h) of
181   the main content or an appendix.
182
183   How it works:
184   1. It looks for the page corresponding to the style:master-page-name of the
185      given style (contained in the styles.xml file).
186   2. It looks for the print-orientation of the page.
187   -->
188   <xsl:template name="getPrintOrientation">
189     <!-- Mandatory param -->
190     <xsl:param name="styleName"/>
191     <!-- Optional param -->
192     <xsl:param name="parentStyleName" select="''"/>
193    
194     <!-- Implementation finding print-orientation from precomputed list -->
195     <xsl:value-of select="substring-before(
196       substring-after($styleNamesPrintOrientations, concat($styleName, ',')),
197       ';')"/>
198     <xsl:if test="string($parentStyleName)">
199       <xsl:value-of select="substring-before(
200     substring-after($styleNamesPrintOrientations, concat($parentStyleName, ',')),
201     ';')"/>
202     </xsl:if>
203
204     <!-- Implementation finding print-orientation dynamically -->
205     <!--
206     <xsl:for-each select="//style:style[@style:name = $styleName]">
207       <xsl:variable name="masterPageName" select="@style:master-page-name"/>
208       <xsl:for-each select="//style:master-page[@style:name = $masterPageName]">
209     <xsl:variable name="pageMasterName" select="@style:page-master-name"/>
210     <xsl:for-each select="//style:page-master[@style:name = $pageMasterName]">
211       <xsl:value-of select="style:properties/@style:print-orientation"/>
212     </xsl:for-each>
213       </xsl:for-each>
214     </xsl:for-each>
215     -->
216   </xsl:template>
217
218   <!--
219   =============
220   DOCUMENT ROOT
221   =============
222   -->
223   <xsl:template match="/">
224     <xsl:element name="{$topElementName}">
225       <xsl:attribute name="lang">
226     <xsl:value-of select="/office:document/office:meta/dc:language"/>
227       </xsl:attribute>
228
229       <xsl:processing-instruction name="ooogenerator">
230     <xsl:value-of select="$oooGenerator"/>
231       </xsl:processing-instruction>
232       <xsl:processing-instruction name="oooversion">
233     <xsl:value-of select="$oooVersion"/>
234       </xsl:processing-instruction>
235
236 <!--
237     <DEBUG><xsl:value-of select="$measureUnit"/></DEBUG>
238     <DEBUG><xsl:value-of select="$styleNamesPrintOrientations"/></DEBUG>
239 -->
240     <xsl:call-template name="metaInfo"/>
241
242       <!--
243       Only books can have preface elements.
244       A book might have both a Foreword and an Introduction.
245       Both should be tagged as preface.
246       -->
247     <xsl:if test="$topElementName='book'">
248         <xsl:call-template name="preface"/>
249     </xsl:if>
250
251       <!-- We start with the first title of level 1 -->
252       <xsl:choose>
253         <xsl:when test="/office:document/office:body/office:text/text:h[@text:outline-level='1']">
254             <xsl:apply-templates
255             select="/office:document/office:body/office:text/text:h[@text:outline-level='1'][1]"
256             mode="hierarchy">
257             <xsl:with-param name="source" select="$topElementName"/>
258             </xsl:apply-templates>
259         </xsl:when>
260         <xsl:otherwise>
261             <xsl:apply-templates select="/office:document/office:body/office:text"
262             mode="noHierarchy"/>
263         </xsl:otherwise>
264       </xsl:choose>
265
266       <xsl:call-template name="appendix"/>
267       <xsl:call-template name="bibliography"/>
268       <xsl:call-template name="glossary"/>
269       <xsl:call-template name="index"/>
270     </xsl:element>
271   </xsl:template>
272
273
274   <!--
275   =============================
276   CHAPTER AND SECTION HIERARCHY
277   =============================
278   -->
279
280   <xsl:template match="*|@*" name="hierarchy" mode="hierarchy">
281     <!-- Specify which element calls this template (optional) -->
282     <xsl:param name="source"/>
283     <!-- Store the current depth level (1, 2, etc.) (optional) -->
284     <xsl:param name="level" select="'0'"/>
285     <!--
286     Specify the id of the node you don't want to have in the result set
287     (optional)
288     -->
289     <xsl:param name="excludeNodeId"/>
290
291     <xsl:choose>
292
293       <!-- If the matched element is not a title (text:h) -->
294       <xsl:when test="name(.) != 'text:h'">
295             <xsl:call-template name="allTags">
296               <xsl:with-param name="source" select="'hierarchy'"/>
297             </xsl:call-template>
298             <xsl:apply-templates select="following-sibling::*[1]" mode="hierarchy">
299               <xsl:with-param name="level" select="$level"/>
300             </xsl:apply-templates>
301       </xsl:when>
302
303       <!-- If the matched element is a title (text:h)
304       and is deeper (level) than the preceding title -->
305       <xsl:when test="@text:outline-level > $level">
306
307     <!--
308     If we want to produce an article it is possible to have paras
309     preceding the 1st title at level 1. We want to have those paras too
310     when a preface or an appendix is encountered.
311     So those instructions are used to display paras that could occur
312     before any title is encountered.
313     The only case when we don't want to have preceding paras is when the
314     source is a book element, the source being the element calling the
315     template, which means that a preface in a book can have paras before its
316     first title, but chapters in a book cannot have paras before their
317     first title.
318     -->
319     <xsl:if test="$source != 'book'
320       and count(preceding-sibling::text:h[@text:outline-level='1']) = 0">
321       <xsl:apply-templates select="preceding-sibling::*[
322         generate-id(.) != $excludeNodeId]" mode="noHierarchy"/>
323     </xsl:if>
324
325     <!--
326     We construct a new section (sectn) and the content of the "h" source
327     element is placed into the "title" output element.
328     -->
329         <!-- Debug
330         <level><xsl:value-of select="$level"/></level>
331         <source><xsl:value-of select="$source"/></source>-->
332
333     <xsl:if test="$level >= 0">
334       <xsl:variable name="structuringElementName">
335         <xsl:choose>
336           <xsl:when test="$level=0 and $source='book'">
337         <xsl:value-of select="'chapter'"/>
338           </xsl:when>
339           <xsl:otherwise>
340         <xsl:value-of select="'section'"/>
341           </xsl:otherwise>
342         </xsl:choose>
343       </xsl:variable>
344       <xsl:element name="{$structuringElementName}">
345
346         <!-- rajout MT recherche si bookmark pour les titres et sections
347                      si oui on met un id -->
348         <xsl:call-template name="GenereIdSection" select="/text:bookmark-start"/>
349         <!-- fin rajout MT-->
350
351         <xsl:call-template name="outputPrintOrientation">
352           <xsl:with-param name="styleName" select="@text:style-name"/>
353         </xsl:call-template>
354         <title><xsl:apply-templates/></title>
355         <xsl:apply-templates select="following-sibling::*[1]" mode="hierarchy">
356           <xsl:with-param name="level" select="@text:outline-level"/>
357           <xsl:with-param name="source" select="$source"/>
358         </xsl:apply-templates>
359       </xsl:element>
360     </xsl:if>
361
362     <xsl:apply-templates select="following-sibling::*[1]" mode="scanLevel">
363       <xsl:with-param name="level" select="@text:outline-level"/>
364       <xsl:with-param name="source" select="$source"/>
365     </xsl:apply-templates>
366
367       </xsl:when>
368
369     </xsl:choose>
370   </xsl:template>
371
372   <xsl:template match="*" mode="scanLevel">
373     <xsl:param name="level" select="'0'"/>
374     <xsl:param name="source"/>
375     <xsl:choose>
376       <xsl:when test="@text:outline-level &lt; $level"/>
377       <xsl:when test="@text:outline-level = $level">
378     <xsl:call-template name="hierarchy">
379       <xsl:with-param name="level" select="$level - 1"/>
380       <xsl:with-param name="source" select="$source"/>
381     </xsl:call-template>
382       </xsl:when>
383       <xsl:otherwise>
384     <xsl:apply-templates select="following-sibling::*[1]" mode="scanLevel">
385       <xsl:with-param name="level" select="$level"/>
386       <xsl:with-param name="source" select="$source"/>
387     </xsl:apply-templates>
388       </xsl:otherwise>
389     </xsl:choose>
390   </xsl:template>
391
392   <xsl:template match="/office:document/office:body/office:text" mode="noHierarchy">
393     <xsl:apply-templates mode="noHierarchy"/>
394   </xsl:template>
395
396   <xsl:template match="*|@*" mode="noHierarchy">
397     <xsl:call-template name="allTags"/>
398   </xsl:template>
399
400 <xsl:template name="allTags">
401     <xsl:param name="source"/>
402
403     <xsl:choose>
404
405         <xsl:when test="name(current())='text:h'">
406             <xsl:choose>
407                 <xsl:when test="$source='hierarchy'"/>
408             <xsl:otherwise>
409                 <para>ERROR: Title hierarchy is wrong, section title is in bad position.</para>
410             </xsl:otherwise>
411             </xsl:choose>
412         </xsl:when>
413
414         <xsl:when test="name(current())='text:p'">
415             <xsl:call-template name="para">
416                 <xsl:with-param name="source" select="$source"/>
417             </xsl:call-template>
418         </xsl:when>
419
420     <!-- Traitement des liste avec la version 2-->
421
422         <xsl:when test="name(current())='text:list'">
423             <xsl:call-template name="ListesV2"/>
424         </xsl:when>
425
426
427         <xsl:when test="name(current())='table:table'">
428             <xsl:choose>
429                 <xsl:when test="$source='cellTable'">
430                     <para>ERROR: Section title should not be in a cell.</para>
431                 </xsl:when>
432                 <xsl:otherwise>
433                     <xsl:call-template name="table"/>
434                 </xsl:otherwise>
435             </xsl:choose>
436         </xsl:when>
437
438     </xsl:choose>
439 </xsl:template>
440
441
442   <!--
443   ========
444   METAINFO
445   ========
446   -->
447
448   <xsl:template match="/office:document/office:meta"/>
449   <xsl:template match="text:p"/>
450
451   <xsl:template name="metaInfo">
452     <xsl:param name="bodyRootPara" select="/office:document/office:body/office:text/text:p"/>
453     <xsl:element name="{$topElementMetainfoName}">
454       <xsl:apply-templates select="$bodyRootPara" mode="metaInfo"/>
455       <xsl:apply-templates select="/office:document/office:meta/dc:title"/>
456       <xsl:apply-templates select="/office:document/office:meta/dc:date"/>
457       <xsl:apply-templates select="/office:document/office:meta/dc:subject"/>
458       <xsl:element name="keywordset">
459         <xsl:apply-templates select="/office:document/office:meta/meta:keyword"/>
460       </xsl:element>
461       <xsl:call-template name="abstract"/>
462       <xsl:call-template name="userFields"/>
463     </xsl:element>
464   </xsl:template>
465
466
467   <xsl:template name="userFields">
468     <xsl:call-template name="metainfoUserFields"/>
469     <xsl:call-template name="authorUserFields"/>
470     <xsl:call-template name="publisherUserFields"/>
471     <xsl:call-template name="contractsponsorUserFields"/>
472     <xsl:call-template name="conferenceUserFields"/>
473   </xsl:template>
474
475
476   <xsl:template name="metainfoUserFields">
477     <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
478       text:user-field-decl[@office:string-value!=''
479       and starts-with(@text:name, 'metainfo_')]">
480       <xsl:if test="@text:name='metainfo_subtitle'">
481             <subtitle>
482               <xsl:value-of select="@office:string-value"/>
483             </subtitle>
484       </xsl:if>
485       <xsl:if test="@text:name='metainfo_date'">
486             <date>
487               <xsl:value-of select="@office:string-value"/>
488             </date>
489       </xsl:if>
490
491       <xsl:if test="@text:name='metainfo_abstract'">
492             <abstract>
493               <para>
494                 <xsl:value-of select="@office:string-value"/>
495               </para>
496             </abstract>
497       </xsl:if>
498
499       <xsl:if test="@text:name='metainfo_bibliomisc'">
500             <bibliomisc>
501               <xsl:value-of select="@office:string-value"/>
502             </bibliomisc>
503       </xsl:if>
504
505       <xsl:if test="@text:name='metainfo_volumenum'">
506             <volumenum>
507               <xsl:value-of select="@office:string-value"/>
508             </volumenum>
509       </xsl:if>
510
511       <xsl:if test="@text:name='metainfo_seriesvolnums'">
512             <seriesvolnums>
513               <xsl:value-of select="@office:string-value"/>
514             </seriesvolnums>
515       </xsl:if>
516
517       <xsl:if test="@text:name='metainfo_contractnum'">
518             <contractnum>
519               <xsl:value-of select="@office:string-value"/>
520             </contractnum>
521       </xsl:if>
522
523       <xsl:if test="@text:name='metainfo_isbn'">
524             <biblioid class="isbn">
525               <xsl:value-of select="@office:string-value"/>
526             </biblioid>
527       </xsl:if>
528
529       <xsl:if test="@text:name='metainfo_issn'">
530             <biblioid class="issn">
531               <xsl:value-of select="@office:string-value"/>
532             </biblioid>
533       </xsl:if>
534
535       <xsl:if test="@text:name='metainfo_isrn'">
536             <biblioid class="isrn">
537               <xsl:value-of select="@office:string-value"/>
538             </biblioid>
539       </xsl:if>
540     </xsl:for-each>
541   </xsl:template>
542
543   <xsl:template name="conferenceUserFields">
544     <confgroup>
545     <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
546       text:user-field-decl[@office:string-value!=''
547       and starts-with(@text:name, 'metainfo_confgroup')]">
548       <xsl:if test="@text:name='metainfo_confgroup_address'">
549     <address>
550       <xsl:value-of select="@office:string-value"/>
551     </address>
552       </xsl:if>
553
554       <xsl:if test="@text:name='metainfo_confgroup_confdates'">
555     <confdates>
556       <xsl:value-of select="@office:string-value"/>
557     </confdates>
558       </xsl:if>
559
560       <xsl:if test="@text:name='metainfo_confgroup_confnum'">
561     <confnum>
562       <xsl:value-of select="@office:string-value"/>
563     </confnum>
564       </xsl:if>
565
566       <xsl:if test="@text:name='metainfo_confgroup_confsponsor'">
567     <confsponsor>
568       <xsl:value-of select="@office:string-value"/>
569     </confsponsor>
570       </xsl:if>
571
572       <xsl:if test="@text:name='metainfo_confgroup_conftitle'">
573     <conftitle>
574       <xsl:value-of select="@office:string-value"/>
575     </conftitle>
576       </xsl:if>
577
578     </xsl:for-each>
579     </confgroup>
580   </xsl:template>
581
582   <xsl:template name="authorUserFields">
583     <!--
584     Testing if there are authors to put in the authorgroup element because
585     this element cannot be empty.
586     XXX: Maybe there is way to optimize the treatments below where we test if
587     there are some nodes (text:user-field-decl) and then look for those same
588     nodes over again.
589     -->
590     <!-- tests if any author metadata exists -->
591       <xsl:variable name="hasAuthor">
592         <xsl:for-each select="/office:document/office:body/office:user-field-decls/text:user-field-decl[@text:string-value!=''
593         and starts-with(@text:name, 'metainfo_author')]">
594           <xsl:value-of select="@text:string-value"/>
595         </xsl:for-each>
596       </xsl:variable>
597
598     <xsl:if test="string($hasAuthor)">
599     <authorgroup>
600       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
601     text:user-field-decl[@office:string-value!=''
602     and starts-with(@text:name, 'metainfo_author')
603     and contains(@text:name, '_surname')]">
604     <!-- Getting the "namexxx_" string -->
605     <xsl:variable name="authorBase"
606       select="concat(substring-before(@text:name, '_'), '_',
607                      substring-before(substring-after(@text:name, '_'), '_'), '_')"/>
608     <author>
609       <xsl:variable name="firstname">
610         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
611           text:user-field-decl[@text:name=concat($authorBase, 'firstname')]">
612           <xsl:value-of select="@office:string-value"/>
613         </xsl:for-each>
614       </xsl:variable>
615       <xsl:if test="string($firstname)">
616         <firstname><xsl:value-of select="$firstname"/></firstname>
617       </xsl:if>
618
619       <xsl:variable name="surname">
620         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
621           text:user-field-decl[@text:name=concat($authorBase, 'surname')]">
622           <xsl:value-of select="@office:string-value"/>
623         </xsl:for-each>
624       </xsl:variable>
625       <xsl:if test="string($surname)">
626         <surname><xsl:value-of select="$surname"/></surname>
627       </xsl:if>
628
629       <xsl:variable name="honorific">
630         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
631           text:user-field-decl[@text:name=concat($authorBase, 'honorific')]">
632           <xsl:value-of select="@office:string-value"/>
633         </xsl:for-each>
634       </xsl:variable>
635       <xsl:if test="string($honorific)">
636         <honorific><xsl:value-of select="$honorific"/></honorific>
637       </xsl:if>
638
639         <xsl:variable name="email">
640             <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
641             text:user-field-decl[@text:name=concat($authorBase, 'email')]">
642             <xsl:value-of select="@office:string-value"/>
643             </xsl:for-each>
644         </xsl:variable>
645         <xsl:if test="string($email)">
646             <email><xsl:value-of select="$email"/></email>
647         </xsl:if>
648
649       <xsl:variable name="orgabbrev">
650         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
651           text:user-field-decl[@text:name=concat($authorBase, 'orgname_acronym')]">
652           <xsl:value-of select="@office:string-value"/>
653         </xsl:for-each>
654       </xsl:variable>
655
656       <xsl:variable name="jobtitle">
657         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
658           text:user-field-decl[@text:name=concat($authorBase, 'jobtitle')]">
659           <xsl:value-of select="@office:string-value"/>
660         </xsl:for-each>
661       </xsl:variable>
662
663       <xsl:variable name="orgname">
664         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
665           text:user-field-decl[@text:name=concat($authorBase, 'orgname')]">
666           <xsl:value-of select="@office:string-value"/>
667         </xsl:for-each>
668       </xsl:variable>
669       <xsl:variable name="orgdiv">
670         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
671           text:user-field-decl[@text:name=concat($authorBase, 'orgdiv')]">
672           <xsl:value-of select="@office:string-value"/>
673         </xsl:for-each>
674       </xsl:variable>
675       <xsl:variable name="address">
676         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
677           text:user-field-decl[@text:name=concat($authorBase, 'address')]">
678           <xsl:value-of select="@office:string-value"/>
679         </xsl:for-each>
680       </xsl:variable>
681       <xsl:if test="string($jobtitle)
682         or string($orgname) or string($orgdiv) or string($orgabbrev) or string($address)">
683         <affiliation>
684           <xsl:if test="string($orgabbrev)">
685         <shortaffil role="orgabbrev"><xsl:value-of select="$orgabbrev"/></shortaffil>
686           </xsl:if>
687           <xsl:if test="string($jobtitle)">
688         <jobtitle><xsl:value-of select="$jobtitle"/></jobtitle>
689           </xsl:if>
690           <xsl:if test="string($orgname)">
691         <orgname><xsl:value-of select="$orgname"/></orgname>
692           </xsl:if>
693           <xsl:if test="string($orgdiv)">
694         <orgdiv><xsl:value-of select="$orgdiv"/></orgdiv>
695           </xsl:if>
696           <xsl:if test="string($address)">
697         <address><xsl:value-of select="$address"/></address>
698           </xsl:if>
699         </affiliation>
700       </xsl:if>
701     </author>
702       </xsl:for-each>
703     </authorgroup>
704    </xsl:if>
705   </xsl:template>
706
707
708   <xsl:template name="publisherUserFields">
709     <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
710       text:user-field-decl[
711       @office:string-value != ''
712       and starts-with(@text:name, 'metainfo_corpauthor')
713       and contains(@text:name, '_orgname')
714       and substring-after(@text:name, '_orgname') = ''
715       ]">
716       <!-- Getting the "corpauthorxxx_" string -->
717       <xsl:variable name="authorBase"
718       select="concat(substring-before(@text:name, '_'), '_',
719                      substring-before(substring-after(@text:name, '_'), '_'), '_')"/>
720       <publisher>
721     <xsl:variable name="name">
722       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
723         text:user-field-decl[@text:name=concat($authorBase, 'orgname')]">
724         <xsl:value-of select="@office:string-value"/>
725       </xsl:for-each>
726     </xsl:variable>
727     <xsl:if test="string($name)">
728       <publishername><xsl:value-of select="$name"/></publishername>
729     </xsl:if>
730
731     <!--
732     Unused variable because there is no markup for this information
733     in DocBook yet.
734     -->
735     <xsl:variable name="orgabbrev">
736       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
737         text:user-field-decl[@text:name=concat($authorBase, 'orgname_acronym')]">
738         <xsl:value-of select="@office:string-value"/>
739       </xsl:for-each>
740     </xsl:variable>
741     <!--
742     Unused variable because there is no markup for this information
743     in DocBook yet.
744     -->
745     <xsl:variable name="orgdiv">
746       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
747         text:user-field-decl[@text:name=concat($authorBase, 'orgdiv')]">
748         <xsl:value-of select="@office:string-value"/>
749       </xsl:for-each>
750     </xsl:variable>
751
752     <xsl:variable name="street">
753       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
754         text:user-field-decl[@text:name=concat($authorBase, 'address')]">
755         <xsl:value-of select="@office:string-value"/>
756       </xsl:for-each>
757     </xsl:variable>
758     <xsl:variable name="pob">
759       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
760         text:user-field-decl[@text:name=concat($authorBase, 'pob')]">
761         <xsl:value-of select="@office:string-value"/>
762       </xsl:for-each>
763     </xsl:variable>
764     <xsl:variable name="postcode">
765       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
766         text:user-field-decl[@text:name=concat($authorBase, 'postcode')]">
767         <xsl:value-of select="@office:string-value"/>
768       </xsl:for-each>
769     </xsl:variable>
770     <xsl:variable name="city">
771       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
772         text:user-field-decl[@text:name=concat($authorBase, 'city')]">
773         <xsl:value-of select="@office:string-value"/>
774       </xsl:for-each>
775     </xsl:variable>
776     <xsl:variable name="state">
777       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
778         text:user-field-decl[@text:name=concat($authorBase, 'state')]">
779         <xsl:value-of select="@office:string-value"/>
780       </xsl:for-each>
781     </xsl:variable>
782     <xsl:variable name="phone">
783       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
784         text:user-field-decl[@text:name=concat($authorBase, 'phone')]">
785         <xsl:value-of select="@office:string-value"/>
786       </xsl:for-each>
787     </xsl:variable>
788     <xsl:variable name="fax">
789       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
790         text:user-field-decl[@text:name=concat($authorBase, 'fax')]">
791         <xsl:value-of select="@office:string-value"/>
792       </xsl:for-each>
793     </xsl:variable>
794     <xsl:variable name="email">
795       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
796         text:user-field-decl[@text:name=concat($authorBase, 'email')]">
797         <xsl:value-of select="@office:string-value"/>
798       </xsl:for-each>
799     </xsl:variable>
800     <xsl:variable name="ulink">
801       <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
802         text:user-field-decl[@text:name=concat($authorBase, 'ulink')]">
803         <xsl:value-of select="@office:string-value"/>
804       </xsl:for-each>
805     </xsl:variable>
806
807     <xsl:if test="string($street) or string($pob) or string($postcode)
808       or string($city) or string($state)
809       or string($phone) or string($fax) or string($email) or string($ulink)">
810       <address>
811         <xsl:if test="string($street)">
812           <street><xsl:value-of select="$street"/></street>
813         </xsl:if>
814         <xsl:if test="string($pob)">
815           <pob><xsl:value-of select="$pob"/></pob>
816         </xsl:if>
817         <xsl:if test="string($postcode)">
818           <postcode><xsl:value-of select="$postcode"/></postcode>
819         </xsl:if>
820         <xsl:if test="string($city)">
821           <city><xsl:value-of select="$city"/></city>
822         </xsl:if>
823         <xsl:if test="string($state)">
824           <state><xsl:value-of select="$state"/></state>
825         </xsl:if>
826         <xsl:if test="string($phone)">
827           <phone><xsl:value-of select="$phone"/></phone>
828         </xsl:if>
829         <xsl:if test="string($fax)">
830           <fax><xsl:value-of select="$fax"/></fax>
831         </xsl:if>
832         <xsl:if test="string($email)">
833           <email><xsl:value-of select="$email"/></email>
834         </xsl:if>
835         <xsl:if test="string($ulink)">
836           <otheraddr>
837         <ulink>
838           <xsl:attribute name="url">
839             <xsl:value-of select="$ulink"/>
840           </xsl:attribute>
841           <xsl:value-of select="$ulink"/>
842         </ulink>
843           </otheraddr>
844         </xsl:if>
845       </address>
846     </xsl:if>
847       </publisher>
848     </xsl:for-each>
849   </xsl:template>
850
851
852   <xsl:template name="contractsponsorUserFields">
853     <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
854       text:user-field-decl[
855       @office:string-value!=''
856       and starts-with(@text:name, 'metainfo_contractsponsor')
857       and contains(@text:name, '_orgname')
858       and substring-after(@text:name, '_orgname') = ''
859       ]">
860       <!-- Getting the "contractsponsorxxx_" string -->
861       <xsl:variable name="authorBase"
862       select="concat(substring-before(@text:name, '_'), '_',
863                      substring-before(substring-after(@text:name, '_'), '_'), '_')"/>
864       <xsl:variable name="name">
865     <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
866       text:user-field-decl[@text:name=concat($authorBase, 'orgname')]">
867       <xsl:value-of select="@office:string-value"/>
868     </xsl:for-each>
869       </xsl:variable>
870       <xsl:variable name="street">
871         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
872           text:user-field-decl[@text:name=concat($authorBase, 'address')]">
873           <xsl:value-of select="@office:string-value"/>
874         </xsl:for-each>
875       </xsl:variable>
876       <xsl:variable name="pob">
877         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
878           text:user-field-decl[@text:name=concat($authorBase, 'pob')]">
879           <xsl:value-of select="@office:string-value"/>
880         </xsl:for-each>
881       </xsl:variable>
882       <xsl:variable name="postcode">
883         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
884           text:user-field-decl[@text:name=concat($authorBase, 'postcode')]">
885           <xsl:value-of select="@office:string-value"/>
886         </xsl:for-each>
887       </xsl:variable>
888       <xsl:variable name="city">
889         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
890           text:user-field-decl[@text:name=concat($authorBase, 'city')]">
891           <xsl:value-of select="@office:string-value"/>
892         </xsl:for-each>
893       </xsl:variable>
894       <xsl:variable name="state">
895         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
896           text:user-field-decl[@text:name=concat($authorBase, 'state')]">
897           <xsl:value-of select="@office:string-value"/>
898         </xsl:for-each>
899       </xsl:variable>
900       <xsl:variable name="phone">
901         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
902           text:user-field-decl[@text:name=concat($authorBase, 'phone')]">
903           <xsl:value-of select="@office:string-value"/>
904         </xsl:for-each>
905       </xsl:variable>
906       <xsl:variable name="fax">
907         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
908           text:user-field-decl[@text:name=concat($authorBase, 'fax')]">
909           <xsl:value-of select="@office:string-value"/>
910         </xsl:for-each>
911       </xsl:variable>
912       <xsl:variable name="email">
913         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
914           text:user-field-decl[@text:name=concat($authorBase, 'email')]">
915           <xsl:value-of select="@office:string-value"/>
916         </xsl:for-each>
917       </xsl:variable>
918       <xsl:variable name="ulink">
919         <xsl:for-each select="/office:document/office:body/office:text/text:user-field-decls/
920           text:user-field-decl[@text:name=concat($authorBase, 'ulink')]">
921           <xsl:value-of select="@office:string-value"/>
922         </xsl:for-each>
923       </xsl:variable>
924
925       <contractsponsor>
926         <xsl:value-of select="$name"/>
927         <xsl:if test="string($street) or string($pob) or string($postcode)
928           or string($city) or string($state)
929           or string($phone) or string($fax) or string($email) or string($ulink)">
930           <xsl:comment>Address</xsl:comment>
931         </xsl:if>
932         <xsl:if test="string($street)">
933           <xsl:processing-instruction name="street">
934             <xsl:value-of select="$street"/>
935           </xsl:processing-instruction>
936         </xsl:if>
937         <xsl:if test="string($pob)">
938           <xsl:processing-instruction name="pob">
939             <xsl:value-of select="$pob"/>
940           </xsl:processing-instruction>
941         </xsl:if>
942         <xsl:if test="string($postcode)">
943           <xsl:processing-instruction name="postcode">
944             <xsl:value-of select="$postcode"/>
945           </xsl:processing-instruction>
946         </xsl:if>
947         <xsl:if test="string($city)">
948           <xsl:processing-instruction name="city">
949             <xsl:value-of select="$city"/>
950           </xsl:processing-instruction>
951         </xsl:if>
952         <xsl:if test="string($state)">
953           <xsl:processing-instruction name="state">
954             <xsl:value-of select="$state"/>
955           </xsl:processing-instruction>
956         </xsl:if>
957         <xsl:if test="string($phone)">
958           <xsl:processing-instruction name="phone">
959             <xsl:value-of select="$phone"/>
960           </xsl:processing-instruction>
961         </xsl:if>
962         <xsl:if test="string($fax)">
963           <xsl:processing-instruction name="fax">
964             <xsl:value-of select="$fax"/>
965           </xsl:processing-instruction>
966         </xsl:if>
967         <xsl:if test="string($email)">
968           <xsl:processing-instruction name="email">
969             <xsl:value-of select="$email"/>
970           </xsl:processing-instruction>
971         </xsl:if>
972         <xsl:if test="string($ulink)">
973           <xsl:processing-instruction name="ulink">
974             <xsl:value-of select="$ulink"/>
975           </xsl:processing-instruction>
976         </xsl:if>
977       </contractsponsor>
978     </xsl:for-each>
979   </xsl:template>
980
981
982   <xsl:template name="keywordsetContent">
983     <!--
984     keywordsString is a string of coma separated keywords
985     Spaces can appear before or after the comas.
986     A so called keyword can contain spaces.
987     Examples:
988     keywordsString = "aaa, bbb, ccc"
989     keywordsString = "aaa  ,  bbb  ,ccc"
990     keywordsString = "a aa, b bb, ccc"
991     keywordsString = "a aa  ,  b bb  ,ccc"
992     -->
993     <xsl:param name="keywordsString"/>
994     <xsl:if test="$keywordsString">
995       <xsl:choose>
996     <xsl:when test="contains($keywordsString, ',')">
997       <keyword><xsl:value-of select="normalize-space(substring-before($keywordsString, ','))"/></keyword>
998       <xsl:call-template name="keywordsetContent">
999         <xsl:with-param name="keywordsString" select="substring-after($keywordsString, ',')"/>
1000       </xsl:call-template>
1001     </xsl:when>
1002     <xsl:otherwise>
1003       <keyword><xsl:value-of select="normalize-space($keywordsString)"/></keyword>
1004     </xsl:otherwise>
1005       </xsl:choose>
1006     </xsl:if>
1007   </xsl:template>
1008
1009
1010   <xsl:template name="authorGroupContent">
1011     <!--
1012     authorsString is a string of semi-colon separated authors
1013     Spaces can appear before or after the semi-colons.
1014     A so called author can contain spaces and a coma.
1015     If there is a coma for an author, the surname is first and then comes the
1016     surname. This could have been the other way but this is how it is defined
1017     in OOo.
1018     Examples:
1019     authorsString = "aaa; bbb; ccc"
1020     authorsString = "aaa  ;  bbb  ;ccc"
1021     authorsString = "a aa; b bb; ccc"
1022     authorsString = "a aa  ;  b bb  ;ccc"
1023     authorsString = " DOE, John  ;  Monroe, Marilyn  ;Buzz"
1024     -->
1025     <xsl:param name="authorsString"/>
1026     <xsl:if test="$authorsString">
1027       <xsl:choose>
1028     <xsl:when test="contains($authorsString, ';')">
1029       <xsl:call-template name="authorGroupContent">
1030         <xsl:with-param name="authorsString" select="substring-after($authorsString, ';')"/>
1031       </xsl:call-template>
1032     </xsl:when>
1033     <xsl:otherwise>
1034       <author>