1<?xml version='1.0' encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<xsl:stylesheet version="1.0" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:office="http://openoffice.org/2000/office" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script" xmlns:config="http://openoffice.org/2001/config" office:class="text" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="office meta table number dc fo xlink chart math script xsl draw svg dr3d form config text style">
25	<xsl:output method="xml" indent="yes" omit-xml-declaration="no" version="1.0" encoding="UTF-8" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN" doctype-system="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/>
26
27
28	<!-- Heading will be mapped to sections.
29		 In OpenDocument headings are not nested, they do not embrace their related content, the XML hierarchy has to be restructured.
30
31		Example of OpenDocument content:
32
33		<office:body>
34			<text:h text:style-name="Heading 1" text:level="1">Heading 1</text:h>
35			<text:p text:style-name="Text body">Heading 1 Content</text:p>
36			<text:h text:style-name="Heading 2" text:level="2">Heading 2</text:h>
37			<text:p text:style-name="Text body">Heading 2 Content</text:p>
38		<office:body>
39
40		Example of DocBook content:
41
42		<article lang="en-US">
43			<sect1>
44				<title>Heading 1</title>
45				<para>Heading 1 Content</para>
46				<sect2>
47					<title>Heading 2</title>
48					<para>Heading 2 Content</para>
49				</sect2>
50			</sect1>
51		</article>
52	-->
53
54	<!-- The key function "nestedContent" returns all ODF elements that are children of the current heading (i.e. text:h) or their parent office:body in case there is no text:h.
55		It works by matching all ODF elements, that text:h refer to (it's sibling or office:body childring)
56		Various keyed element sets of these matched elements are being generated. A set is identified by having the same last (closest) preceding text:h or if none exisitent the parent document.
57		All those elements, that have the current heading as last preceding heading (text:h) are returned as a nodeset.
58	-->
59	<xsl:key name="nestedContent"
60			 match="text:p | table:table | text:span | text:ordered-list | office:annotation | text:unordered-list | text:footnote | text:a | text:list-item | draw:plugin | draw:text-box | text:footnote-body | text:section"
61			 use="generate-id((.. | preceding::text:h)[last()])"/>
62
63	<!-- The key function "nestedHeadings" returns a nodeset of all heading (text:h) elements, which belong to this heading (follow and have a higher outline number than the current text:h, which ID is given to the function) -->
64	<xsl:key name="nestedHeadings"
65			 match="text:h"
66			 use="generate-id(preceding::text:h[@text:level &lt; current()/@text:level][1])"/>
67
68	<!-- The key function "getHeadingsByOutline" returns all headings of a certain outline level -->
69	<xsl:key name="getHeadingsByOutline"
70			 match="text:h"
71			 use="@text:level"/>
72
73	<!-- A further problem during mapping of Heading to sections is the quantity of levels. In OpenDocument there can exist more than 4 hierarchies (outline levels).
74	Furthermore an OpenDocument have not to start with heading outline level 1 nor does a outline level 2 have to follow.
75	Therefore all possible existing heading outline levels from 1 to 10 have to be mapped to the section1 to section4 in DocBook.
76	The lowest outline number is mapped section1, second is section2... until fourth and higher are all mapped to section4 -->
77
78	<!-- Each global variable hold the outline level which has been mapped to one of the four sections in DocBook   -->
79	<xsl:variable name="section1_OutlineLevel">
80		<xsl:call-template name="findOutlineLevel">
81			<xsl:with-param name="candidateOutlineLevel" select="1"/>
82		</xsl:call-template>
83	</xsl:variable>
84	<xsl:variable name="section2_OutlineLevel">
85		<xsl:call-template name="findOutlineLevel">
86			<xsl:with-param name="candidateOutlineLevel" select="$section1_OutlineLevel + 1"/>
87		</xsl:call-template>
88	</xsl:variable>
89	<xsl:variable name="section3_OutlineLevel">
90		<xsl:call-template name="findOutlineLevel">
91			<xsl:with-param name="candidateOutlineLevel" select="$section2_OutlineLevel + 1"/>
92		</xsl:call-template>
93	</xsl:variable>
94	<xsl:variable name="section4_OutlineLevel">
95		<xsl:call-template name="findOutlineLevel">
96			<xsl:with-param name="candidateOutlineLevel" select="$section3_OutlineLevel + 1"/>
97		</xsl:call-template>
98	</xsl:variable>
99
100	<!-- get the minimum available heading outline level (usually '1') -->
101	<xsl:template name="findOutlineLevel">
102		<xsl:param name="candidateOutlineLevel"/>
103		<xsl:choose>
104			<xsl:when test="key('getHeadingsByOutline', $candidateOutlineLevel)[1]/@text:level != ''">
105				<xsl:value-of select="$candidateOutlineLevel"/>
106			</xsl:when>
107			<xsl:otherwise>
108				<xsl:if test="$candidateOutlineLevel &lt; 11">
109					<xsl:call-template name="findOutlineLevel">
110						<xsl:with-param name="candidateOutlineLevel" select="$candidateOutlineLevel + 1"/>
111					</xsl:call-template>
112				</xsl:if>
113			</xsl:otherwise>
114		</xsl:choose>
115	</xsl:template>
116
117
118	<!-- START -->
119	<xsl:template match="/*">
120		<xsl:element name="article">
121			<xsl:attribute name="lang">
122				<xsl:value-of select="/*/office:meta/dc:language"/>
123			</xsl:attribute>
124            <!-- page style header -->
125            <xsl:call-template name="page-style">
126                <xsl:with-param name="area" select="'header'"/>
127            </xsl:call-template>
128			<xsl:apply-templates select="office:body"/>
129            <!-- page style footer -->
130            <xsl:call-template name="page-style"/>
131		</xsl:element>
132	</xsl:template>
133
134
135    <xsl:key match="style:master-page" name="styleMasterPage" use="@style:name" />
136    <!-- using a simple heuristic for "standard" page-style heading/footer from page styles -->
137    <xsl:template name="page-style">
138        <xsl:param name="area"/>
139
140        <xsl:variable name="defaultPageStyle" select="key('styleMasterPage', 'Standard')"/>
141        <xsl:choose>
142            <xsl:when test="$area = 'header'">
143                <xsl:apply-templates select="$defaultPageStyle/style:header/*"/>
144            </xsl:when>
145            <xsl:otherwise>
146                <xsl:apply-templates select="$defaultPageStyle/style:footer/*"/>
147            </xsl:otherwise>
148        </xsl:choose>
149
150    </xsl:template>
151
152	<xsl:template match="office:body">
153		<!-- here all children of office:body before the first heading are matched -->
154		<xsl:apply-templates select="key('nestedContent', generate-id())"/>
155		<!-- have to be descendant as text:h can be in a list:item in some list -->
156		<xsl:variable name="firstHeading" select="descendant::text:h[1]"/>
157		<!-- changing the context node from office:body to text:h as required for used key functions -->
158		<xsl:for-each select="descendant::text:h[@text:level=$section1_OutlineLevel][1]">
159			<!-- if the first heading is not of the section1 level -->
160			<xsl:if test="generate-id(.) != generate-id($firstHeading)">
161				<!-- create an anonymous section1 and embrace all headings preceding the first real existent section1 -->
162                <xsl:element name="sect1">
163                    <title></title>
164                    <!-- create sections for all the first section1 preluding headings -->
165                    <xsl:for-each select="key('getHeadingsByOutline', $section1_OutlineLevel)[1]/preceding::text:h">
166                        <xsl:call-template name="make-section">
167                            <xsl:with-param name="previousSectionLevel" select="$section1_OutlineLevel"/>
168                            <xsl:with-param name="currentSectionLevel">
169                                <xsl:call-template name="getSectionLevel">
170                                    <xsl:with-param name="outlineLevel" select="@text:level"/>
171                                </xsl:call-template>
172                            </xsl:with-param>
173                        </xsl:call-template>
174                    </xsl:for-each>
175                </xsl:element>
176			</xsl:if>
177		</xsl:for-each>
178		<!-- match all headings, which are mapped to section1 to create a nested section structure used in docbook (see first comment after copyright) -->
179		<xsl:apply-templates mode="recreateStructure" select="descendant::text:h[@text:level = $section1_OutlineLevel]"/>
180	</xsl:template>
181
182	<xsl:template match="text:h" mode="recreateStructure">
183		<!-- relate the current ODF outline level of the heading to one of the four docbook section levels-->
184		<xsl:variable name="currentSectionLevel">
185			<xsl:call-template name="getSectionLevel">
186				<xsl:with-param name="outlineLevel" select="@text:level"/>
187			</xsl:call-template>
188		</xsl:variable>
189		<xsl:choose>
190			<!-- heading with outline level 1 might be an Abstract  -->
191			<xsl:when test="$currentSectionLevel = 1">
192				<xsl:choose>
193					<!-- when the content of a level 1 heading is 'Abstract' the <abstract> docbook element is used instead of <section1>  -->
194					<xsl:when test=".='Abstract'">
195						<abstract>
196							<xsl:apply-templates select="key('nestedContent', generate-id())"/>
197							<xsl:apply-templates select="key('nestedHeadings', generate-id())" mode="recreateStructure"/>
198						</abstract>
199					</xsl:when>
200					<xsl:otherwise>
201						<xsl:call-template name="make-section">
202							<xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
203							<xsl:with-param name="previousSectionLevel" select="$currentSectionLevel"/>
204						</xsl:call-template>
205					</xsl:otherwise>
206				</xsl:choose>
207			</xsl:when>
208			<xsl:otherwise>
209				<xsl:variable name="previousHeading" select="preceding::text:h[@text:level &lt; current()/@text:level][1]"/>
210				<xsl:choose>
211					<xsl:when test="$previousHeading/@text:level != ''">
212						<xsl:call-template name="make-section">
213							<xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
214							<xsl:with-param name="previousSectionLevel">
215								<xsl:call-template name="getSectionLevel">
216									<xsl:with-param name="outlineLevel" select="$previousHeading/@text:level"/>
217								</xsl:call-template>
218							</xsl:with-param>
219						</xsl:call-template>
220					</xsl:when>
221					<xsl:otherwise>
222						<xsl:call-template name="make-section">
223							<xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
224							<xsl:with-param name="previousSectionLevel" select="$currentSectionLevel"/>
225						</xsl:call-template>
226					</xsl:otherwise>
227				</xsl:choose>
228			</xsl:otherwise>
229		</xsl:choose>
230	</xsl:template>
231
232	<xsl:template match="text:bookmark | text:bookmark-start">
233		<xsl:element name="anchor">
234			<xsl:attribute name="id">
235				<!-- ID have to be an NCName which have to start with a letter or '_'
236					in case of the frequent starting number a '_' will be added as prefix -->
237				<xsl:choose>
238					<xsl:when test="(starts-with(@text:name, '0') or
239                                     starts-with(@text:name, '1') or
240                                     starts-with(@text:name, '2') or
241                                     starts-with(@text:name, '3') or
242                                     starts-with(@text:name, '4') or
243                                     starts-with(@text:name, '5') or
244                                     starts-with(@text:name, '6') or
245                                     starts-with(@text:name, '7') or
246                                     starts-with(@text:name, '8') or
247                                     starts-with(@text:name, '9'))">
248						<xsl:value-of select="concat('_', @text:name)"/>
249					</xsl:when>
250					<xsl:otherwise>
251						<xsl:value-of select="@text:name"/>
252					</xsl:otherwise>
253				</xsl:choose>
254			</xsl:attribute>
255		</xsl:element>
256	</xsl:template>
257
258	<xsl:template name="getSectionLevel">
259		<xsl:param name="outlineLevel"/>
260		<xsl:choose>
261			<xsl:when test="$outlineLevel = $section1_OutlineLevel">1</xsl:when>
262			<xsl:when test="$outlineLevel = $section2_OutlineLevel">2</xsl:when>
263			<xsl:when test="$outlineLevel = $section3_OutlineLevel">3</xsl:when>
264			<xsl:otherwise>4</xsl:otherwise>
265		</xsl:choose>
266	</xsl:template>
267
268	<!-- make-section creates the nested section hierarchy and
269		 in case the difference between the parent section and the new section is higher than one
270		 a section is inserted to keep the output format valid  -->
271	<xsl:template name="make-section">
272		<xsl:param name="currentSectionLevel"/>
273		<xsl:param name="previousSectionLevel"/>
274		<xsl:choose>
275			<!-- empty title as it is an empty section between two headings with an outline level difference higher than 1 -->
276			<xsl:when test="$currentSectionLevel &gt; $previousSectionLevel+1">
277                <xsl:element name="{concat('sect', $previousSectionLevel + 1)}">
278                    <title></title>
279                    <xsl:call-template name="make-section">
280                        <xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
281                        <xsl:with-param name="previousSectionLevel" select="$previousSectionLevel +1"/>
282                    </xsl:call-template>
283                </xsl:element>
284			</xsl:when>
285			<xsl:otherwise>
286                <xsl:element name="{concat('sect', $currentSectionLevel)}">
287                    <title>
288                        <xsl:apply-templates/>
289                    </title>
290                    <xsl:apply-templates select="key('nestedContent', generate-id())"/>
291                    <xsl:apply-templates select="key('nestedHeadings', generate-id())" mode="recreateStructure"/>
292                </xsl:element>
293			</xsl:otherwise>
294		</xsl:choose>
295	</xsl:template>
296
297
298	<xsl:template match="office:meta">
299	<!--<xsl:apply-templates/>--></xsl:template>
300
301	<xsl:template match="meta:editing-cycles"></xsl:template>
302
303	<xsl:template match="meta:user-defined"></xsl:template>
304
305	<xsl:template match="meta:editing-duration"></xsl:template>
306
307	<xsl:template match="dc:language"></xsl:template>
308
309	<xsl:template match="dc:date">
310	<!--<pubdate>
311		<xsl:value-of select="substring-before(.,'T')"/>
312	</pubdate>--></xsl:template>
313
314	<xsl:template match="meta:creation-date"></xsl:template>
315
316	<xsl:template match="office:styles">
317		<xsl:apply-templates/>
318	</xsl:template>
319
320	<xsl:template match="office:script"></xsl:template>
321
322
323	<xsl:template match="office:settings"></xsl:template>
324
325	<xsl:template match="office:font-decls"></xsl:template>
326
327	<xsl:template match="text:section">
328		<xsl:choose>
329			<xsl:when test="@text:name='ArticleInfo'">
330				<articleinfo>
331					<title>
332						<xsl:value-of select="text:p[@text:style-name='Document Title']"/>
333					</title>
334					<subtitle>
335						<xsl:value-of select="text:p[@text:style-name='Document SubTitle']"/>
336					</subtitle>
337					<edition>
338						<xsl:value-of select="text:p/text:variable-set[@text:name='articleinfo.edition']"/>
339					</edition>
340					<xsl:for-each select="text:p/text:variable-set[substring-after(@text:name,'articleinfo.releaseinfo')]">
341						<releaseinfo>
342							<xsl:value-of select="."/>
343						</releaseinfo>
344					</xsl:for-each>
345					<xsl:call-template name="ArticleInfo">
346						<xsl:with-param name="level" select="0"/>
347					</xsl:call-template>
348				</articleinfo>
349			</xsl:when>
350			<xsl:when test="@text:name='Abstract'">
351				<abstract>
352					<xsl:apply-templates/>
353				</abstract>
354			</xsl:when>
355			<xsl:when test="@text:name='Appendix'">
356				<appendix>
357					<xsl:apply-templates/>
358				</appendix>
359			</xsl:when>
360			<xsl:otherwise>
361                <xsl:element name="{concat('sect', count(ancestor::text:section) + 1)}">
362                    <xsl:attribute name="id">
363                        <xsl:value-of select="@text:name"/>
364                    </xsl:attribute>
365                    <xsl:apply-templates/>
366                </xsl:element>
367			</xsl:otherwise>
368		</xsl:choose>
369	</xsl:template>
370
371	<xsl:template name="ArticleInfo">
372		<xsl:param name="level"/>
373		<xsl:variable name="author">
374			<xsl:value-of select="concat('articleinfo.author_','', $level)"/>
375		</xsl:variable>
376		<xsl:if test="text:p/text:variable-set[contains(@text:name, $author )]">
377			<xsl:call-template name="Author">
378				<xsl:with-param name="AuthorLevel" select="0"/>
379			</xsl:call-template>
380			<xsl:call-template name="Copyright">
381				<xsl:with-param name="CopyrightLevel" select="0"/>
382			</xsl:call-template>
383		</xsl:if>
384	</xsl:template>
385
386	<xsl:template name="Copyright">
387		<xsl:param name="CopyrightLevel"/>
388
389		<xsl:variable name="Copyright">
390			<xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
391		</xsl:variable>
392
393		<xsl:if test="text:p/text:variable-set[contains(@text:name,$Copyright)]">
394			<copyright>
395				<xsl:call-template name="Year">
396					<xsl:with-param name="CopyrightLevel" select="$CopyrightLevel"/>
397					<xsl:with-param name="YearlLevel" select="0"/>
398				</xsl:call-template>
399				<xsl:call-template name="Holder">
400					<xsl:with-param name="CopyrightLevel" select="$CopyrightLevel"/>
401					<xsl:with-param name="HolderlLevel" select="0"/>
402
403				</xsl:call-template>
404			</copyright>
405		</xsl:if>
406	</xsl:template>
407
408
409	<xsl:template name="Year">
410		<xsl:param name="CopyrightLevel"/>
411		<xsl:param name="YearLevel"/>
412		<xsl:variable name="Copyright">
413			<xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
414		</xsl:variable>
415		<xsl:variable name="Year">
416			<xsl:value-of select="concat($Copyright,'',concat('.year_','',$YearLevel))"/>
417		</xsl:variable>
418
419		<xsl:if test="text:p/text:variable-set[@text:name=$Year]">
420			<orgname>
421				<xsl:value-of select="text:p/text:variable-set[@text:name=$Year]"/>
422			</orgname>
423		</xsl:if>
424	</xsl:template>
425
426
427	<xsl:template name="Holder">
428		<xsl:param name="CopyrightLevel"/>
429		<xsl:param name="HolderLevel"/>
430		<xsl:variable name="Copyright">
431			<xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
432		</xsl:variable>
433		<xsl:variable name="Holder">
434			<xsl:value-of select="concat($Copyright,'',concat('.holder_','',$HolderLevel))"/>
435		</xsl:variable>
436
437		<xsl:if test="text:p/text:variable-set[@text:name=$Holder]">
438			<orgname>
439				<xsl:value-of select="text:p/text:variable-set[@text:name=$Holder]"/>
440			</orgname>
441		</xsl:if>
442	</xsl:template>
443
444
445
446	<xsl:template name="Author">
447		<xsl:param name="AuthorLevel"/>
448		<xsl:variable name="Author">
449			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
450		</xsl:variable>
451		<xsl:if test="text:p/text:variable-set[contains(@text:name, $Author )]">
452			<author>
453				<xsl:call-template name="Surname">
454					<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
455					<xsl:with-param name="SurnameLevel" select="0"/>
456				</xsl:call-template>
457				<xsl:call-template name="Firstname">
458					<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
459					<xsl:with-param name="FirstnameLevel" select="0"/>
460				</xsl:call-template>
461				<xsl:call-template name="Affiliation">
462					<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
463					<xsl:with-param name="AffilLevel" select="0"/>
464				</xsl:call-template>
465			</author>
466			<xsl:call-template name="Author">
467				<xsl:with-param name="AuthorLevel" select="$AuthorLevel+1"/>
468			</xsl:call-template>
469		</xsl:if>
470	</xsl:template>
471
472
473	<xsl:template name="Surname">
474		<xsl:param name="AuthorLevel"/>
475		<xsl:param name="SurnameLevel"/>
476		<xsl:variable name="Author">
477			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
478		</xsl:variable>
479		<xsl:variable name="Surname">
480			<xsl:value-of select="concat($Author,'',concat('.surname_','',$SurnameLevel))"/>
481		</xsl:variable>
482		<xsl:if test="text:p/text:variable-set[@text:name=$Surname]">
483			<surname>
484				<xsl:value-of select="text:p/text:variable-set[@text:name=$Surname]"/>
485			</surname>
486			<xsl:call-template name="Surname">
487				<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
488				<xsl:with-param name="SurnameLevel" select="SurnameLevel+1"/>
489			</xsl:call-template>
490
491		</xsl:if>
492	</xsl:template>
493
494
495
496
497	<xsl:template name="Firstname">
498		<xsl:param name="AuthorLevel"/>
499		<xsl:param name="FirstnameLevel"/>
500		<xsl:variable name="Author">
501			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
502		</xsl:variable>
503		<xsl:variable name="Firstname">
504			<xsl:value-of select="concat($Author,'',concat('.firstname_','',$FirstnameLevel))"/>
505		</xsl:variable>
506		<xsl:if test="text:p/text:variable-set[@text:name=$Firstname]">
507			<firstname>
508				<xsl:value-of select="text:p/text:variable-set[@text:name=$Firstname]"/>
509			</firstname>
510			<xsl:call-template name="Surname">
511				<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
512				<xsl:with-param name="FirstnameLevel" select="FirstnameLevel+1"/>
513			</xsl:call-template>
514		</xsl:if>
515	</xsl:template>
516
517
518
519	<xsl:template name="Affiliation">
520		<xsl:param name="AuthorLevel"/>
521		<xsl:param name="AffilLevel"/>
522		<xsl:variable name="Author">
523			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
524		</xsl:variable>
525		<xsl:variable name="Affil">
526			<xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
527		</xsl:variable>
528		<xsl:if test="text:p/text:variable-set[contains(@text:name,$Affil)]">
529			<affiliation>
530				<xsl:call-template name="Orgname">
531					<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
532					<xsl:with-param name="AffilLevel" select="$AffilLevel"/>
533					<xsl:with-param name="OrgLevel" select="0"/>
534				</xsl:call-template>
535				<xsl:call-template name="Address">
536					<xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
537					<xsl:with-param name="AffilLevel" select="$AffilLevel"/>
538					<xsl:with-param name="AddressLevel" select="0"/>
539
540				</xsl:call-template>
541			</affiliation>
542		</xsl:if>
543	</xsl:template>
544
545	<xsl:template name="Orgname">
546		<xsl:param name="AuthorLevel"/>
547		<xsl:param name="AffilLevel"/>
548		<xsl:param name="OrgLevel"/>
549
550		<xsl:variable name="Author">
551			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
552		</xsl:variable>
553		<xsl:variable name="Affil">
554			<xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
555		</xsl:variable>
556		<xsl:variable name="Org">
557			<xsl:value-of select="concat($Affil,'',concat('.orgname_','',$OrgLevel))"/>
558		</xsl:variable>
559
560		<xsl:if test="text:p/text:variable-set[@text:name=$Org]">
561			<orgname>
562				<xsl:value-of select="text:p/text:variable-set[@text:name=$Org]"/>
563			</orgname>
564		</xsl:if>
565	</xsl:template>
566
567	<xsl:template name="Address">
568		<xsl:param name="AuthorLevel"/>
569		<xsl:param name="AffilLevel"/>
570		<xsl:param name="AddressLevel"/>
571
572		<xsl:variable name="Author">
573			<xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
574		</xsl:variable>
575		<xsl:variable name="Affil">
576			<xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
577		</xsl:variable>
578		<xsl:variable name="Address">
579			<xsl:value-of select="concat($Affil,'',concat('.address_','',$AddressLevel))"/>
580		</xsl:variable>
581
582		<xsl:if test="text:p/text:variable-set[@text:name=$Address]">
583			<address>
584				<xsl:value-of select="text:p/text:variable-set[@text:name=$Address]"/>
585			</address>
586		</xsl:if>
587	</xsl:template>
588
589
590
591
592	<xsl:template match="text:p[@text:style-name='Document Title']"></xsl:template>
593
594	<xsl:template match="text:p[@text:style-name='Document SubTitle']"></xsl:template>
595
596
597	<xsl:template match="text:p[@text:style-name='Section Title']">
598		<xsl:element name="title">
599			<xsl:apply-templates/>
600		</xsl:element>
601	</xsl:template>
602
603	<xsl:template match="text:p[@text:style-name='Appendix Title']">
604		<xsl:element name="title">
605			<xsl:apply-templates/>
606		</xsl:element>
607	</xsl:template>
608
609
610<!--<xsl:template match="text:p[@text:style-name='VarList Item']">
611	<xsl:if test="not(preceding-sibling::text:p[@text:style-name='VarList Item'])">
612		<xsl:text disable-output-escaping="yes">&lt;listitem&gt;</xsl:text>
613	</xsl:if>
614		<para>
615			<xsl:apply-templates/>
616		</para>
617	<xsl:if test="not(following-sibling::text:p[@text:style-name='VarList Item'])">
618		<xsl:text disable-output-escaping="yes">&lt;/listitem&gt;</xsl:text>
619	</xsl:if>
620</xsl:template>-->
621
622
623	<xsl:template match="text:p[@text:style-name='Section1 Title']">
624		<xsl:element name="title">
625			<xsl:apply-templates/>
626		</xsl:element>
627	</xsl:template>
628
629
630	<xsl:template match="text:p[@text:style-name='Section2 Title']">
631		<xsl:element name="title">
632			<xsl:apply-templates/>
633		</xsl:element>
634	</xsl:template>
635
636
637	<xsl:template match="text:p[@text:style-name='Section3 Title']">
638		<xsl:element name="title">
639			<xsl:apply-templates/>
640		</xsl:element>
641	</xsl:template>
642
643	<xsl:template match="text:footnote-citation"></xsl:template>
644
645	<xsl:template match="text:p[@text:style-name='Mediaobject']">
646		<mediaobject>
647			<xsl:apply-templates/>
648		</mediaobject>
649	</xsl:template>
650
651	<xsl:template match="office:annotation/text:p">
652		<note>
653			<remark>
654				<xsl:apply-templates/>
655			</remark>
656		</note>
657	</xsl:template>
658
659<!--<xsl:template match="meta:initial-creator">
660	<author>
661	<xsl:apply-templates />
662		</author>
663</xsl:template>-->
664
665	<xsl:template match="table:table">
666		<xsl:choose>
667			<xsl:when test="following-sibling::text:p[@text:style-name='Table']">
668				<table frame="all">
669					<xsl:attribute name="id">
670						<xsl:value-of select="@table:name"/>
671					</xsl:attribute>
672					<title>
673						<xsl:value-of select="following-sibling::text:p[@text:style-name='Table']"/>
674					</title>
675					<xsl:call-template name="generictable"/>
676				</table>
677			</xsl:when>
678			<xsl:otherwise>
679				<informaltable frame="all">
680					<xsl:call-template name="generictable"/>
681				</informaltable>
682			</xsl:otherwise>
683		</xsl:choose>
684	</xsl:template>
685
686
687	<xsl:template name="generictable">
688		<xsl:variable name="cells" select="count(descendant::table:table-cell)"></xsl:variable>
689		<xsl:variable name="rows">
690			<xsl:value-of select="count(descendant::table:table-row)"/>
691		</xsl:variable>
692		<xsl:variable name="cols">
693			<xsl:value-of select="$cells div $rows"/>
694		</xsl:variable>
695		<xsl:variable name="numcols">
696			<xsl:choose>
697				<xsl:when test="child::table:table-column/@table:number-columns-repeated">
698					<xsl:value-of select="number(table:table-column/@table:number-columns-repeated+1)"/>
699				</xsl:when>
700				<xsl:otherwise>
701					<xsl:value-of select="$cols"/>
702				</xsl:otherwise>
703			</xsl:choose>
704		</xsl:variable>
705		<xsl:element name="tgroup">
706			<xsl:attribute name="cols">
707				<xsl:value-of select="$numcols"/>
708			</xsl:attribute>
709			<xsl:call-template name="colspec">
710				<xsl:with-param name="left" select="1"/>
711			</xsl:call-template>
712			<xsl:apply-templates/>
713		</xsl:element>
714	</xsl:template>
715
716	<xsl:template name="colspec">
717		<xsl:param name="left"/>
718		<xsl:if test="number($left &lt; ( table:table-column/@table:number-columns-repeated +2) )">
719			<xsl:element name="colspec">
720				<xsl:attribute name="colnum">
721					<xsl:value-of select="$left"/>
722				</xsl:attribute>
723				<xsl:attribute name="colname">c<xsl:value-of select="$left"/>
724				</xsl:attribute>
725			</xsl:element>
726			<xsl:call-template name="colspec">
727				<xsl:with-param name="left" select="$left+1"/>
728			</xsl:call-template>
729		</xsl:if>
730	</xsl:template>
731
732	<xsl:template match="table:table-column">
733		<xsl:apply-templates/>
734	</xsl:template>
735
736	<xsl:template match="table:table-header-rows">
737		<thead>
738			<xsl:apply-templates/>
739		</thead>
740	</xsl:template>
741
742	<xsl:template match="table:table-header-rows/table:table-row">
743		<row>
744			<xsl:apply-templates/>
745		</row>
746	</xsl:template>
747
748	<xsl:template match="table:table/table:table-row">
749		<xsl:if test="not(preceding-sibling::table:table-row)">
750			<xsl:text disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
751		</xsl:if>
752		<row>
753			<xsl:apply-templates/>
754		</row>
755		<xsl:if test="not(following-sibling::table:table-row)">
756			<xsl:text disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
757		</xsl:if>
758	</xsl:template>
759
760	<xsl:template match="table:table-cell">
761		<xsl:element name="entry">
762			<xsl:if test="@table:number-columns-spanned >'1'">
763				<xsl:attribute name="namest">
764					<xsl:value-of select="concat('c',count(preceding-sibling::table:table-cell[not(@table:number-columns-spanned)]) +sum(preceding-sibling::table:table-cell/@table:number-columns-spanned)+1)"/>
765				</xsl:attribute>
766				<xsl:attribute name="nameend">
767					<xsl:value-of select="concat('c',count(preceding-sibling::table:table-cell[not(@table:number-columns-spanned)]) +sum(preceding-sibling::table:table-cell/@table:number-columns-spanned)+ @table:number-columns-spanned)"/>
768				</xsl:attribute>
769			</xsl:if>
770			<xsl:apply-templates/>
771		</xsl:element>
772	</xsl:template>
773
774	<xsl:template match="text:p">
775		<xsl:choose>
776			<xsl:when test="@text:style-name='Table'"></xsl:when>
777			<xsl:otherwise>
778				<para>
779					<xsl:apply-templates/>
780				</para>
781			</xsl:otherwise>
782		</xsl:choose>
783	</xsl:template>
784
785	<xsl:key match="text:list-style" name="getListStyle" use="@style:name"/>
786
787	<xsl:template match="text:ordered-list">
788		<xsl:param name="outlineLevel" select="1"/>
789
790		<xsl:variable name="listStyle" select="key('getListStyle', @text:style-name)/*[@text:level = $outlineLevel]"/>
791
792		<!-- if the list is not recognizable as a list (e.g. no indent, number/bullet, etc.) the list will be ignored -->
793		<xsl:if test="$listStyle/style:properties/@*">
794			<orderedlist>
795				<xsl:apply-templates>
796					<xsl:with-param name="itemType" select="'listitem'"/>
797					<xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
798				</xsl:apply-templates>
799			</orderedlist>
800		</xsl:if>
801	</xsl:template>
802
803	<xsl:template match="text:unordered-list">
804		<xsl:param name="outlineLevel" select="1"/>
805
806		<xsl:variable name="listStyle" select="key('getListStyle', @text:style-name)/*[@text:level = $outlineLevel]"/>
807		<!-- if the list is not recognizable as a list (e.g. no indent, number/bullet, etc.) the list will be ignored -->
808		<xsl:if test="$listStyle/style:properties/@*">
809			<xsl:choose>
810				<xsl:when test="@text:style-name='Var List'">
811					<variablelist>
812						<xsl:apply-templates>
813							<xsl:with-param name="itemType" select="'varlist'"/>
814							<xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
815						</xsl:apply-templates>
816					</variablelist>
817				</xsl:when>
818				<xsl:otherwise>
819					<itemizedlist>
820						<xsl:apply-templates>
821							<xsl:with-param name="itemType" select="'listitem'"/>
822							<xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
823						</xsl:apply-templates>
824					</itemizedlist>
825				</xsl:otherwise>
826			</xsl:choose>
827		</xsl:if>
828	</xsl:template>
829
830	<xsl:template match="text:list-item | text:list-header">
831		<xsl:param name="listType"/>
832		<xsl:param name="outlineLevel"/>
833
834		<xsl:choose>
835			<xsl:when test="$listType='Var List'">
836				<xsl:element name="varlistentry">
837					<xsl:apply-templates>
838						<xsl:with-param name="outlineLevel" select="$outlineLevel"/>
839					</xsl:apply-templates>
840				</xsl:element>
841			</xsl:when>
842			<xsl:otherwise>
843				<xsl:element name="listitem">
844					<xsl:apply-templates>
845						<xsl:with-param name="outlineLevel" select="$outlineLevel"/>
846					</xsl:apply-templates>
847				</xsl:element>
848			</xsl:otherwise>
849		</xsl:choose>
850	</xsl:template>
851
852	<xsl:template match="text:p[@text:style-name='VarList Term']">
853		<xsl:element name="term">
854			<xsl:apply-templates/>
855		</xsl:element>
856	</xsl:template>
857
858	<xsl:template match="text:p[@text:style-name='VarList Item']">
859		<xsl:element name="para">
860			<xsl:apply-templates/>
861		</xsl:element>
862	</xsl:template>
863
864	<!-- text headings should only be matched once, when creating a nested docbook section structure, but might be as well become as part of a list a title -->
865	<xsl:template match="text:h">
866		<title>
867			<xsl:apply-templates/>
868		</title>
869	</xsl:template>
870
871	<xsl:template match="dc:title"></xsl:template>
872
873	<xsl:template match="dc:description">
874		<abstract>
875			<para>
876				<xsl:apply-templates/>
877			</para>
878		</abstract>
879	</xsl:template>
880
881	<xsl:template match="dc:subject"></xsl:template>
882
883
884	<xsl:template match="meta:generator"></xsl:template>
885
886	<xsl:template match="draw:plugin">
887		<xsl:element name="audioobject">
888			<xsl:attribute name="fileref">
889				<xsl:value-of select="@xlink:href"/>
890			</xsl:attribute>
891			<xsl:attribute name="width"></xsl:attribute>
892		</xsl:element>
893	</xsl:template>
894
895	<xsl:template match="text:footnote">
896		<footnote>
897			<xsl:apply-templates/>
898		</footnote>
899	</xsl:template>
900
901	<xsl:template match="text:footnote-body">
902		<xsl:apply-templates/>
903	</xsl:template>
904
905
906	<xsl:template match="draw:text-box"></xsl:template>
907
908
909
910	<xsl:template match="draw:image">
911		<xsl:choose>
912			<xsl:when test="parent::text:p[@text:style-name='Mediaobject']">
913				<xsl:element name="imageobject">
914					<xsl:element name="imagedata">
915						<xsl:attribute name="fileref">
916							<xsl:value-of select="@xlink:href"/>
917						</xsl:attribute>
918					</xsl:element>
919					<xsl:element name="caption">
920						<xsl:value-of select="."/>
921					</xsl:element>
922				</xsl:element>
923			</xsl:when>
924			<xsl:otherwise>
925				<xsl:element name="inlinegraphic">
926					<xsl:attribute name="fileref">
927						<xsl:choose>
928							<xsl:when test="@xlink:href != ''">
929								<xsl:value-of select="@xlink:href"/>
930							</xsl:when>
931							<xsl:otherwise>
932								<xsl:text>embedded:</xsl:text>
933								<xsl:value-of select="@draw:name"/>
934							</xsl:otherwise>
935						</xsl:choose>
936					</xsl:attribute>
937					<xsl:attribute name="width">
938						<xsl:value-of select="@svg:width"/>
939					</xsl:attribute>
940					<xsl:attribute name="depth">
941						<xsl:value-of select="@svg:height"/>
942					</xsl:attribute>
943				</xsl:element>
944			</xsl:otherwise>
945		</xsl:choose>
946	</xsl:template>
947
948
949	<xsl:template match="text:span">
950		<xsl:choose>
951			<xsl:when test="./@text:style-name='GuiMenu'">
952				<xsl:element name="guimenu">
953					<xsl:value-of select="."/>
954				</xsl:element>
955			</xsl:when>
956			<xsl:when test="./@text:style-name='GuiSubMenu'">
957				<xsl:element name="guisubmenu">
958					<xsl:value-of select="."/>
959				</xsl:element>
960			</xsl:when>
961			<xsl:when test="@text:style-name='GuiMenuItem'">
962				<xsl:element name="guimenuitem">
963					<xsl:value-of select="."/>
964				</xsl:element>
965			</xsl:when>
966			<xsl:when test="@text:style-name='GuiButton'">
967				<xsl:element name="guibutton">
968					<xsl:value-of select="."/>
969				</xsl:element>
970			</xsl:when>
971			<xsl:when test="@text:style-name='GuiButton'">
972				<xsl:element name="guibutton">
973					<xsl:value-of select="."/>
974				</xsl:element>
975			</xsl:when>
976			<xsl:when test="@text:style-name='GuiLabel'">
977				<xsl:element name="guilabel">
978					<xsl:value-of select="."/>
979				</xsl:element>
980			</xsl:when>
981			<xsl:when test="@text:style-name='Emphasis'">
982				<xsl:element name="emphasis">
983					<xsl:value-of select="."/>
984				</xsl:element>
985			</xsl:when>
986			<xsl:when test="@text:style-name='FileName'">
987				<xsl:element name="filename">
988					<xsl:value-of select="."/>
989				</xsl:element>
990			</xsl:when>
991			<xsl:when test="@text:style-name='Application'">
992				<xsl:element name="application">
993					<xsl:value-of select="."/>
994				</xsl:element>
995			</xsl:when>
996			<xsl:when test="@text:style-name='Command'">
997				<command>
998					<xsl:apply-templates/>
999				</command>
1000			</xsl:when>
1001			<xsl:when test="@text:style-name='SubScript'">
1002				<subscript>
1003					<xsl:apply-templates/>
1004				</subscript>
1005			</xsl:when>
1006			<xsl:when test="@text:style-name='SuperScript'">
1007				<superscript>
1008					<xsl:apply-templates/>
1009				</superscript>
1010			</xsl:when>
1011			<xsl:when test="@text:style-name='SystemItem'">
1012				<systemitem>
1013					<xsl:apply-templates/>
1014				</systemitem>
1015			</xsl:when>
1016			<xsl:when test="@text:style-name='ComputerOutput'">
1017				<computeroutput>
1018					<xsl:apply-templates/>
1019				</computeroutput>
1020			</xsl:when>
1021			<xsl:when test="@text:style-name='Highlight'">
1022				<highlight>
1023					<xsl:apply-templates/>
1024				</highlight>
1025			</xsl:when>
1026			<xsl:when test="@text:style-name='KeyCap'">
1027				<keycap>
1028					<xsl:apply-templates/>
1029				</keycap>
1030			</xsl:when>
1031			<xsl:when test="@text:style-name='KeySym'">
1032				<xsl:element name="keysym">
1033					<xsl:apply-templates/>
1034				</xsl:element>
1035			</xsl:when>
1036			<xsl:when test="@text:style-name='KeyCombo'">
1037				<keycombo>
1038					<xsl:apply-templates/>
1039				</keycombo>
1040			</xsl:when>
1041			<xsl:otherwise>
1042				<xsl:apply-templates/>
1043			</xsl:otherwise>
1044		</xsl:choose>
1045
1046	</xsl:template>
1047
1048
1049	<xsl:template match="text:a">
1050		<xsl:choose>
1051			<xsl:when test="contains(@xlink:href,'://')">
1052				<xsl:element name="ulink">
1053					<xsl:attribute name="url">
1054						<xsl:value-of select="@xlink:href"/>
1055					</xsl:attribute>
1056					<xsl:apply-templates/>
1057				</xsl:element>
1058			</xsl:when>
1059			<xsl:when test="contains(@xlink:href,'mailto:')">
1060				<xsl:element name="ulink">
1061					<xsl:attribute name="url">
1062						<xsl:value-of select="@xlink:href"/>
1063					</xsl:attribute>
1064					<xsl:apply-templates/>
1065				</xsl:element>
1066			</xsl:when>
1067			<xsl:when test="not(contains(@xlink:href,'#'))">
1068				<xsl:element name="olink">
1069					<xsl:attribute name="targetdocent">
1070						<xsl:value-of select="@xlink:href"/>
1071					</xsl:attribute>
1072					<xsl:apply-templates/>
1073				</xsl:element>
1074			</xsl:when>
1075			<xsl:otherwise>
1076				<xsl:variable name="linkvar" select="substring-after(@xlink:href,'#')"/>
1077				<xsl:element name="link">
1078					<xsl:attribute name="linkend">
1079						<xsl:value-of select="substring-before($linkvar,'%')"/>
1080					</xsl:attribute>
1081					<xsl:apply-templates/>
1082				</xsl:element>
1083			</xsl:otherwise>
1084		</xsl:choose>
1085	</xsl:template>
1086
1087<!--
1088	Change Made By Kevin Fowlks (fowlks@msu.edu) July 2nd, 2003
1089	This allows users to create example code in DocBook.
1090
1091	Note: This type of grouping could also be implemented for
1092	<notes>,<literallayout>, <blockquote> or any other tag that requires text to be treated as blocked.
1093-->
1094	<xsl:template match="text:p[@text:style-name='Example']">
1095		<xsl:if test="not(preceding-sibling::*[1][self::text:p[@text:style-name='Example']])">
1096			<xsl:element name="example">
1097				<xsl:element name="title"></xsl:element>
1098				<xsl:element name="programlisting">
1099					<xsl:value-of select="."/>
1100					<xsl:text disable-output-escaping="no">&#xD;</xsl:text>
1101					<xsl:apply-templates mode="in-list" select="following-sibling::*[1][self::text:p[@text:style-name='Example']]"/>
1102				</xsl:element>
1103			</xsl:element>
1104		</xsl:if>
1105	</xsl:template>
1106
1107	<xsl:template match="text:p[@text:style-name='Example']" mode="in-list">
1108		<xsl:value-of select="."/>
1109		<xsl:text disable-output-escaping="no">&#xD;</xsl:text>
1110		<xsl:apply-templates mode="in-list" select="following-sibling::*[1][self::text:p[@text:style-name='Example']]"/>
1111	</xsl:template>
1112
1113	<!-- ****************** -->
1114	<!-- *** Whitespace *** -->
1115	<!-- ****************** -->
1116
1117	<xsl:template match="text:s">
1118		<xsl:call-template name="write-breakable-whitespace">
1119			<xsl:with-param name="whitespaces" select="@text:c"/>
1120		</xsl:call-template>
1121	</xsl:template>
1122
1123
1124	<!--write the number of 'whitespaces' -->
1125	<xsl:template name="write-breakable-whitespace">
1126		<xsl:param name="whitespaces"/>
1127
1128		<!--write two space chars as the normal white space character will be stripped
1129			and the other is able to break -->
1130		<xsl:text>&#160;</xsl:text>
1131		<xsl:if test="$whitespaces >= 2">
1132			<xsl:call-template name="write-breakable-whitespace-2">
1133				<xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
1134			</xsl:call-template>
1135		</xsl:if>
1136	</xsl:template>
1137
1138
1139	<!--write the number of 'whitespaces' -->
1140	<xsl:template name="write-breakable-whitespace-2">
1141		<xsl:param name="whitespaces"/>
1142		<!--write two space chars as the normal white space character will be stripped
1143			and the other is able to break -->
1144		<xsl:text> </xsl:text>
1145		<xsl:if test="$whitespaces >= 2">
1146			<xsl:call-template name="write-breakable-whitespace">
1147				<xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
1148			</xsl:call-template>
1149		</xsl:if>
1150	</xsl:template>
1151
1152	<xsl:template match="text:tab-stop">
1153		<xsl:call-template name="write-breakable-whitespace">
1154			<xsl:with-param name="whitespaces" select="8"/>
1155		</xsl:call-template>
1156	</xsl:template>
1157</xsl:stylesheet>
1158