xref: /core/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl (revision 984f0e49d35ba87c105310f27d945147a23d1198)
1<?xml version="1.0" encoding="UTF-8"?> <!-- -*- fill-column: 130; nxml-child-indent: 4; tab-width: 4; indent-tabs-mode: nil -*- -->
2<!--
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 *   Licensed to the Apache Software Foundation (ASF) under one or more
12 *   contributor license agreements. See the NOTICE file distributed
13 *   with this work for additional information regarding copyright
14 *   ownership. The ASF licenses this file to you under the Apache
15 *   License, Version 2.0 (the "License"); you may not use this file
16 *   except in compliance with the License. You may obtain a copy of
17 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18-->
19<!--
20    For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
21-->
22<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xt="http://www.jclark.com/xt" xmlns:common="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" exclude-result-prefixes="chart config dc dom dr3d draw fo form loext math meta number office ooo oooc ooow presentation script style svg table text xforms xlink xsd xsi xt common xalan" xmlns="http://www.w3.org/1999/xhtml">
23
24
25    <!--+++++ INCLUDED XSL MODULES +++++-->
26
27    <!-- helper collection, to convert measures (e.g. inch to pixel using DPI (dots per inch) parameter)-->
28    <xsl:import href="../../common/measure_conversion.xsl"/>
29
30    <!-- common office body element handling -->
31    <xsl:import href="../common/body.xsl"/>
32
33    <!-- common table handling -->
34    <xsl:import href="../common/table/table.xsl"/>
35
36    <!-- xhtml table handling -->
37    <xsl:include href="table.xsl"/>
38
39    <!-- Useful in case of 'style:map', conditional formatting, where a style references to another -->
40    <xsl:key name="styles" match="/*/office:styles/style:style | /*/office:automatic-styles/style:style" use="@style:name"/>
41
42
43    <!-- ************ -->
44    <!-- *** body *** -->
45    <!-- ************ -->
46
47    <xsl:key match="style:style/@style:master-page-name" name="masterPage" use="'count'"/>
48    <xsl:key match="style:master-page" name="masterPageElements" use="@style:name"/>
49    <xsl:key match="style:page-layout" name="pageLayoutElements" use="@style:name"/>
50    <xsl:key name="writingModeStyles" match="/*/office:styles/style:style/style:paragraph-properties/@style:writing-mode | /*/office:automatic-styles/style:style/style:paragraph-properties/@style:writing-mode" use="'test'"/>
51    <xsl:template name="create-body">
52        <xsl:param name="globalData"/>
53        <xsl:text>&#xa;</xsl:text>
54        <xsl:call-template name="create-body.collect-page-properties">
55            <xsl:with-param name="globalData" select="$globalData"/>
56        </xsl:call-template>
57        <xsl:text>&#xa;</xsl:text>
58    </xsl:template>
59
60    <xsl:template name="create-body.collect-page-properties">
61        <xsl:param name="globalData"/>
62
63        <!-- approximation to find the correct master page style (with page dimensions) -->
64        <xsl:variable name="masterPageNames">
65            <!-- Loop over every style:style containing a @style:master-page-name attribute -->
66            <xsl:for-each select="key('masterPage','count')">
67                <!-- Check if this style is being used in the body -->
68                <xsl:if test="key('elementUsingStyle', ../@style:name)">
69                    <!-- Check every master-page-name if it is not empty and return as ';' separated list  -->
70                    <xsl:if test="string-length(../@style:master-page-name) &gt; 0">
71                        <xsl:value-of select="../@style:master-page-name"/>;
72                    </xsl:if>
73                </xsl:if>
74            </xsl:for-each>
75        </xsl:variable>
76
77        <!-- Take the first of the masterpage list and get the according style:master-page element and find the @style:page-layout-name  -->
78        <xsl:variable name="pageLayoutName" select="key('masterPageElements', substring-before($masterPageNames,';'))/@style:page-layout-name"/>
79        <xsl:variable name="pagePropertiesRTF">
80            <xsl:choose>
81                <xsl:when test="not($pageLayoutName) or $pageLayoutName = ''">
82                    <xsl:copy-of select="$globalData/styles-file/*/office:automatic-styles/style:page-layout[1]/style:page-layout-properties"/>
83                </xsl:when>
84                <xsl:otherwise>
85                    <!-- Find the according style:page-layout and store the properties in a variable  -->
86                    <xsl:copy-of select="key('pageLayoutElements', $pageLayoutName)/style:page-layout-properties"/>
87                </xsl:otherwise>
88            </xsl:choose>
89        </xsl:variable>
90
91        <xsl:choose>
92            <xsl:when test="function-available('common:node-set')">
93                <xsl:call-template name="create-body.create">
94                    <xsl:with-param name="globalData" select="common:node-set($globalData)"/>
95                    <xsl:with-param name="pageProperties" select="common:node-set($pagePropertiesRTF)"/>
96                </xsl:call-template>
97            </xsl:when>
98            <xsl:when test="function-available('xalan:nodeset')">
99                <xsl:call-template name="create-body.create">
100                    <xsl:with-param name="globalData" select="xalan:nodeset($globalData)"/>
101                    <xsl:with-param name="pageProperties" select="xalan:nodeset($pagePropertiesRTF)"/>
102                </xsl:call-template>
103            </xsl:when>
104            <xsl:when test="function-available('xt:node-set')">
105                <xsl:call-template name="create-body.create">
106                    <xsl:with-param name="globalData" select="xt:node-set($globalData)"/>
107                    <xsl:with-param name="pageProperties" select="xt:node-set($pagePropertiesRTF)"/>
108                </xsl:call-template>
109            </xsl:when>
110            <xsl:otherwise>
111                <xsl:message terminate="yes">The required node-set function was not found!</xsl:message>
112            </xsl:otherwise>
113        </xsl:choose>
114    </xsl:template>
115
116    <xsl:template name="create-body.create">
117        <xsl:param name="globalData"/>
118        <xsl:param name="pageProperties"/>
119
120        <xsl:element name="body">
121            <!-- direction of text flow -->
122            <xsl:variable name="writingMode" select="$pageProperties/style:page-layout-properties/@style:writing-mode"/>
123            <xsl:choose>
124                <xsl:when test="$writingMode">
125                    <xsl:choose>
126                        <xsl:when test="contains($writingMode, 'lr')">
127                            <xsl:attribute name="dir">ltr</xsl:attribute>
128                        </xsl:when>
129                        <xsl:when test="contains($writingMode, 'rl')">
130                            <xsl:attribute name="dir">rtl</xsl:attribute>
131                        </xsl:when>
132                    </xsl:choose>
133                </xsl:when>
134                <xsl:otherwise>
135                    <!-- As CSS writing-mode is not implemented by all browsers, a heuristic is done -->
136                    <xsl:variable name="writingModeTest" select="key('writingModeStyles', 'test')"/>
137                    <xsl:if test="contains($writingModeTest, 'rl')">
138                        <xsl:attribute name="dir">rtl</xsl:attribute>
139                    </xsl:if>
140                </xsl:otherwise>
141            </xsl:choose>
142            <!-- adapt page size -->
143            <xsl:variable name="pageWidth" select="$pageProperties/style:page-layout-properties/@fo:page-width"/>
144            <xsl:variable name="pageHeight" select="$pageProperties/style:page-layout-properties/@fo:height"/>
145
146            <!-- multiple backgroundimages for different page styles (never used in html) -->
147            <xsl:variable name="backgroundImage" select="$pageProperties/style:page-layout-properties/style:background-image"/>
148            <!-- page margins & background image  -->
149            <xsl:if test="$pageWidth or $pageHeight or $pageProperties/style:page-layout-properties/@fo:* or $backgroundImage/@xlink:href">
150                <xsl:attribute name="style">
151                    <xsl:if test="$pageWidth">
152                        <xsl:text>max-width:</xsl:text>
153                        <xsl:value-of select="$pageWidth" />
154                        <xsl:text>;</xsl:text>
155                    </xsl:if>
156                    <xsl:if test="$pageHeight">
157                        <xsl:text>max-height:</xsl:text>
158                        <xsl:value-of select="$pageHeight" />
159                        <xsl:text>;</xsl:text>
160                    </xsl:if>
161                    <xsl:if test="$pageProperties/style:page-layout-properties/@fo:* or $backgroundImage/@xlink:href">
162                        <xsl:apply-templates select="$pageProperties/style:page-layout-properties/@fo:*"/>
163                        <xsl:if test="$backgroundImage/@xlink:href">
164                            <xsl:text>background-image:url(</xsl:text>
165                            <xsl:call-template name="create-href">
166                                <xsl:with-param name="href" select="$backgroundImage/@xlink:href"/>
167                            </xsl:call-template>
168                            <xsl:text>);</xsl:text>
169
170                            <xsl:if test="$backgroundImage/@style:repeat">
171                                <xsl:choose>
172                                    <xsl:when test="$backgroundImage/@style:repeat = 'no-repeat'">
173                                        <xsl:text>background-repeat:no-repeat;</xsl:text>
174                                    </xsl:when>
175                                    <xsl:otherwise>
176                                        <xsl:text>background-repeat:repeat;</xsl:text>
177                                    </xsl:otherwise>
178                                </xsl:choose>
179                            </xsl:if>
180                            <xsl:if test="$backgroundImage/@style:position">
181                                <xsl:text>background-position:</xsl:text>
182                                <xsl:value-of select="$backgroundImage/@style:position"/>
183                                <xsl:text>;</xsl:text>
184                            </xsl:if>
185                        </xsl:if>
186                    </xsl:if>
187                </xsl:attribute>
188            </xsl:if>
189            <xsl:text>&#xa;</xsl:text>
190            <!-- processing the content of the OpenDocument content file -->
191            <xsl:apply-templates select="/*/office:body/*">
192                <xsl:with-param name="globalData" select="$globalData"/>
193            </xsl:apply-templates>
194
195        </xsl:element>
196    </xsl:template>
197
198    <!-- processing the content of the OpenDocument content file -->
199    <xsl:template match="office:body/*">
200        <xsl:param name="globalData"/>
201
202        <!-- not using of 'apply-styles-and-content' as the content table information might have been added to 'globalData' variable -->
203        <xsl:apply-templates select="@text:style-name | @draw:style-name | @draw:text-style-name | @table:style-name"><!-- | @presentation:style-name -->
204            <xsl:with-param name="globalData" select="$globalData"/>
205        </xsl:apply-templates>
206
207        <xsl:apply-templates>
208            <xsl:with-param name="globalData" select="$globalData"/>
209        </xsl:apply-templates>
210
211        <!-- writing the footer- and endnotes beyond the body -->
212        <xsl:call-template name="write-text-nodes">
213            <xsl:with-param name="globalData" select="$globalData"/>
214        </xsl:call-template>
215    </xsl:template>
216
217    <!-- ******************************* -->
218    <!-- *** User Field Declarations *** -->
219    <!-- ******************************* -->
220
221    <xsl:template match="text:user-field-get | text:user-field-input">
222        <xsl:param name="globalData"/>
223
224        <xsl:value-of select="."/>
225    </xsl:template>
226
227    <xsl:template match="text:conditional-text">
228        <xsl:param name="globalData"/>
229
230        <xsl:value-of select="."/>
231    </xsl:template>
232
233    <!-- ODF text fields -->
234    <xsl:template match="text:author-initials | text:author-name | text:chapter | text:character-count | text:creation-date | text:creation-time | text:creator | text:date | text:description | text:editing-cycles | text:editing-duration | text:file-name | text:image-count | text:initial-creator | text:keywords | text:modification-date | text:modification-time | text:object-count | text:page-continuation | text:page-count | text:page-number | text:paragraph-count | text:print-date | text:print-time | text:printed-by | text:sender-city | text:sender-company | text:sender-country | text:sender-email | text:sender-fax | text:sender-firstname | text:sender-initials | text:sender-lastname | text:sender-phone-private | text:sender-phone-work | text:sender-position | text:sender-postal-code | text:sender-state-or-province | text:sender-street | text:sender-title | text:sheet-name | text:subject | text:table-count | text:time | text:title | text:user-defined | text:word-count">
235        <xsl:param name="globalData"/>
236
237        <xsl:element name="span">
238            <xsl:attribute name="title">
239                <xsl:value-of select="local-name()"/>
240            </xsl:attribute>
241            <xsl:apply-templates>
242                <xsl:with-param name="globalData" select="$globalData"/>
243            </xsl:apply-templates>
244        </xsl:element>
245        <xsl:text>&#xa;</xsl:text>
246    </xsl:template>
247
248
249
250    <!-- *************** -->
251    <!-- *** Textbox *** -->
252    <!-- *************** -->
253
254    <xsl:template match="draw:text-box">
255        <xsl:param name="globalData"/>
256
257        <xsl:text>&#xa;</xsl:text>
258        <xsl:comment>Next 'div' was a 'draw:text-box'.</xsl:comment>
259        <xsl:text>&#xa;</xsl:text>
260        <xsl:element name="div">
261            <xsl:variable name="dimension">
262                <xsl:apply-templates select="@fo:min-width" />
263                <xsl:apply-templates select="@fo:max-width" />
264                <xsl:apply-templates select="@fo:min-height" />
265                <xsl:apply-templates select="@fo:max-height" />
266            </xsl:variable>
267            <!-- inline heading -->
268            <xsl:variable name="inlineHeading">
269                <xsl:if test="parent::draw:frame/@text:anchor-type='as-char'">display:inline;</xsl:if>
270            </xsl:variable>
271            <xsl:if test="normalize-space($dimension)!=''">
272                <xsl:attribute name="style">
273                    <xsl:value-of select="concat($dimension,$inlineHeading)" />
274                </xsl:attribute>
275            </xsl:if>
276
277            <xsl:apply-templates select="@xml:id">
278                <xsl:with-param name="globalData" select="$globalData" />
279            </xsl:apply-templates>
280            <xsl:apply-templates select="node()">
281                <xsl:with-param name="globalData" select="$globalData"/>
282            </xsl:apply-templates>
283        </xsl:element>
284    </xsl:template>
285
286    <xsl:template match="@fo:min-width">
287        <xsl:text>min-width:</xsl:text>
288        <xsl:value-of select="."/>
289        <xsl:text>;</xsl:text>
290    </xsl:template>
291    <xsl:template match="@fo:max-width">
292        <xsl:text>max-width:</xsl:text>
293        <xsl:value-of select="."/>
294        <xsl:text>;</xsl:text>
295    </xsl:template>
296    <xsl:template match="@fo:min-height">
297        <xsl:text>min-height:</xsl:text>
298        <xsl:value-of select="."/>
299        <xsl:text>;</xsl:text>
300    </xsl:template>
301    <xsl:template match="@fo:max-height">
302        <xsl:text>max-height:</xsl:text>
303        <xsl:value-of select="."/>
304        <xsl:text>;</xsl:text>
305    </xsl:template>
306
307
308    <!-- inline style helper for the 'div' boxes -->
309    <xsl:template name="svg:height">
310        <xsl:text>height:</xsl:text>
311        <xsl:choose>
312            <!-- changing the distance measure: inch to in -->
313            <xsl:when test="contains(@svg:height, 'inch')">
314                <xsl:value-of select="substring-before(@svg:height, 'ch')"/>
315            </xsl:when>
316            <xsl:otherwise>
317                <xsl:value-of select="@svg:height"/>
318            </xsl:otherwise>
319        </xsl:choose>
320        <xsl:text>;</xsl:text>
321    </xsl:template>
322
323    <!-- inline style helper for the 'div' boxes -->
324    <xsl:template name="svg:width">
325        <xsl:text>width:</xsl:text>
326        <xsl:choose>
327            <!-- changing the distance measure: inch to in -->
328            <xsl:when test="contains(@svg:width, 'inch')">
329                <xsl:value-of select="substring-before(@svg:width, 'ch')"/>
330            </xsl:when>
331            <xsl:otherwise>
332                <xsl:value-of select="@svg:width"/>
333            </xsl:otherwise>
334        </xsl:choose>
335        <xsl:text>;</xsl:text>
336    </xsl:template>
337
338
339
340    <!-- ****************** -->
341    <!-- *** Paragraphs *** -->
342    <!-- ****************** -->
343
344    <xsl:template match="text:p | draw:page">
345        <xsl:param name="globalData"/>
346        <!-- The footnote symbol is the prefix for a footnote in the footer -->
347        <xsl:param name="footnotePrefix"/>
348        <!-- 1) In ODF sometimes the following children are nested
349                <text:p>
350                    <draw:frame>
351                        <draw:text-box>
352                            <text:p>
353                Which results in a paragraphs (the last text:p) having a paragraph as its ancestor.
354                In HTML a 'p' can only have inline documents (no other 'p' as children'),
355                a 'div' will be given for the ancestors instead.
356             2) ODF images are embedded in a paragraph, but CSS is not able to express a horizontal alignment for an HTML image (text:align is only valid for block elements).
357                A surrounding 'div' element taking over the image style solves that problem, but the div is invalid as child of a paragraph
358                Therefore the paragraph has to be exchanged with a HTML div element
359        -->
360        <!-- TODO page alignment fix - PART1 -->
361        <xsl:variable name="childText"><xsl:apply-templates mode="getAllTextChildren"/></xsl:variable>
362        <xsl:choose>
363            <xsl:when test="name() = 'text:p' and not(*) and (normalize-space($childText) = '')">
364                <!-- WorkAround: Test if the empty paragraph was added after an image, which OOO often does -->
365                <xsl:variable name="isFollowingImage">
366                    <xsl:call-template name="follows-empty-paragraphs-and-image">
367                        <xsl:with-param name="precedingElement" select="preceding-sibling::node()[1]"/>
368                    </xsl:call-template>
369                </xsl:variable>
370                <xsl:if test="$isFollowingImage = 'no'">
371                    <xsl:call-template name="create-paragraph">
372                        <xsl:with-param name="globalData" select="$globalData" />
373                        <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
374                    </xsl:call-template>
375                </xsl:if>
376
377            </xsl:when>
378            <xsl:when test="name() = 'draw:frame' and ((normalize-space($childText) != '')  or (((count(*) - count(text:soft-page-break)) &gt; 1)))">
379                <!-- If there is a 'draw:frame' child with text (not being whitespace alone) and more than the draw:frame alone and
380                    not the draw:frame and a soft-page-break alone (which is quite often) -->
381
382                <!-- If there is a frame within the text:p or draw:page, its siblings are surrounded as well by a div and are floating (CSS float) -->
383                <!-- But it makes no sense to create floating if the frame is alone or only together with a soft-page-break not usable for HTML -->
384                <!-- The paragraph is written as DIV as there might be nested paragraphs (see above choose block) -->
385                <xsl:choose>
386                    <xsl:when test="name() = 'text:p'">
387                        <xsl:text>&#xa;</xsl:text>
388                        <xsl:comment>Next 'div' was a 'text:p'.</xsl:comment>
389                        <xsl:text>&#xa;</xsl:text>
390                    </xsl:when>
391                    <xsl:otherwise>
392                        <xsl:text>&#xa;</xsl:text>
393                        <xsl:comment>Next 'div' was a 'draw:page'.</xsl:comment>
394                        <xsl:text>&#xa;</xsl:text>
395                    </xsl:otherwise>
396                </xsl:choose>
397                <xsl:element name="div">
398                    <xsl:apply-templates select="@*">
399                        <xsl:with-param name="globalData" select="$globalData"/>
400                    </xsl:apply-templates>
401                    <!-- the footnote symbol is the prefix for a footnote in the footer -->
402                    <xsl:copy-of select="$footnotePrefix"/>
403                    <!-- deal with none draw:frame ahead of the <draw:frame> -->
404                    <xsl:if test="name(node()[1]) != 'draw:frame'">
405                        <xsl:apply-templates select="node()[1]" mode="frameFloating">
406                            <xsl:with-param name="globalData" select="$globalData" />
407                            <xsl:with-param name="previousFrameWidths" select="0"/>
408                            <xsl:with-param name="previousFrameHeights" select="0"/>
409                            <xsl:with-param name="leftPosition" select="0" />
410                            <xsl:with-param name="stopAtFirstFrame" select="true()" />
411                            <!-- TODO for me (Svante) - Not used, uncertain for now...
412                            <xsl:with-param name="pageMarginLeft">
413                                <xsl:call-template name="getPageMarginLeft"/>
414                            </xsl:with-param>-->
415                        </xsl:apply-templates>
416                    </xsl:if>
417                    <!-- start floating of frames (each take care of its siblings till next draw:frame) -->
418                    <xsl:apply-templates select="draw:frame" mode="frameFloating">
419                        <xsl:with-param name="globalData" select="$globalData" />
420                        <xsl:with-param name="previousFrameWidths" select="0"/>
421                        <xsl:with-param name="previousFrameHeights" select="0"/>
422                        <xsl:with-param name="leftPosition" select="0"/>
423
424                        <!-- TODO for me (Svante) - Not used, uncertain for now...
425                        <xsl:with-param name="pageMarginLeft">
426                            <xsl:call-template name="getPageMarginLeft"/>
427                         </xsl:with-param>-->
428                    </xsl:apply-templates>
429                </xsl:element>
430                <!-- after the last draw:frame sibling the CSS float is disabled
431                    &#160; is an unbreakable whitespace to give content to the element and force a browser not to ignore the element -->
432                <div style="clear:both; line-height:0; width:0; height:0; margin:0; padding:0;">&#160;</div>
433            </xsl:when>
434            <xsl:when test="text:tab and not(ancestor::text:index-body)">
435                <!-- If there is a tabulator (ie. text:tab) within a paragraph, a heuristic for ODF tabulators creates a
436                    span for every text:tab embracing the following text nodes aligning them according to the tabulator.
437                    A line break or another text:tab starts a new text:span, line break even the tab counter for the line.
438                -->
439                <xsl:element name="p">
440                    <xsl:apply-templates select="@*">
441                        <xsl:with-param name="globalData" select="$globalData" />
442                    </xsl:apply-templates>
443                    <!-- start with first child of the paragraph -->
444                    <xsl:variable name="firstChildNode" select="node()[1]" />
445                    <xsl:apply-templates select="$firstChildNode" mode="tabHandling">
446                        <xsl:with-param name="globalData" select="$globalData" />
447                        <xsl:with-param name="tabStops" select="$globalData/all-doc-styles/style[@style:name = current()/@text:style-name]/*/style:tab-stops"/>
448                        <xsl:with-param name="parentMarginLeft">
449                            <!-- Styles of first paragraph in list item, including ancestor styles (inheritance) -->
450                            <xsl:variable name="paragraphName" select="@text:style-name" />
451                            <xsl:variable name="imageParagraphStyle" select="$globalData/all-styles/style[@style:name = $paragraphName]/final-properties"/>
452                            <!-- Only the left margin of the first paragraph of a list item will be added to the margin of the complete list (all levels)-->
453                            <!-- TODO: left-margin in order with bidirectional -->
454                            <xsl:choose>
455                                <xsl:when test="contains($imageParagraphStyle, 'margin-left:')">
456                                    <xsl:call-template name="convert2cm">
457                                        <xsl:with-param name="value" select="normalize-space(substring-before(substring-after($imageParagraphStyle, 'margin-left:'), ';'))"/>
458                                    </xsl:call-template>
459                                </xsl:when>
460                                <xsl:otherwise>0</xsl:otherwise>
461                            </xsl:choose>
462                        </xsl:with-param>
463                        <xsl:with-param name="pageMarginLeft">
464                            <xsl:call-template name="getPageMarginLeft"/>
465                        </xsl:with-param>
466                    </xsl:apply-templates>
467                </xsl:element>
468            </xsl:when>
469            <xsl:when test="text:tab and text:a and ancestor::text:index-body">
470                <xsl:element name="p">
471                    <xsl:apply-templates select="attribute::* | child::text:a">
472                        <xsl:with-param name="globalData" select="$globalData" />
473                    </xsl:apply-templates>
474                </xsl:element>
475            </xsl:when>
476            <xsl:otherwise>
477                <xsl:choose>
478                    <!-- !!Check if paragraph is empty!!
479                        OOo writes out empty paragraphs layouted behind an image (= draw:image within draw:frame)
480                        those have to be neglected in HTML -->
481                    <xsl:when test="name() = 'text:p' and not($childText) and not(*)">
482                        <xsl:variable name="isFollowingImage">
483                            <xsl:call-template name="follows-empty-paragraphs-and-image">
484                                <xsl:with-param name="precedingElement" select="preceding-sibling::node()[1]"/>
485                            </xsl:call-template>
486                        </xsl:variable>
487                        <xsl:if test="$isFollowingImage = 'no'">
488                            <xsl:call-template name="create-paragraph">
489                                <xsl:with-param name="globalData" select="$globalData" />
490                                <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
491                            </xsl:call-template>
492                        </xsl:if>
493                    </xsl:when>
494                    <xsl:otherwise>
495                        <xsl:text>&#xa;</xsl:text>
496                        <xsl:call-template name="create-paragraph">
497                            <xsl:with-param name="globalData" select="$globalData" />
498                            <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
499                        </xsl:call-template>
500                        <xsl:text>&#xa;</xsl:text>
501                    </xsl:otherwise>
502                </xsl:choose>
503            </xsl:otherwise>
504        </xsl:choose>
505    </xsl:template>
506
507    <!-- Return the text  -->
508    <xsl:template match="text()" mode="getAllTextChildren">
509        <xsl:value-of select="."/>
510    </xsl:template>
511
512    <!-- A span will be created for every text:tab embracing the following text nodes.
513        A line break or another text:tab starts a new text:span -->
514    <xsl:template match="* | text()" mode="tabHandling">
515        <xsl:param name="globalData"/>
516        <xsl:param name="tabStops"/>
517        <!-- there can be multiple tabs in one line, tabNo guesses the one to apply. By default the first i.e. "1" -->
518        <xsl:param name="tabCount" select="0"/>
519        <xsl:param name="parentMarginLeft" />
520        <xsl:param name="pageMarginLeft" />
521
522<!-- TODO: EXCHANGE FOLLOWING SIBLING BY VARIABLE -->
523        <xsl:variable name="followingSiblingNode" select="following-sibling::node()[1]"/>
524
525
526        <!--
527            Every tabulator indents its following content, encapuslated in a span
528            element.
529
530            This template have two modes:
531
532            1) Before the first tabulator it will match as usually paragraph content
533            to HTML.
534            2) After the first paragraph it will always triggers two recursions.
535            One embraces the following content of a paragraph element into a span.
536            (tabContentHandling)
537            The other calls this template and will now ignore anything else than
538            TAB and LINE-BREAK.
539
540
541            The tabulators and linebreaks are being iterated, one by one to keep track of the tab number
542        -->
543
544
545        <xsl:choose>
546            <xsl:when test="name() = 'text:tab'">
547                <!-- every frame sibling have to be encapsulated within a div with left indent  -->
548                <xsl:element name="span">
549                    <xsl:choose>
550                        <xsl:when test="count($tabStops/style:tab-stop) &gt; 0 and count($tabStops/style:tab-stop) &lt; 3">
551                            <!-- only allow the heuristic when the style has less than 3 TABS -->
552                            <!-- ignore heuristics if no TABS are defined -->
553                            <xsl:attribute name="style">
554                                <xsl:call-template name="createTabIndent">
555                                    <xsl:with-param name="globalData" select="$globalData"/>
556                                    <xsl:with-param name="tabStops" select="$tabStops"/>
557                                    <xsl:with-param name="tabCount" select="$tabCount + 1"/>
558                                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
559                                    <xsl:with-param name="pageMarginLeft" select="$pageMarginLeft"/>
560                                </xsl:call-template>
561                            </xsl:attribute>
562                        </xsl:when>
563                        <xsl:otherwise>
564                            <!-- if there are more than 3 TABS in the style, create a none-breakable-space as whitespace -->
565                            <xsl:text>&#160;</xsl:text>
566                        </xsl:otherwise>
567                    </xsl:choose>
568                    <xsl:apply-templates select="following-sibling::node()[1]" mode="tabContentHandling">
569                        <xsl:with-param name="globalData" select="$globalData"/>
570                    </xsl:apply-templates>
571                </xsl:element>
572                <xsl:text>&#xa;</xsl:text>
573                <xsl:apply-templates select="following-sibling::node()[1]" mode="tabHandling">
574                    <xsl:with-param name="globalData" select="$globalData"/>
575                    <xsl:with-param name="tabStops" select="$tabStops"/>
576                    <xsl:with-param name="tabCount" select="$tabCount + 1"/>
577                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
578                    <xsl:with-param name="pageMarginLeft" select="$pageMarginLeft"/>
579                </xsl:apply-templates>
580            </xsl:when>
581            <xsl:when test="name() = 'text:line-break'">
582                <!-- A line-break resets the tabCount to '0' -->
583                <br/>
584                <xsl:text>&#xa;</xsl:text>
585                <xsl:apply-templates select="following-sibling::node()[1]" mode="tabHandling">
586                    <xsl:with-param name="globalData" select="$globalData"/>
587                    <xsl:with-param name="tabStops" select="$tabStops"/>
588                    <xsl:with-param name="tabCount" select="0"/>
589                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
590                    <xsl:with-param name="pageMarginLeft" select="$pageMarginLeft"/>
591                </xsl:apply-templates>
592                <xsl:text>&#xa;</xsl:text>
593            </xsl:when>
594            <xsl:otherwise>
595                <!-- only before the first tab all content is written out -->
596                <xsl:if test="$tabCount = 0">
597                    <xsl:apply-templates select=".">
598                        <xsl:with-param name="globalData" select="$globalData"/>
599                    </xsl:apply-templates>
600                </xsl:if>
601                <xsl:apply-templates select="following-sibling::node()[1]" mode="tabHandling">
602                    <xsl:with-param name="globalData" select="$globalData"/>
603                    <xsl:with-param name="tabStops" select="$tabStops"/>
604                    <xsl:with-param name="tabCount" select="$tabCount"/>
605                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
606                    <xsl:with-param name="pageMarginLeft" select="$pageMarginLeft"/>
607                </xsl:apply-templates>
608                <xsl:text>&#xa;</xsl:text>
609            </xsl:otherwise>
610        </xsl:choose>
611    </xsl:template>
612
613    <!--
614        This recursion creates the content of a tab (i.e. following siblings
615        till next TAB or LINE BREAK) and ends with the next
616        TAB, LINE-BREAK or with the end of the paragraph.
617     -->
618    <xsl:template match="* | text()" mode="tabContentHandling">
619        <xsl:param name="globalData"/>
620
621        <xsl:if test="(name() != 'text:tab') and (name() != 'text:line-break')">
622            <!-- Write out content -->
623            <xsl:apply-templates select=".">
624                <xsl:with-param name="globalData" select="$globalData"/>
625            </xsl:apply-templates>
626            <!-- Apply for the next node -->
627            <xsl:apply-templates select="following-sibling::node()[1]" mode="tabContentHandling">
628                <xsl:with-param name="globalData" select="$globalData"/>
629            </xsl:apply-templates>
630        </xsl:if>
631    </xsl:template>
632
633    <xsl:template name="createTabIndent">
634        <xsl:param name="globalData"/>
635        <xsl:param name="tabStops"/>
636        <xsl:param name="tabCount"/>
637        <xsl:param name="parentMarginLeft" />
638        <xsl:param name="pageMarginLeft" />
639
640        <xsl:text>position:absolute;left:</xsl:text>
641        <xsl:variable name="tabPosition">
642            <xsl:call-template name="convert2cm">
643                <xsl:with-param name="value" select="$tabStops/style:tab-stop[$tabCount]/@style:position"/>
644            </xsl:call-template>
645        </xsl:variable>
646        <xsl:variable name="tabIndent">
647            <xsl:choose>
648                <xsl:when test="$tabStops/style:tab-stop[$tabCount]/@style:type = 'center'">
649                    <!-- in case of style:type 'center' the text is even before the tab stop,
650                      centered around the beginning. As I see currently no way in mapping this,
651                      therefore I do some HEURISTIC (minus -2.5cm) -->
652                    <xsl:value-of select="$tabPosition + $parentMarginLeft + $pageMarginLeft - 2.5"/>
653                </xsl:when>
654                <xsl:otherwise>
655                    <xsl:value-of select="$tabPosition + $parentMarginLeft + $pageMarginLeft"/>
656                </xsl:otherwise>
657            </xsl:choose>
658        </xsl:variable>
659        <!--<xsl:message>TAB: tabCount=
660            <xsl:value-of select="$tabCount"/>, tabPosition=
661            <xsl:value-of select="$tabPosition"/>, tabIndent=
662            <xsl:value-of select="$tabIndent"/>
663        </xsl:message>-->
664        <xsl:choose>
665            <xsl:when test="$tabIndent='NaN'">
666                <xsl:variable name="tabPositionTmp">
667                    <xsl:call-template name="convert2cm">
668                        <xsl:with-param name="value" select="$tabStops/style:tab-stop[last()]/@style:position"/>
669                    </xsl:call-template>
670                </xsl:variable>
671                    <!-- Heuristic: for every tab that is more than specified give a further 1 cm -->
672                <xsl:value-of select="$parentMarginLeft + $tabPositionTmp + count($tabStops/style:tab-stop) - $tabCount"/>
673            </xsl:when>
674            <xsl:otherwise>
675                <xsl:value-of select="$tabIndent"/>
676            </xsl:otherwise>
677        </xsl:choose>
678        <xsl:text>cm;</xsl:text>
679        <xsl:apply-templates select="$tabStops/style:tab-stop[$tabCount]/@style:type"/>
680    </xsl:template>
681
682    <!-- OOo writes out empty paragraphs layouted behind an image,
683        those have to be neglected in HTML
684    This method checks if an empty paragraph is of that kind! -->
685    <xsl:template name="follows-empty-paragraphs-and-image">
686        <xsl:param name="precedingElement" />
687        <xsl:param name="elementToCheck" select="1"/>
688        <xsl:choose>
689            <!-- OOo writes out empty paragraphs layouted behind the image,
690                those have to be neglected in HTML
691            <xsl:when test="name() = 'text:p' and (normalize-space($childText) = '')"> -->
692                <!-- WorkAround: Test if the empty paragraph was added after an image, which OOO often does -->
693            <xsl:when test="(name($precedingElement) = 'text:p' and not($precedingElement/text()) and not($precedingElement/*))">
694                <xsl:call-template name="follows-empty-paragraphs-and-image">
695                    <xsl:with-param name="precedingElement" select="preceding-sibling::*[$elementToCheck]"/>
696                    <xsl:with-param name="elementToCheck" select="$elementToCheck +1"/>
697                </xsl:call-template>
698            </xsl:when>
699            <xsl:when test="$precedingElement/draw:frame">yes</xsl:when>
700            <xsl:otherwise>no</xsl:otherwise>
701        </xsl:choose>
702    </xsl:template>
703
704    <xsl:template name="create-paragraph">
705        <xsl:param name="globalData"/>
706        <!-- the footnote symbol is the prefix for a footnote in the footer -->
707        <xsl:param name="footnotePrefix"/>
708
709        <!-- xhtml:p may only contain inline elements.
710             If there is one frame beyond, div must be used! -->
711        <xsl:variable name="elementName">
712            <xsl:choose>
713                <xsl:when test="descendant::draw:frame[1] or descendant::text:p[1]">div</xsl:when>
714                <xsl:otherwise>p</xsl:otherwise>
715            </xsl:choose>
716        </xsl:variable>
717        <xsl:if test="name() = 'text:p' and $elementName = 'div'">
718            <xsl:comment>Next 'div' was a 'text:p'.</xsl:comment>
719            <xsl:text>&#xa;</xsl:text>
720        </xsl:if>
721        <xsl:element name="{$elementName}">
722            <xsl:choose>
723                <!-- in ODF borders of paragraphs will be merged by default. Merging means the adjacent paragraphs are building a unit,
724                    where only the first and the last will have a border to the surrounding (top / bottom border)
725                                                <xsl:variable name="precedingParagraphStyle" select="preceding-sibling::*[1][name() = 'text:p']/@text:style-name"/>
726                    <xsl:variable name="followingParagraphStyle" select="following-sibling::*[1][name() = 'text:p']/@text:style-name"/>
727                    -->
728                <xsl:when test="$globalData/all-styles/style[@style:name = current()/@text:style-name]/@mergedBorders">
729                    <xsl:variable name="precedingParagraphStyle" select="preceding-sibling::*[1][name() = 'text:p']/@text:style-name"/>
730                    <xsl:variable name="followingParagraphStyle" select="following-sibling::*[1][name() = 'text:p']/@text:style-name"/>
731                    <xsl:choose>
732                        <xsl:when test="$precedingParagraphStyle or $followingParagraphStyle">
733                            <xsl:variable name="isPrecedingBorderParagraph" select="$globalData/all-styles/style[@style:name = $precedingParagraphStyle]/@mergedBorders"/>
734                            <xsl:variable name="isFollowingBorderParagraph" select="$globalData/all-styles/style[@style:name = $followingParagraphStyle]/@mergedBorders"/>
735                            <xsl:choose>
736                                <xsl:when test="not($isPrecedingBorderParagraph) and $isFollowingBorderParagraph">
737                                    <xsl:attribute name="class">
738                                        <xsl:value-of select="concat(translate(@text:style-name, '.,;: %()[]/\+', '_____________'), '_borderStart')"/>
739                                    </xsl:attribute>
740                                    <xsl:apply-templates>
741                                        <xsl:with-param name="globalData" select="$globalData"/>
742                                    </xsl:apply-templates>
743                                </xsl:when>
744                                <xsl:when test="$isPrecedingBorderParagraph and not($isFollowingBorderParagraph)">
745                                    <xsl:attribute name="class">
746                                        <xsl:value-of select="concat(translate(@text:style-name, '.,;: %()[]/\+', '_____________'), '_borderEnd')"/>
747                                    </xsl:attribute>
748                                    <xsl:apply-templates>
749                                        <xsl:with-param name="globalData" select="$globalData"/>
750                                    </xsl:apply-templates>
751                                </xsl:when>
752                                <!-- inbetween paragraphs with border/margin -->
753                                <xsl:when test="$isPrecedingBorderParagraph and $isFollowingBorderParagraph">
754                                    <xsl:attribute name="class">
755                                        <xsl:value-of select="concat(translate(@text:style-name, '.,;: %()[]/\+', '_____________'), '_borderSides')"/>
756                                    </xsl:attribute>
757                                    <xsl:apply-templates>
758                                        <xsl:with-param name="globalData" select="$globalData"/>
759                                    </xsl:apply-templates>
760                                </xsl:when>
761                                <xsl:otherwise>
762                                    <xsl:call-template name="write-paragraph">
763                                        <xsl:with-param name="globalData" select="$globalData"/>
764                                    </xsl:call-template>
765                                </xsl:otherwise>
766                            </xsl:choose>
767                        </xsl:when>
768                        <xsl:otherwise>
769                            <xsl:call-template name="write-paragraph">
770                                <xsl:with-param name="globalData" select="$globalData"/>
771                            </xsl:call-template>
772                        </xsl:otherwise>
773                    </xsl:choose>
774                </xsl:when>
775                <xsl:otherwise>
776                    <xsl:call-template name="write-paragraph">
777                        <xsl:with-param name="globalData" select="$globalData" />
778                        <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
779                    </xsl:call-template>
780                </xsl:otherwise>
781            </xsl:choose>
782        </xsl:element>
783    </xsl:template>
784
785    <xsl:template name="write-paragraph">
786        <xsl:param name="globalData"/>
787        <!-- the footnote symbol is the prefix for a footnote in the footer -->
788        <xsl:param name="footnotePrefix" />
789
790            <!-- empty paragraph tags does not provoke a carriage return,
791                therefore a non breakable space (&nbsp) have been inserted.-->
792        <xsl:choose>
793            <xsl:when test="node()">
794                <xsl:call-template name="apply-styles-and-content">
795                    <xsl:with-param name="globalData" select="$globalData" />
796                    <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
797                </xsl:call-template>
798            </xsl:when>
799            <xsl:otherwise>
800                <xsl:call-template name="apply-styles-and-content">
801                    <xsl:with-param name="globalData" select="$globalData" />
802                    <xsl:with-param name="footnotePrefix" select="$footnotePrefix" />
803                </xsl:call-template>
804                <xsl:text>&#160;</xsl:text>
805            </xsl:otherwise>
806        </xsl:choose>
807    </xsl:template>
808
809    <xsl:template match="style:tab-stop/@style:type">
810        <xsl:text>text-align:</xsl:text>
811        <xsl:choose>
812            <xsl:when test=". = 'left'">left</xsl:when>
813            <xsl:when test=". = 'right'">right</xsl:when>
814            <xsl:when test=". = 'center'">center</xsl:when>
815            <xsl:otherwise>justify</xsl:otherwise>
816        </xsl:choose>
817        <xsl:text>;</xsl:text>
818    </xsl:template>
819
820    <!-- As soon a frame is within a paragraph (text:p) or page:frame, every child element is floating (CSS) and worked out in sequence.
821    Accumulating prior frame width and adding parent's left margin -->
822    <!-- Matching all elements and text beyond a paragraph/text:page which are sibling of a draw:frame -->
823    <xsl:template match="* | text()" mode="frameFloating">
824        <xsl:param name="globalData"/>
825        <xsl:param name="previousFrameWidths" select="0"/>
826        <xsl:param name="previousFrameHeights" select="0" />
827        <xsl:param name="leftPosition" select="0" />
828        <xsl:param name="parentMarginLeft" />
829        <xsl:param name="stopAtFirstFrame" select="false()" />
830
831        <xsl:choose>
832            <xsl:when test="name() = 'draw:frame' and not($stopAtFirstFrame)">
833                <!-- if the first node is a draw:frame create a div -->
834                <xsl:call-template name="createDrawFrame">
835                    <xsl:with-param name="globalData" select="$globalData"/>
836                    <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
837                    <xsl:with-param name="previousFrameHeights" select="$previousFrameHeights"/>
838                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
839                </xsl:call-template>
840                <!-- next elements will be called after the creation with the new indent (plus width of frame) -->
841            </xsl:when>
842            <xsl:otherwise>
843                <xsl:variable name="nextSiblingIsFrame" select="name(following-sibling::node()[1]) = 'draw:frame'"/>
844                <xsl:choose>
845                    <xsl:when test="normalize-space(.) != ''">
846                        <!-- every following frame sibling till the next draw:frame
847                            have to be encapsulated within a div with left indent.
848                            To be moved altogether according the indent (usually right) -->
849                        <xsl:text>&#xa;</xsl:text>
850                        <xsl:comment>Next 'div' added for floating.</xsl:comment>
851                        <xsl:text>&#xa;</xsl:text>
852                        <xsl:element name="div">
853                            <xsl:attribute name="style">
854                                <xsl:text>display:inline; position:relative; left:</xsl:text>
855                                <xsl:value-of select="$leftPosition"/>
856                                <xsl:text>cm;</xsl:text>
857                            </xsl:attribute>
858                            <xsl:apply-templates select=".">
859                                <xsl:with-param name="globalData" select="$globalData"/>
860                            </xsl:apply-templates>
861                            <!-- if it is a frame sibling it will be NOT encapsulated within the div (as already within one) -->
862                            <xsl:if test="not($nextSiblingIsFrame)">
863                                <xsl:apply-templates select="following-sibling::node()[1]" mode="frameFloating">
864                                    <xsl:with-param name="globalData" select="$globalData"/>
865                                    <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
866                                    <xsl:with-param name="previousFrameHeights" select="$previousFrameHeights"/>
867                                    <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
868                                    <xsl:with-param name="leftPosition" select="$leftPosition"/>
869                                    <xsl:with-param name="stopAtFirstFrame" select="$stopAtFirstFrame" />
870                                </xsl:apply-templates>
871                            </xsl:if>
872                        </xsl:element>
873
874                        <!-- Other draw:frame will be created outside of the div element  -->
875                        <xsl:if test="nextSiblingIsFrame and not(stopAtFirstFrame)">
876                            <xsl:apply-templates select="following-sibling::draw:frame[1]" mode="frameFloating">
877                                <xsl:with-param name="globalData" select="$globalData"/>
878                                <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
879                                <xsl:with-param name="previousFrameHeights" select="$previousFrameHeights"/>
880                                <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
881                                <xsl:with-param name="leftPosition" select="$leftPosition"/>
882                                <xsl:with-param name="stopAtFirstFrame" select="$stopAtFirstFrame" />
883                            </xsl:apply-templates>
884                        </xsl:if>
885                    </xsl:when>
886                    <xsl:otherwise>
887                        <xsl:apply-templates select=".">
888                            <xsl:with-param name="globalData" select="$globalData"/>
889                        </xsl:apply-templates>
890                        <xsl:if test="not($nextSiblingIsFrame)">
891                            <xsl:apply-templates select="following-sibling::node()[1]" mode="frameFloating">
892                                <xsl:with-param name="globalData" select="$globalData"/>
893                                <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
894                                <xsl:with-param name="previousFrameHeights" select="$previousFrameHeights"/>
895                                <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
896                                <xsl:with-param name="leftPosition" select="$leftPosition"/>
897                                <xsl:with-param name="stopAtFirstFrame" select="$stopAtFirstFrame" />
898                            </xsl:apply-templates>
899                        </xsl:if>
900                    </xsl:otherwise>
901                </xsl:choose>
902            </xsl:otherwise>
903        </xsl:choose>
904    </xsl:template>
905
906    <!-- A XML node other than text or element (e.g. comment) should not stop the recursion  -->
907    <xsl:template match="comment()" mode="frameFloating">
908        <xsl:param name="globalData"/>
909        <xsl:param name="previousFrameWidths" select="0"/>
910        <xsl:param name="previousFrameHeights" select="0" />
911        <xsl:param name="leftPosition" />
912        <xsl:param name="parentMarginLeft" />
913        <xsl:param name="stopAtFirstFrame" select="false()" />
914
915        <xsl:apply-templates select="following-sibling::node()[1]" mode="frameFloating">
916            <xsl:with-param name="globalData" select="$globalData"/>
917            <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
918            <xsl:with-param name="parentMarginLeft" select="$parentMarginLeft"/>
919            <xsl:with-param name="leftPosition" select="$leftPosition"/>
920            <xsl:with-param name="stopAtFirstFrame" select="$stopAtFirstFrame" />
921        </xsl:apply-templates>
922    </xsl:template>
923
924
925
926    <!-- As draw:frame may occur within more elements than in text:p and draw:page -->
927    <xsl:template match="draw:frame">
928        <xsl:param name="globalData"/>
929        <xsl:param name="previousFrameWidths" select="0"/>
930        <xsl:param name="previousFrameHeights" select="0" />
931
932        <xsl:call-template name="createDrawFrame">
933            <xsl:with-param name="globalData" select="$globalData" />
934            <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths"/>
935            <xsl:with-param name="previousFrameHeights" select="$previousFrameHeights"/>
936        </xsl:call-template>
937        <!-- after the last draw:frame sibling the CSS float is disabled -->
938        <xsl:if test="@text:anchor-type!='as-char'">
939            <div style="clear:both; line-height:0; width:0; height:0; margin:0; padding:0;">&#160;</div>
940        </xsl:if>
941    </xsl:template>
942
943    <xsl:template name="getPageMarginLeft">
944        <!-- approximation to find the correct master page style (with page dimensions) -->
945        <xsl:variable name="masterPageNames">
946            <!-- Loop over every style:style containing a @style:master-page-name attribute -->
947            <xsl:for-each select="key('masterPage','count')">
948                    <!-- Check if this style is being used in the body -->
949                <xsl:if test="key('elementUsingStyle', ../@style:name)">
950                        <!-- Check every master-page-name if it is not empty and return as ';' separated list  -->
951                    <xsl:if test="string-length(../@style:master-page-name) &gt; 0">
952                        <xsl:value-of select="../@style:master-page-name"/>;
953                    </xsl:if>
954                </xsl:if>
955            </xsl:for-each>
956        </xsl:variable>
957        <!-- Take the first of the masterpage list and get the according style:master-page element and find the @style:page-layout-name  -->
958        <xsl:variable name="pageLayoutName" select="key('masterPageElements', substring-before($masterPageNames,';'))/@style:page-layout-name"/>
959         <!-- Find the according style:page-layout and store the properties in a variable  -->
960        <xsl:variable name="pageMarginLeftAttr" select="key('pageLayoutElements', $pageLayoutName)/style:page-layout-properties/@fo:margin-left"/>
961        <xsl:choose>
962            <xsl:when test="$pageMarginLeftAttr">
963                <xsl:call-template name="convert2cm">
964                    <xsl:with-param name="value" select="$pageMarginLeftAttr"/>
965                </xsl:call-template>
966            </xsl:when>
967            <xsl:otherwise>0</xsl:otherwise>
968        </xsl:choose>
969    </xsl:template>
970
971    <!-- Elements and text aside of a draw:frame are floating, here a div is being created.
972        Either for a draw:frame or for text and other elements floating aside -->
973    <xsl:template name="createDrawFrame">
974        <xsl:param name="globalData"/>
975        <xsl:param name="previousFrameWidths" select="0"/>
976        <xsl:param name="previousFrameHeights" select="0" />
977        <xsl:param name="parentMarginLeft"/>
978        <xsl:param name="stopAtFirstFrame" select="false()" />
979
980        <xsl:variable name="parentMarginLeftNew">
981            <xsl:choose>
982                <xsl:when test="string-length(normalize-space($parentMarginLeft)) &lt; 1">
983                    <!-- Styles of first paragraph in list item, including ancestor styles (inheritance) -->
984                    <xsl:variable name="paragraphName" select="parent::*/@text:style-name" />
985                    <xsl:variable name="imageParagraphStyle" select="$globalData/all-styles/style[@style:name = $paragraphName]/final-properties"/>
986                    <!-- Only the left margin of the first paragraph of a list item will be added to the margin of the complete list (all levels)-->
987                    <xsl:choose>
988                        <xsl:when test="contains($imageParagraphStyle, 'margin-left:')">
989                            <xsl:call-template name="convert2cm">
990                                <xsl:with-param name="value" select="normalize-space(substring-before(substring-after($imageParagraphStyle, 'margin-left:'), ';'))"/>
991                            </xsl:call-template>
992                        </xsl:when>
993                        <xsl:otherwise>0</xsl:otherwise>
994                    </xsl:choose>
995                </xsl:when>
996                <xsl:otherwise>
997                    <xsl:value-of select="normalize-space($parentMarginLeft)" />
998                </xsl:otherwise>
999            </xsl:choose>
1000        </xsl:variable>
1001        <xsl:variable name="svgWidth">
1002            <xsl:choose>
1003                <xsl:when test="@svg:width">
1004                    <xsl:call-template name="convert2cm">
1005                        <xsl:with-param name="value" select="@svg:width"/>
1006                    </xsl:call-template>
1007                </xsl:when>
1008                <xsl:otherwise>0</xsl:otherwise>
1009            </xsl:choose>
1010        </xsl:variable>
1011        <xsl:variable name="svgX">
1012            <xsl:choose>
1013                <xsl:when test="@svg:x">
1014                    <xsl:call-template name="convert2cm">
1015                        <xsl:with-param name="value" select="@svg:x"/>
1016                    </xsl:call-template>
1017                </xsl:when>
1018                <xsl:otherwise>0</xsl:otherwise>
1019            </xsl:choose>
1020        </xsl:variable>
1021        <xsl:variable name="leftPosition" select="$svgX - $parentMarginLeftNew - $previousFrameWidths"/>
1022        <xsl:variable name="svgY">
1023            <xsl:choose>
1024                <xsl:when test="@svg:y">
1025                    <xsl:call-template name="convert2cm">
1026                        <xsl:with-param name="value" select="@svg:y"/>
1027                    </xsl:call-template>
1028                </xsl:when>
1029                <xsl:otherwise>0</xsl:otherwise>
1030            </xsl:choose>
1031        </xsl:variable>
1032        <!-- if the frame is anchored on a paragraph -->
1033        <xsl:if test="@text:anchor-type='paragraph'">
1034            <xsl:text>&#xa;</xsl:text>
1035            <xsl:comment>Next 'div' is emulating the top height of a draw:frame.</xsl:comment>
1036            <xsl:text>&#xa;</xsl:text>
1037            <!-- When the svg:y is set relative to the paragraph content, the best way to emulate a positive height,
1038             is to add an invisible division inbetween with a height.
1039             Often text will flow into this 'gap', which is handled separately!
1040             -->
1041            <xsl:if test="$svgY &gt; 0">
1042                <xsl:element name="div">
1043                    <xsl:attribute name="style">
1044                        <xsl:text>height:</xsl:text>
1045                        <xsl:value-of select="$svgY"/>
1046                        <xsl:text>cm;</xsl:text>
1047                    </xsl:attribute>
1048                    <xsl:text>&#160;</xsl:text>
1049                </xsl:element>
1050            </xsl:if>
1051        </xsl:if>
1052        <xsl:call-template name="createDrawFrame2">
1053            <xsl:with-param name="globalData" select="$globalData"/>
1054            <xsl:with-param name="previousFrameWidths" select="$previousFrameWidths + $svgWidth"/>
1055            <xsl:with-param name="parentMarginLeftNew" select="$parentMarginLeftNew"/>
1056            <xsl:with-param name="leftPosition" select="$leftPosition"/>
1057            <xsl:with-param name="svgY" select="$svgY"/>
1058        </xsl:call-template>
1059    </xsl:template>
1060
1061    <xsl:template name="createDrawFrame2">
1062        <xsl:param name="globalData"/>
1063        <xsl:param name="previousFrameWidths" />
1064        <xsl:param name="parentMarginLeftNew"/>
1065        <xsl:param name="leftPosition" />
1066        <xsl:param name="svgY" />
1067
1068        <xsl:variable name="elem-name">
1069            <xsl:choose>
1070                <xsl:when test="@text:anchor-type='as-char'">span</xsl:when>
1071                <xsl:otherwise>div</xsl:otherwise>
1072            </xsl:choose>
1073        </xsl:variable>
1074        <xsl:text>&#xa;</xsl:text>
1075        <xsl:comment>Next '<xsl:value-of select="$elem-name"/>' is a draw:frame. </xsl:comment>
1076        <xsl:text>&#xa;</xsl:text>
1077        <xsl:element name="{$elem-name}">
1078            <xsl:choose>
1079                <xsl:when test="draw:object/math:math">
1080                    <!-- draw:frame elements contain many data that are not
1081                    relevant for mathematical formulas and that may
1082                    cause incorrect rendering. Let's ignore the
1083                    replacement image and keep only the id attribute.
1084                    See fdo#66645 -->
1085                    <xsl:apply-templates select="@draw:name"/>
1086                    <xsl:apply-templates select="draw:object[1]"/><xsl:text> </xsl:text><!-- often trailing whitespace is missing -->
1087                </xsl:when>
1088                <xsl:otherwise>
1089                    <xsl:attribute name="style">
1090                    <xsl:call-template name="widthAndHeight"/>
1091                    <xsl:text> padding:0; </xsl:text>
1092                    <xsl:choose>
1093                        <xsl:when test="@text:anchor-type='as-char'">
1094                            <!-- images being used as character are not floating and are not positioned (CSS position:static being the default)-->
1095                            <!--<xsl:text> position:static;</xsl:text>-->
1096                        </xsl:when>
1097                        <xsl:when test="@text:anchor-type!='as-char'">
1098                            <!-- all images float (CSS float relative) with a left position calculated by svg:x - parentMarginLeft - previousFrameWidths -->
1099                            <xsl:text> float:left; position:relative; left:</xsl:text>
1100                                    <xsl:value-of select="$leftPosition" />
1101                            <xsl:text>cm; </xsl:text>
1102                            <!-- if the frame is anchored on a char -->
1103                            <xsl:if test="@text:anchor-type='char'">
1104                                <xsl:text>top:</xsl:text>
1105                                        <xsl:value-of select="$svgY" />
1106                                <xsl:text>cm; </xsl:text>
1107                            </xsl:if>
1108                        </xsl:when>
1109                        <!-- if there is no attribute @text:anchor-type -->
1110                        <xsl:otherwise>
1111                                <xsl:text> position:absolute; left:</xsl:text>
1112                                    <xsl:value-of select="$leftPosition" />
1113                            <xsl:text>cm; </xsl:text>
1114                            <xsl:text>top:</xsl:text>
1115                                    <xsl:value-of select="$svgY" />
1116                            <xsl:text>cm; </xsl:text>
1117                        </xsl:otherwise>
1118                    </xsl:choose>
1119                </xsl:attribute>
1120                <xsl:apply-templates select="@*">
1121                    <xsl:with-param name="globalData" select="$globalData"/>
1122                </xsl:apply-templates>
1123                <xsl:apply-templates select="node()">
1124                    <xsl:with-param name="globalData" select="$globalData"/>
1125                </xsl:apply-templates>
1126                </xsl:otherwise>
1127            </xsl:choose>
1128        </xsl:element>
1129    </xsl:template>
1130
1131    <xsl:template match="svg:desc"/>
1132
1133    <xsl:template name="widthAndHeight">
1134        <xsl:if test="@svg:height | @svg:width">
1135            <xsl:choose>
1136                <xsl:when test="not(@svg:width)">
1137                    <xsl:call-template name="svg:height"/>
1138                </xsl:when>
1139                <xsl:when test="not(@svg:height)">
1140                    <xsl:call-template name="svg:width"/>
1141                </xsl:when>
1142                <xsl:otherwise>
1143                    <xsl:call-template name="svg:height"/>
1144                    <xsl:call-template name="svg:width"/>
1145                </xsl:otherwise>
1146            </xsl:choose>
1147        </xsl:if>
1148    </xsl:template>
1149
1150    <!-- ***************** -->
1151    <!-- *** Text Span *** -->
1152    <!-- ***************** -->
1153
1154    <xsl:template match="text:span">
1155        <xsl:param name="globalData"/>
1156
1157        <xsl:choose>
1158            <xsl:when test="draw:frame">
1159                <!-- sometimes an ODF image is anchored as character and the
1160                    image frame appears within a span (which is not valid for HTML)
1161                    Heuristic: Neglecting the span assuming no text content aside
1162                    of frame within span -->
1163                <xsl:apply-templates>
1164                    <xsl:with-param name="globalData" select="$globalData"/>
1165                </xsl:apply-templates>
1166            </xsl:when>
1167            <xsl:otherwise>
1168                <xsl:element name="span">
1169                    <xsl:call-template name="apply-styles-and-content">
1170                        <xsl:with-param name="globalData" select="$globalData"/>
1171                    </xsl:call-template>
1172                </xsl:element>
1173            </xsl:otherwise>
1174        </xsl:choose>
1175    </xsl:template>
1176
1177
1178
1179    <!-- **************** -->
1180    <!-- *** Headings *** -->
1181    <!-- **************** -->
1182
1183    <xsl:template match="text:h">
1184        <xsl:param name="globalData"/>
1185
1186        <!-- no creation of empty headings (without text content)   -->
1187        <xsl:if test="text() or descendant::text()">
1188            <!-- The URL linking of a table-of-content is due to a bug (cp. bug id# 102311) not mapped as URL in the XML.
1189                 Linking of the table-of-content can therefore only be achieved by a work-around in HTML -->
1190            <xsl:call-template name="create-heading">
1191                <xsl:with-param name="globalData" select="$globalData"/>
1192            </xsl:call-template>
1193        </xsl:if>
1194    </xsl:template>
1195
1196    <!-- default matching for header elements -->
1197    <xsl:template name="create-heading">
1198        <xsl:param name="globalData"/>
1199
1200        <xsl:variable name="headingLevel">
1201            <xsl:choose>
1202                <xsl:when test="@text:outline-level &lt; 6">
1203                    <xsl:value-of select="@text:outline-level"/>
1204                </xsl:when>
1205                <xsl:otherwise>6</xsl:otherwise>
1206            </xsl:choose>
1207        </xsl:variable>
1208        <xsl:variable name="headertyp" select="concat('h', $headingLevel)"/>
1209        <xsl:element name="{$headertyp}">
1210            <!-- outline style 'text:min-label-width' is interpreted as a CSS 'margin-right' attribute
1211            NOTE: Should be handled as CSS style in style header -->
1212            <xsl:variable name="min-label" select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/*/@text:min-label-width"/>
1213            <xsl:attribute name="class">
1214                <xsl:call-template name="create-unique-style-id">
1215                    <xsl:with-param name="styleName" select="@text:style-name"/>
1216                    <xsl:with-param name="styleFamily" select="'paragraph'"/>
1217                </xsl:call-template>
1218            </xsl:attribute>
1219
1220            <!-- inline heading -->
1221            <xsl:if test="parent::draw:text-box and ../../@text:anchor-type='as-char'">
1222                <xsl:attribute name="style">
1223                    <xsl:text>display:inline;</xsl:text>
1224                </xsl:attribute>
1225            </xsl:if>
1226
1227            <xsl:call-template name="create-heading-anchor">
1228                <xsl:with-param name="globalData" select="$globalData"/>
1229            </xsl:call-template>
1230
1231            <xsl:apply-templates>
1232                <xsl:with-param name="globalData" select="$globalData"/>
1233            </xsl:apply-templates>
1234        </xsl:element>
1235
1236        <!-- add new line, except for inline headings to avoid of double spaces -->
1237        <xsl:if test="not(parent::draw:text-box and ../../@text:anchor-type='as-char')">
1238            <xsl:text>&#xa;</xsl:text>
1239        </xsl:if>
1240    </xsl:template>
1241
1242    <xsl:template name="create-heading-anchor">
1243        <xsl:param name="globalData"/>
1244
1245        <!-- writing out a heading number if desired.-->
1246        <!-- if a corresponding 'text:outline-style' exist or is not empty -->
1247        <xsl:choose>
1248            <xsl:when test="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/@style:num-format != '' and not(@text:is-list-header='true')">
1249
1250                <!-- Every heading element will get a unique anchor for its file, from its hierarchy level and name:
1251                     For example:  The heading title 'My favorite heading' might get <a name="1_2_2_My_favorite_heading" /> -->
1252                <!-- creating an anchor for referencing the heading (e.g. from content table) -->
1253                <xsl:variable name="headingNumber">
1254                    <xsl:call-template name="get-heading-number">
1255                        <xsl:with-param name="globalData" select="$globalData"/>
1256                    </xsl:call-template>
1257                </xsl:variable>
1258                <xsl:call-template name="create-heading-anchor2">
1259                    <xsl:with-param name="globalData" select="$globalData"/>
1260                    <xsl:with-param name="headingNumber" select="$headingNumber"/>
1261                </xsl:call-template>
1262            </xsl:when>
1263            <xsl:otherwise>
1264                <xsl:call-template name="create-heading-anchor2">
1265                    <xsl:with-param name="globalData" select="$globalData"/>
1266                </xsl:call-template>
1267            </xsl:otherwise>
1268        </xsl:choose>
1269    </xsl:template>
1270
1271
1272    <xsl:template name="get-heading-number">
1273        <xsl:param name="globalData"/>
1274
1275        <!-- write number prefix -->
1276        <xsl:value-of select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/@style:num-prefix"/>
1277        <xsl:call-template name="write-heading-number">
1278            <xsl:with-param name="globalData" select="$globalData"/>
1279        </xsl:call-template>
1280        <!-- write number suffix -->
1281        <xsl:value-of select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/@style:num-suffix"/>
1282    </xsl:template>
1283
1284    <!-- creating an anchor for referencing the heading -->
1285    <xsl:template name="create-heading-anchor2">
1286        <xsl:param name="globalData"/>
1287        <xsl:param name="headingNumber" />
1288
1289        <xsl:variable name="title">
1290            <xsl:apply-templates mode="concatenate"/>
1291        </xsl:variable>
1292        <!-- REFERENCE HANDLING - ANCHOR -->
1293        <xsl:element namespace="{$namespace}" name="a">
1294            <xsl:attribute name="id">
1295                <xsl:value-of select="translate(concat('a_',normalize-space($headingNumber), '_', normalize-space($title)), '&#xA;&amp;&lt;&gt;–.,;: %()[]/\+', '____________________________')" disable-output-escaping="yes"/>
1296            </xsl:attribute>
1297
1298            <xsl:element name="span">
1299                <!-- Convert the "label-followed-by" to margins. According to ODF, possible values are: 'listtab', 'space', and 'nothing'.
1300                'space' seems not to be written out by LO, and for 'nothing' we obviously need do nothing.
1301                NOTE: Should be handled as CSS style in style header -->
1302                <xsl:variable name="currentOutlineLevel" select="@text:outline-level"/>
1303                <xsl:variable name="labelFollowedBy" select="$globalData//office:document/office:styles/text:outline-style/text:outline-level-style[@text:level = $currentOutlineLevel]/style:list-level-properties[@text:list-level-position-and-space-mode='label-alignment']/style:list-level-label-alignment/@text:label-followed-by"/>
1304
1305                <!-- Add some margin, but only if there is a number preceding the heading. -->
1306                <xsl:if test="$labelFollowedBy='listtab' and $headingNumber != ''">
1307                    <xsl:attribute name="class">
1308                        <xsl:text>heading_numbering</xsl:text>
1309                    </xsl:attribute>
1310                </xsl:if>
1311                <xsl:copy-of select="$headingNumber"/>
1312            </xsl:element>
1313        </xsl:element>
1314    </xsl:template>
1315
1316    <xsl:template name="write-heading-number">
1317        <xsl:param name="globalData"/>
1318
1319        <!-- By default heading start with '1', the parameter 'textStartValue' will only be set, if the attribute @text:start-value exist -->
1320        <xsl:choose>
1321            <xsl:when test="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/@text:start-value">
1322                <xsl:call-template name="calc-heading-number">
1323                    <xsl:with-param name="globalData" select="$globalData"/>
1324                    <xsl:with-param name="outlineLevel" select="@text:outline-level"/>
1325                    <xsl:with-param name="textStartValue" select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = current()/@text:outline-level]/@text:start-value"/>
1326                </xsl:call-template>
1327            </xsl:when>
1328            <xsl:otherwise>
1329                <xsl:call-template name="calc-heading-number">
1330                    <xsl:with-param name="globalData" select="$globalData"/>
1331                    <xsl:with-param name="outlineLevel" select="@text:outline-level"/>
1332                </xsl:call-template>
1333            </xsl:otherwise>
1334        </xsl:choose>
1335    </xsl:template>
1336
1337    <!--
1338    Find the correct heading no., which is the sum of 'text:start-value'
1339    and preceding siblings of 'text:h' with the same 'text:outline-level' (until a text:outline-level with lower value is found).
1340    If the 'text:start-value is not set the default value of '1' has to be taken.
1341    If a heading number is found (e.g. text:outline-level='3') all heading numbers
1342    for the higher levels have to be written out -->
1343    <xsl:template name="calc-heading-number">
1344        <xsl:param name="globalData"/>
1345        <xsl:param name="outlineLevel"/><!-- text level of the heading -->
1346        <xsl:param name="iOutlineLevel" select="1"/><!-- iterator, counts from 1 to the text level of the heading -->
1347        <xsl:param name="textStartValue" select="1"/><!-- text level to start with, default is '1' -->
1348
1349        <xsl:choose>
1350            <!-- iText levels counts up from '1' to outlineLevel
1351                Which means writing a heading number from left to right -->
1352            <xsl:when test="$iOutlineLevel &lt; $outlineLevel">
1353
1354            <!-- Write preceding heading numbers -->
1355                <xsl:if test="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = ($iOutlineLevel)]/@style:num-format != ''">
1356                    <xsl:call-template name="writeNumber">
1357                        <xsl:with-param name="numberDigit">
1358                            <xsl:call-template name="calc-heading-digit">
1359                                <xsl:with-param name="value" select="0"/>
1360                                <xsl:with-param name="currentoutlineLevel" select="$iOutlineLevel"/>
1361                            </xsl:call-template>
1362                        </xsl:with-param>
1363                        <xsl:with-param name="numberFormat" select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = ($iOutlineLevel)]/@style:num-format"/>
1364                    </xsl:call-template>
1365                </xsl:if>
1366                <xsl:choose>
1367                    <xsl:when test="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = ($iOutlineLevel + 1)]/@text:start-value">
1368                        <xsl:call-template name="calc-heading-number">
1369                            <xsl:with-param name="globalData" select="$globalData"/>
1370                            <xsl:with-param name="outlineLevel" select="$outlineLevel"/>
1371                            <xsl:with-param name="iOutlineLevel" select="$iOutlineLevel + 1"/>
1372                            <xsl:with-param name="textStartValue" select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = ($iOutlineLevel + 1)]/@text:start-value"/>
1373                        </xsl:call-template>
1374                    </xsl:when>
1375                    <xsl:otherwise>
1376                        <xsl:call-template name="calc-heading-number">
1377                            <xsl:with-param name="globalData" select="$globalData"/>
1378                            <xsl:with-param name="outlineLevel" select="$outlineLevel"/>
1379                            <xsl:with-param name="iOutlineLevel" select="$iOutlineLevel + 1"/>
1380                        </xsl:call-template>
1381                    </xsl:otherwise>
1382                </xsl:choose>
1383            </xsl:when>
1384            <xsl:otherwise>
1385                <!-- Write preceding heading numbers -->
1386                <xsl:call-template name="writeNumber">
1387                    <xsl:with-param name="numberDigit">
1388                        <xsl:call-template name="calc-heading-digit">
1389                            <xsl:with-param name="value" select="$textStartValue"/>
1390                            <xsl:with-param name="currentoutlineLevel" select="$iOutlineLevel"/>
1391                        </xsl:call-template>
1392                    </xsl:with-param>
1393                    <xsl:with-param name="numberFormat" select="$globalData/office:styles/text:outline-style/text:outline-level-style[@text:level = $iOutlineLevel]/@style:num-format"/>
1394                    <xsl:with-param name="last" select="true()"/>
1395                </xsl:call-template>
1396            </xsl:otherwise>
1397        </xsl:choose>
1398    </xsl:template>
1399
1400    <xsl:template name="writeNumber">
1401        <xsl:param name="numberDigit"/>
1402        <xsl:param name="numberFormat"/>
1403        <xsl:param name="last"/>
1404
1405        <xsl:choose>
1406            <xsl:when test="not($numberFormat)">
1407                <xsl:number value="$numberDigit" format="1."/>
1408            </xsl:when>
1409            <xsl:otherwise>
1410                <xsl:choose>
1411                    <xsl:when test="$last">
1412                        <xsl:number value="$numberDigit" format="{$numberFormat}"/>
1413                    </xsl:when>
1414                    <xsl:otherwise>
1415                        <xsl:number value="$numberDigit" format="{$numberFormat}."/>
1416                    </xsl:otherwise>
1417                </xsl:choose>
1418            </xsl:otherwise>
1419        </xsl:choose>
1420    </xsl:template>
1421
1422    <xsl:template name="calc-heading-digit">
1423        <xsl:param name="value"/>
1424        <xsl:param name="currentoutlineLevel"/>
1425        <xsl:param name="i" select="1"/>
1426
1427        <xsl:variable name="precedingHeading" select="preceding-sibling::text:h[@text:outline-level &lt;= $currentoutlineLevel][$i]"/>
1428        <xsl:variable name="precedingoutlineLevel" select="$precedingHeading/@text:outline-level"/>
1429        <!-- tdf#107696: if text:h has attribute "is-list-header" with "true" value, it mustn't be counted for numbering -->
1430        <xsl:variable name="precedingoutlineLevel-is-list-header" select="$precedingHeading[@text:is-list-header='true']/@text:outline-level"/>
1431        <xsl:choose>
1432            <xsl:when test="($currentoutlineLevel = $precedingoutlineLevel) and (not($precedingoutlineLevel-is-list-header)) ">
1433                <xsl:call-template name="calc-heading-digit">
1434                    <xsl:with-param name="value" select="$value + 1"/>
1435                    <xsl:with-param name="currentoutlineLevel" select="$currentoutlineLevel"/>
1436                    <xsl:with-param name="i" select="$i + 1"/>
1437                </xsl:call-template>
1438            </xsl:when>
1439            <!-- tdf#107696: case text:h has attribute "is-list-header" with "true" value, we don't increment value -->
1440            <xsl:when test="($currentoutlineLevel = $precedingoutlineLevel) and ($precedingoutlineLevel-is-list-header) ">
1441                <xsl:call-template name="calc-heading-digit">
1442                    <xsl:with-param name="value" select="$value"/>
1443                    <xsl:with-param name="currentoutlineLevel" select="$currentoutlineLevel"/>
1444                    <xsl:with-param name="i" select="$i + 1"/>
1445                </xsl:call-template>
1446            </xsl:when>
1447            <xsl:when test="$currentoutlineLevel &lt; $precedingoutlineLevel">
1448                <xsl:message terminate="yes">this should not happen</xsl:message>
1449            </xsl:when>
1450            <xsl:otherwise>
1451                <xsl:value-of select="$value"/>
1452            </xsl:otherwise>
1453        </xsl:choose>
1454    </xsl:template>
1455
1456    <!-- Neglect Annotations -->
1457    <xsl:template match="office:annotation" mode="concatenate"/>
1458
1459    <!-- Match text:placeholder child nodes (e.g. text) -->
1460    <xsl:template match="text:placeholder">
1461        <xsl:param name="globalData"/>
1462
1463        <xsl:call-template name="apply-styles-and-content">
1464            <xsl:with-param name="globalData" select="$globalData"/>
1465        </xsl:call-template>
1466    </xsl:template>
1467
1468    <!-- ************* -->
1469    <!-- *** Link  *** -->
1470    <!-- ************* -->
1471
1472    <xsl:template match="text:a | draw:a">
1473        <xsl:param name="globalData"/>
1474
1475        <xsl:call-template name="create-common-anchor-link">
1476            <xsl:with-param name="globalData" select="$globalData"/>
1477        </xsl:call-template>
1478    </xsl:template>
1479
1480
1481    <xsl:template name="create-common-anchor-link">
1482        <xsl:param name="globalData"/>
1483
1484        <xsl:element name="a">
1485            <xsl:attribute name="href">
1486                <xsl:call-template name="create-href">
1487                    <xsl:with-param name="href" select="@xlink:href"/>
1488                </xsl:call-template>
1489            </xsl:attribute>
1490            <xsl:call-template name="apply-styles-and-content">
1491                <xsl:with-param name="globalData" select="$globalData"/>
1492            </xsl:call-template>
1493        </xsl:element>
1494    </xsl:template>
1495
1496
1497
1498    <!-- ******************* -->
1499    <!-- *** Image Link  *** -->
1500    <!-- ******************* -->
1501
1502    <!-- currently suggesting that all draw:object-ole elements are images -->
1503    <xsl:template match="draw:image | draw:object-ole">
1504        <xsl:param name="globalData"/>
1505
1506        <!-- If there is a replacement graphic, we take it (only exception is if the main image is svg).
1507             The replacement graphic is a png which browsers are more likely able to render than the
1508             original graphic which might have arbitrary formats. -->
1509        <xsl:if test="(@loext:mime-type = 'image/svg+xml') or
1510                      (@draw:mime-type = 'image/svg+xml') or
1511                            (not(following-sibling::draw:image) and
1512                             not((preceding-sibling::draw:image[1]/@loext:mime-type = 'image/svg+xml')
1513                                 or
1514                                 (preceding-sibling::draw:image[1]/@draw:mime-type = 'image/svg+xml')))">
1515            <xsl:choose>
1516                <xsl:when test="ancestor::text:p or parent::text:span or parent::text:h or parent::draw:a or parent::text:a or text:ruby-base">
1517                    <!-- XHTML does not allow the mapped elements to contain paragraphs -->
1518                    <xsl:call-template name="create-image-element">
1519                        <xsl:with-param name="globalData" select="$globalData"/>
1520                    </xsl:call-template>
1521                </xsl:when>
1522                <xsl:otherwise>
1523                    <!-- images are embedded in a paragraph, but are in CSS not able to express a horizontal alignment for themself.
1524                        A 'div' element taking over the image style would solve that problem, but is invalid as child of a paragraph -->
1525                    <xsl:element name="p">
1526                        <xsl:apply-templates select="@draw:style-name">
1527                            <xsl:with-param name="globalData" select="$globalData"/>
1528                        </xsl:apply-templates>
1529
1530                        <xsl:call-template name="create-image-element">
1531                            <xsl:with-param name="globalData" select="$globalData"/>
1532                        </xsl:call-template>
1533                    </xsl:element>
1534                </xsl:otherwise>
1535            </xsl:choose>
1536        </xsl:if>
1537    </xsl:template>
1538
1539    <xsl:template name="create-image-element">
1540        <xsl:param name="globalData"/>
1541
1542        <xsl:element name="img">
1543            <xsl:if test="../@svg:width or ../@svg:height">
1544                <xsl:attribute name="style">
1545                    <xsl:if test="../@svg:height">
1546                        <xsl:text>height:</xsl:text>
1547                        <xsl:call-template name="convert2cm">
1548                            <xsl:with-param name="value" select="../@svg:height"/>
1549                        </xsl:call-template>
1550                        <xsl:text>cm;</xsl:text>
1551                    </xsl:if>
1552                    <xsl:if test="../@svg:width">
1553                        <xsl:text>width:</xsl:text>
1554                        <xsl:call-template name="convert2cm">
1555                            <xsl:with-param name="value" select="../@svg:width"/>
1556                        </xsl:call-template>
1557                        <xsl:text>cm;</xsl:text>
1558                    </xsl:if>
1559                </xsl:attribute>
1560            </xsl:if>
1561            <xsl:attribute name="alt">
1562                <xsl:choose>
1563                    <xsl:when test="../svg:title">
1564                        <xsl:value-of select="../svg:title"/>
1565                    </xsl:when>
1566                    <xsl:otherwise>
1567                        <xsl:message>
1568    Accessibility Warning:
1569         No alternate text ('svg:title' element) set for
1570         image '
1571                            <xsl:value-of select="@xlink:href"/>'!
1572                        </xsl:message>
1573                    </xsl:otherwise>
1574                </xsl:choose>
1575            </xsl:attribute>
1576
1577            <xsl:attribute name="src">
1578                <xsl:call-template name="create-href">
1579                    <xsl:with-param name="href" select="@xlink:href"/>
1580                    <xsl:with-param name="mimetype">
1581                        <xsl:choose>
1582                            <xsl:when test="@draw:mime-type">
1583                                <xsl:value-of select="@draw:mime-type"/>
1584                            </xsl:when>
1585                            <xsl:otherwise>
1586                                <xsl:value-of select="@loext:mime-type"/>
1587                            </xsl:otherwise>
1588                        </xsl:choose>
1589                    </xsl:with-param>
1590                </xsl:call-template>
1591            </xsl:attribute>
1592
1593            <!-- style interpretation only, as no subelements are allowed for img in XHTML -->
1594            <xsl:apply-templates select="@draw:style-name">
1595                <xsl:with-param name="globalData" select="$globalData"/>
1596            </xsl:apply-templates>
1597        </xsl:element>
1598    </xsl:template>
1599
1600    <!-- ************ -->
1601    <!-- *** list *** -->
1602    <!-- ************ -->
1603    <!--
1604        Due to the requirements below the ODF list functionality is not handled by CSS, but the list labels calculated and written by XSLT.
1605
1606        REQUIREMENTS:
1607        =============
1608
1609        A)
1610        One significant difference between XHTML and Office List elements is that a list without text nodes but only further list children
1611        would not show a list symbol in the Office, but in the browser from XHTML.
1612
1613        B)
1614        Since OASIS Open Document XML (implemented in OOo2.0) only one parent type exists for list items
1615        the 'text:list' element. The XHTML element 'ol', 'ul' will be chosen upon the list style type.
1616
1617        C)
1618        An Office list may be spread over the whole document. Linked by their style and text:continue-numbering='true'.
1619
1620        D)
1621        An Office list can use characters or images as list label.
1622
1623        E)
1624        An Office list can have a prefix and suffix around the list label.
1625
1626        F)
1627        An Office list style may have the attribute consecutive numbering, which resolves in a list counting for all levels
1628
1629        G)
1630        An Office list may (re)start on any arbitrary value by using @text:start-value on the text:list-item
1631
1632        INDENTATION:
1633        ============
1634
1635        The indent of a list label is not only calculated by using the text:space-before of the list level (listLevelStyle), but
1636        as well taking the left margin of the first paragraph (or heading) of the list into account as long it is not negative.
1637
1638        |           MARGIN LEFT                  |                    LABEL                     |        CONTENT-PADDING
1639            @text:space-before (1)               |            @text:min-label-width (1)         |  @text:min-label-distance (1)
1640        | + @fo:left-margin (firstParagraph)     |                                              |
1641
1642
1643        (1) all attributes belong to: text:list-style/$listLevelStyle/style:list-level-properties/@*
1644            $listLevelStyle might be one of three choices:
1645                1) <text:list-level-style-number>
1646                2) <text:list-level-style-bullet>
1647                3) <text:list-level-style-image>
1648
1649    For example:
1650    <text:list-style style:name="Appendix">
1651        <text:list-level-style-number text:level="1" text:style-name="Zeichenformat" style:num-prefix="Appendix " style:num-suffix=". " style:num-format="A" style:num-letter-sync="true">
1652            <style:list-level-properties text:min-label-width="0.762cm" text:min-label-distance="0.127cm"/>
1653        </text:list-level-style-number>
1654        <text:list-level-style-number text:level="2" text:style-name="Zeichenformat" style:num-suffix="." style:num-format="1" text:display-levels="2">
1655             <style:list-level-properties text:min-label-width="1.016cm"/>
1656        </text:list-level-style-number>
1657    -->
1658    <xsl:key name="listStyles" match=" /*/office:styles/text:list-style | /*/office:automatic-styles/text:list-style | /*/office:styles/style:graphic-properties/text:list-style | /*/office:automatic-styles/style:graphic-properties/text:list-style | /*/office:styles/text:list-style | /*/office:automatic-styles/text:list-style | /*/office:styles/style:graphic-properties/text:list-style | /*/office:automatic-styles/style:graphic-properties/text:list-style" use="@style:name"/>
1659
1660    <!--
1661        A text list may only have text:list-item and text:list-header as children.
1662    -->
1663    <xsl:template match="text:list">
1664        <xsl:param name="globalData"/>
1665        <xsl:param name="isListNumberingReset"/>
1666        <xsl:param name="isNextLevelNumberingReset"/>
1667        <xsl:param name="listLevel" select="count(ancestor::text:list) + 1"/>
1668        <xsl:param name="listRestart" select="false()"/>
1669        <xsl:param name="itemLabel" select="''"/>
1670        <xsl:param name="listStyle"/>
1671        <xsl:param name="listStyleName" select="@text:style-name"/>
1672
1673        <!-- To choose list type - get the list style, with the same 'text:style-name' and same 'text:level' >-->
1674        <xsl:variable name="listStyleRTF">
1675            <xsl:variable name="listStyleInContentFile" select="key('listStyles', $listStyleName)"/>
1676            <xsl:choose>
1677                <xsl:when test="$listStyleInContentFile">
1678                    <xsl:copy-of select="$listStyleInContentFile"/>
1679                </xsl:when>
1680                <xsl:when test="$globalData/office:styles/text:list-style[@style:name = $listStyleName]">
1681                    <xsl:copy-of select="$globalData/office:styles/text:list-style[@style:name = $listStyleName]"/>
1682                </xsl:when>
1683                <xsl:when test="$globalData/office:styles/style:graphic-properties/text:list-style[@style:name = $listStyleName]">
1684                    <xsl:copy-of select="$globalData/office:styles/style:graphic-properties/text:list-style[@style:name = $listStyleName]"/>
1685                </xsl:when>
1686            </xsl:choose>
1687        </xsl:variable>
1688
1689        <xsl:choose>
1690            <xsl:when test="function-available('common:node-set')">
1691                <xsl:call-template name="create-list-type">
1692                    <xsl:with-param name="listStyle" select="common:node-set($listStyleRTF)" />
1693                    <xsl:with-param name="globalData" select="$globalData"/>
1694                    <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
1695                    <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
1696                    <xsl:with-param name="listLevel" select="$listLevel"/>
1697                    <xsl:with-param name="listRestart" select="$listRestart"/>
1698                    <xsl:with-param name="itemLabel" select="$itemLabel"/>
1699                    <xsl:with-param name="listStyleName" select="$listStyleName" />
1700                </xsl:call-template>
1701            </xsl:when>
1702            <xsl:when test="function-available('xalan:nodeset')">
1703                <xsl:call-template name="create-list-type">
1704                    <xsl:with-param name="listStyle" select="xalan:nodeset($listStyleRTF)" />
1705                    <xsl:with-param name="globalData" select="$globalData"/>
1706                    <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
1707                    <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
1708                    <xsl:with-param name="listLevel" select="$listLevel"/>
1709                    <xsl:with-param name="listRestart" select="$listRestart"/>
1710                    <xsl:with-param name="itemLabel" select="$itemLabel"/>
1711                    <xsl:with-param name="listStyleName" select="$listStyleName" />
1712                </xsl:call-template>
1713            </xsl:when>
1714            <xsl:when test="function-available('xt:node-set')">
1715                <xsl:call-template name="create-list-type">
1716                    <xsl:with-param name="listStyle" select="xt:node-set($listStyleRTF)" />
1717                    <xsl:with-param name="globalData" select="$globalData"/>
1718                    <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
1719                    <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
1720                    <xsl:with-param name="listLevel" select="$listLevel"/>
1721                    <xsl:with-param name="listRestart" select="$listRestart"/>
1722                    <xsl:with-param name="itemLabel" select="$itemLabel"/>
1723                    <xsl:with-param name="listStyleName" select="$listStyleName" />
1724                </xsl:call-template>
1725            </xsl:when>
1726            <xsl:otherwise>
1727                <xsl:message terminate="yes">The required node-set function was not found!</xsl:message>
1728            </xsl:otherwise>
1729        </xsl:choose>
1730    </xsl:template>
1731
1732    <xsl:template name="create-list-type">
1733        <xsl:param name="globalData"/>
1734        <xsl:param name="isListNumberingReset"/>
1735        <xsl:param name="isNextLevelNumberingReset"/>
1736        <xsl:param name="listLevel" />
1737        <xsl:param name="listRestart" />
1738        <xsl:param name="itemLabel"/>
1739        <xsl:param name="listStyle"/>
1740        <xsl:param name="listStyleName" />
1741
1742        <!-- $globalData/styles-file/*/office:styles/ -->
1743        <xsl:variable name="listLevelStyle" select="$listStyle/*/*[@text:level = number($listLevel)]"/>
1744        <!-- TODO: Access new list styles
1745        <xsl:variable name="listLevelLabelAlignment1" select="$listLevelStyle/style:list-level-properties/style:list-level-label-alignment"/>-->
1746        <xsl:variable name="listIndent">
1747            <xsl:call-template name="getListIndent">
1748                <xsl:with-param name="globalData" select="$globalData"/>
1749                <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
1750                <xsl:with-param name="firstPara" select="*[1]/*[name() = 'text:p' or name() = 'text:h'][1]"/>
1751            </xsl:call-template>
1752        </xsl:variable>
1753        <xsl:variable name="isEmptyList" select="not(*[1]/*[name() = 'text:h' or name() = 'text:p' or name() = 'text:name'])"/>
1754        <xsl:variable name="listType">
1755            <xsl:choose>
1756                <!-- ordered list -->
1757                <xsl:when test="name($listLevelStyle) = 'text:list-level-style-number'">
1758                    <xsl:text>ol</xsl:text>
1759                </xsl:when>
1760                <!-- unordered list (bullet or image) -->
1761                <xsl:otherwise>
1762                    <xsl:text>ul</xsl:text>
1763                </xsl:otherwise>
1764            </xsl:choose>
1765        </xsl:variable>
1766
1767        <xsl:element name="{$listType}">
1768            <xsl:apply-templates select="*[1]" mode="listItemSibling">
1769                <xsl:with-param name="globalData" select="$globalData"/>
1770                <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
1771                <xsl:with-param name="isListNumberingReset" select="$isNextLevelNumberingReset"/>
1772                <xsl:with-param name="isNextLevelNumberingReset">
1773                    <xsl:choose>
1774                        <xsl:when test="$isListNumberingReset">
1775                            <xsl:value-of select="true()"/>
1776                        </xsl:when>
1777                        <xsl:otherwise>
1778                            <!-- A list is empty if a text:list does not have a text:list-header or text:list-item (wildcard as only those can exist beyond a text:list), which contains a text:h or text:p -->
1779                            <xsl:value-of select="not($isEmptyList)"/>
1780                        </xsl:otherwise>
1781                    </xsl:choose>
1782                </xsl:with-param>
1783                <xsl:with-param name="itemLabel" select="$itemLabel"/>
1784                <xsl:with-param name="listIndent" select="$listIndent"/>
1785                <xsl:with-param name="listLevel" select="$listLevel"/>
1786                <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
1787                <xsl:with-param name="listRestart">
1788                    <xsl:choose>
1789                        <xsl:when test="$listRestart">
1790                            <xsl:value-of select="$listRestart"/>
1791                        </xsl:when>
1792                        <xsl:otherwise>
1793                            <!-- descendants restart their list numbering, when an ancestor is not empty -->
1794                            <xsl:value-of select="not($isEmptyList)"/>
1795                        </xsl:otherwise>
1796                    </xsl:choose>
1797                </xsl:with-param>
1798                <xsl:with-param name="listStyle" select="$listStyle"/>
1799                <xsl:with-param name="listStyleName" select="$listStyleName"/>
1800                <xsl:with-param name="minLabelDist">
1801                    <xsl:choose>
1802                        <xsl:when test="$listLevelStyle/*/@text:min-label-distance">
1803                            <xsl:call-template name="convert2cm">
1804                                <xsl:with-param name="value" select="$listLevelStyle/*/@text:min-label-distance"/>
1805                            </xsl:call-template>
1806                        </xsl:when>
1807                        <xsl:otherwise>0</xsl:otherwise>
1808                    </xsl:choose>
1809                </xsl:with-param>
1810                <xsl:with-param name="minLabelWidth">
1811                    <xsl:choose>
1812                        <xsl:when test="$listLevelStyle/*/@text:min-label-width">
1813                            <xsl:call-template name="convert2cm">
1814                                <xsl:with-param name="value" select="$listLevelStyle/*/@text:min-label-width"/>
1815                            </xsl:call-template>
1816                        </xsl:when>
1817                        <xsl:otherwise>0</xsl:otherwise>
1818                    </xsl:choose>
1819                </xsl:with-param>
1820            </xsl:apply-templates>
1821        </xsl:element>
1822    </xsl:template>
1823
1824    <!-- See comment before text:list template -->
1825    <xsl:template name="getListIndent">
1826        <xsl:param name="globalData"/>
1827        <xsl:param name="listLevelStyle"/>
1828        <!-- The first paragraph of the list item (heading is special paragraph in ODF) -->
1829        <xsl:param name="firstPara" />
1830
1831        <!-- Styles of first paragraph in list item, including ancestor styles (inheritance) -->
1832        <xsl:variable name="firstParaStyles" select="$globalData/all-styles/style[@style:name = $firstPara/@text:style-name]/final-properties"/>
1833
1834        <!-- Only the left margin of the first paragraph of a list item will be added to the margin of the complete list (all levels)-->
1835        <xsl:variable name="firstParaLeftMargin">
1836            <xsl:choose>
1837                <xsl:when test="contains($firstParaStyles, 'margin-left:')">
1838                    <xsl:call-template name="convert2cm">
1839                        <xsl:with-param name="value" select="normalize-space(substring-before(substring-after($firstParaStyles, 'margin-left:'), ';'))"/>
1840                    </xsl:call-template>
1841                </xsl:when>
1842                <xsl:otherwise>0</xsl:otherwise>
1843            </xsl:choose>
1844        </xsl:variable>
1845        <xsl:variable name="spaceBefore">
1846            <xsl:choose>
1847                <xsl:when test="$listLevelStyle/*/@text:space-before">
1848                    <xsl:call-template name="convert2cm">
1849                        <xsl:with-param name="value" select="$listLevelStyle/*/@text:space-before"/>
1850                    </xsl:call-template>
1851                </xsl:when>
1852                <xsl:otherwise>0</xsl:otherwise>
1853            </xsl:choose>
1854        </xsl:variable>
1855        <!-- Only if the left-margin of the first paragraph is positive the sum
1856        text:space-before and fo:left-margin is taken as list indent -->
1857        <xsl:choose>
1858            <xsl:when test="$firstParaLeftMargin &gt; 0">
1859                <xsl:value-of select="$firstParaLeftMargin + $spaceBefore"/>
1860            </xsl:when>
1861            <xsl:otherwise>
1862                <xsl:value-of select="$spaceBefore"/>
1863            </xsl:otherwise>
1864        </xsl:choose>
1865    </xsl:template>
1866
1867    <!-- ****************** -->
1868    <!-- *** list item  *** -->
1869    <!-- ****************** -->
1870<!--
1871    Left margin of the complete list:
1872    The space between left page and the list symbol (left-margin) is in the Office implemented by
1873    the sum of three values:
1874        1) 'text:space-before', which is part of the 'text:list-style' element.
1875        2) 'margin:left' from the style of the first child (e.g. paragraph).
1876        3) 'fo:text-indent' the indent of the first line of some child (e.g. paragraph) (applied by CSS class style)
1877
1878    Possible list children:
1879    <!ELEMENT text:list-item (text:p|text:h|text:list)+>
1880
1881    In the Office the list label before the text depends on two attributes:
1882        - 'text:min-label-width': the distance between list label and all text of the list item.
1883        - 'text:min-label-distance': the distance between list label and text of the first line,
1884            only used, when text does not fit in text:min-label-width (ignored)
1885
1886-->
1887    <xsl:template match="text:list-item | text:list-header" mode="listItemSibling">
1888        <xsl:param name="globalData"/>
1889        <xsl:param name="firstitemLabelWidth"/>
1890        <xsl:param name="isEmptyList" select="not(*[name() = 'text:h' or name() = 'text:p' or name() = 'text:name'])"/>
1891        <xsl:param name="isListNumberingReset"/>
1892        <xsl:param name="isNextLevelNumberingReset"/>
1893        <xsl:param name="itemNumber"/>
1894        <xsl:param name="itemLabel"/>
1895        <xsl:param name="listLevel"/>
1896        <xsl:param name="listLevelStyle"/>
1897        <xsl:param name="listRestart"/>
1898        <xsl:param name="listStyle"/>
1899        <xsl:param name="listStyleName"/>
1900        <xsl:param name="minLabelDist"/>
1901        <xsl:param name="minLabelWidth"/>
1902        <xsl:param name="listIndent" />
1903
1904        <!-- The text:list-header shall not be labeled. According to ODF specification (sect. 4.3.2):
1905        "The <text:list-header> element represents a list header and is a special kind of list item. It
1906        contains one or more paragraphs that are displayed before a list. The paragraphs are formatted
1907        like list items but they do not have a preceding number or bullet." -->
1908        <xsl:variable name="isListHeader" select="boolean(self::text:list-header)"/>
1909
1910        <xsl:variable name="listIndentNew">
1911            <xsl:choose>
1912                <xsl:when test="$listIndent">
1913                    <xsl:value-of select="$listIndent"/>
1914                </xsl:when>
1915                <xsl:otherwise>
1916                    <xsl:call-template name="getListIndent">
1917                        <xsl:with-param name="globalData" select="$globalData"/>
1918                        <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
1919                        <xsl:with-param name="firstPara" select="*[name() = 'text:p' or name() = 'text:h'][1]" />
1920                    </xsl:call-template>
1921                </xsl:otherwise>
1922            </xsl:choose>
1923        </xsl:variable>
1924        <xsl:variable name="itemNumberNew">
1925            <xsl:if test="$listStyle/text:list-style/text:list-level-style-number">
1926                <xsl:choose>
1927                    <xsl:when test="$isListHeader">0</xsl:when>
1928                    <xsl:when test="$isEmptyList">
1929                        <!--  An empty list item (no text:h/text:p as child), will not count as item and does not increment the count.  -->
1930                        <xsl:variable name="tempItemNumber">
1931                            <xsl:choose>
1932                                <!-- siblings will be incremented by one -->
1933                                <xsl:when test="$itemNumber">
1934                                    <xsl:if test="not($isListHeader)">
1935                                        <xsl:value-of select="$itemNumber + 1"/>
1936                                    </xsl:if>
1937                                </xsl:when>
1938                                <!-- if a higher list level had content the numbering starts with 1 -->
1939                                <xsl:when test="$isListNumberingReset and $listLevel &gt; 1">
1940                                    <xsl:value-of select="1"/>
1941                                </xsl:when>
1942                                <xsl:otherwise>
1943                                    <xsl:call-template name="getItemNumber">
1944                                        <xsl:with-param name="listStyleName" select="$listStyleName"/>
1945                                        <xsl:with-param name="listLevel" select="$listLevel"/>
1946                                        <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
1947                                        <xsl:with-param name="listStyle" select="$listStyle"/>
1948                                    </xsl:call-template>
1949                                </xsl:otherwise>
1950                            </xsl:choose>
1951                        </xsl:variable>
1952                        <xsl:choose>
1953                            <!-- in case the empty list-item is the first list-item in document -->
1954                            <xsl:when test="$tempItemNumber = 1">
1955                                <xsl:value-of select="1"/>
1956                            </xsl:when>
1957                            <xsl:otherwise>
1958                                <xsl:value-of select="$tempItemNumber - 1"/>
1959                            </xsl:otherwise>
1960                        </xsl:choose>
1961                    </xsl:when>
1962                    <xsl:otherwise>
1963                        <xsl:choose>
1964                            <xsl:when test="@text:start-value">
1965                                <xsl:value-of select="@text:start-value"/>
1966                            </xsl:when>
1967                            <!-- text:start-value from list level style will only be taken on the first list-item of a list -->
1968                            <xsl:when test="$listLevelStyle/@text:start-value and count(preceding-sibling::text:list-item) = 0">
1969                                <xsl:value-of select="$listLevelStyle/@text:start-value"/>
1970                            </xsl:when>
1971                            <!-- siblings will be incremented by one -->
1972                            <xsl:when test="$itemNumber">
1973                                <xsl:value-of select="$itemNumber + 1"/>
1974                            </xsl:when>
1975                            <!-- if a higher list level had content the numbering starts with 1 -->
1976                            <xsl:when test="$isListNumberingReset and $listLevel &gt; 1">
1977                                <xsl:value-of select="1"/>
1978                            </xsl:when>
1979                            <xsl:otherwise>
1980                                <xsl:call-template name="getItemNumber">
1981                                    <xsl:with-param name="listStyleName" select="$listStyleName"/>
1982                                    <xsl:with-param name="listLevel" select="$listLevel"/>
1983                                    <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
1984                                    <xsl:with-param name="listStyle" select="$listStyle"/>
1985                                </xsl:call-template>
1986                            </xsl:otherwise>
1987                        </xsl:choose>
1988                    </xsl:otherwise>
1989                </xsl:choose>
1990            </xsl:if>
1991        </xsl:variable>
1992        <xsl:variable name="itemLabelNew">
1993            <xsl:if test="$listStyle/text:list-style/text:list-level-style-number">
1994                <!--
1995                    A numbered label (e.g. 2.C.III) is created for every text:list-item/header.
1996                    Above list levels are listed in the label, if the list-style requires this. Levels are separated by @style:num-suffix
1997                    Formatation is dependent for every list level depth.
1998                    The label is passed from ancestor text:list-item/header and if required truncated.
1999                    The prefix/suffix (as well list level dependent) comes before and after the complete label (after truncation)
2000                -->
2001                <!-- Numbered label will be generated  -->
2002                <xsl:call-template name="createItemLabel">
2003                    <xsl:with-param name="itemNumber" select="$itemNumberNew"/>
2004                    <xsl:with-param name="itemLabel" select="$itemLabel"/>
2005                    <xsl:with-param name="listLevelsToDisplay">
2006                        <xsl:variable name="display" select="$listLevelStyle/@text:display-levels"/>
2007                        <xsl:choose>
2008                            <xsl:when test="$display">
2009                                <xsl:value-of select="$display"/>
2010                            </xsl:when>
2011                            <xsl:when test="$isListHeader">0</xsl:when>
2012                            <xsl:otherwise>1</xsl:otherwise>
2013                        </xsl:choose>
2014                    </xsl:with-param>
2015                    <xsl:with-param name="listLevel" select="$listLevel"/>
2016                    <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2017                    <xsl:with-param name="listStyleName" select="$listStyleName"/>
2018                </xsl:call-template>
2019            </xsl:if>
2020        </xsl:variable>
2021        <xsl:element name="li">
2022            <xsl:choose>
2023                <xsl:when test="$isEmptyList or $isListHeader">
2024                    <xsl:apply-templates>
2025                        <xsl:with-param name="globalData" select="$globalData"/>
2026                        <xsl:with-param name="itemLabel" select="$itemLabelNew"/>
2027                        <xsl:with-param name="listLevel" select="$listLevel + 1"/>
2028                        <xsl:with-param name="listStyleName" select="$listStyleName"/>
2029                    </xsl:apply-templates>
2030                </xsl:when>
2031                <xsl:otherwise>
2032                    <!-- Possible following children are text:h, text:p, list:text, text:soft-page-break -->
2033                    <xsl:apply-templates mode="list-item-children" select="*[1]">
2034                        <xsl:with-param name="globalData" select="$globalData"/>
2035                        <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2036                        <xsl:with-param name="isNextLevelNumberingReset" select="$isListHeader or $isNextLevelNumberingReset"/>
2037                        <!-- The new created label is given to the children -->
2038                        <xsl:with-param name="itemLabel" select="$itemLabelNew"/>
2039                        <xsl:with-param name="listLabelElement">
2040                            <xsl:choose>
2041                                <xsl:when test="name() = 'text:list-header'"/>
2042                                <xsl:otherwise>
2043                                    <xsl:variable name="listLabelWidth">
2044                                        <xsl:choose>
2045                                            <xsl:when test="$minLabelWidth &gt; 0">
2046                                                <xsl:value-of select="$minLabelWidth"/>
2047                                            </xsl:when>
2048                                            <xsl:otherwise>
2049                                                <xsl:variable name="listLevelLabelAlignment" select="$listLevelStyle/style:list-level-properties/style:list-level-label-alignment"/>
2050                                                <xsl:variable name="listLevelTextIndent">
2051                                                    <xsl:call-template name="convert2cm">
2052                                                        <xsl:with-param name="value" select="string($listLevelLabelAlignment/@fo:text-indent)"/>
2053                                                    </xsl:call-template>
2054                                                </xsl:variable>
2055                                                <!-- TODO: Access new ODF 1.2 list styles
2056                                                <xsl:variable name="listLevelTextIndent">
2057                                                    <xsl:call-template name="convert2cm">
2058                                                        <xsl:with-param name="value" select="string($listLevelLabelAlignment/@text:list-tab-stop-position)"/>
2059                                                    </xsl:call-template>
2060                                                </xsl:variable> -->
2061                                                <xsl:value-of select="-$listLevelTextIndent"/>
2062                                            </xsl:otherwise>
2063                                        </xsl:choose>
2064                                    </xsl:variable>
2065                                    <!-- Numbering is being done by this transformation creating a HTML span representing the number label
2066                                         The html:span represents the list item/header label (e.g. 1.A.III)
2067                                         As the html:span is usually an inline element is formatted by CSS as block element to use width upon it,
2068                                         to disable the carriage return float:left is used and later neglected -->
2069                                    <xsl:element name="span">
2070                                        <xsl:if test="$listLevelStyle/@text:style-name">
2071                                            <xsl:attribute name="class">
2072                                                <xsl:value-of select="$listLevelStyle/@text:style-name"/>
2073                                            </xsl:attribute>
2074                                        </xsl:if>
2075                                        <xsl:attribute name="style">
2076                                            <xsl:text>display:block;float:</xsl:text>
2077                                            <!-- TODO: Svante - copy this functionality for other used margin:left (in western country 'left') -->
2078                                            <xsl:call-template name="getOppositeWritingDirection">
2079                                                <xsl:with-param name="globalData" select="$globalData"/>
2080                                                <xsl:with-param name="paraStyleName" select="descendant-or-self::*/@text:style-name"/>
2081                                            </xsl:call-template>
2082                                            <xsl:text>;min-width:</xsl:text>
2083                                            <xsl:choose>
2084                                                <xsl:when test="$listLabelWidth and not($listLabelWidth='') and not($listLabelWidth='NaN')">
2085                                                    <xsl:value-of select="translate($listLabelWidth,',','.')"/>
2086                                                </xsl:when>
2087                                                <xsl:otherwise>0</xsl:otherwise>
2088                                            </xsl:choose>
2089                                            <xsl:text>cm;</xsl:text>
2090                                            <xsl:if test="$minLabelDist &gt; 0">
2091                                                <xsl:text>padding-right:</xsl:text><xsl:value-of select="$minLabelDist"/><xsl:text>cm;</xsl:text>
2092                                            </xsl:if>
2093                                        </xsl:attribute>
2094                                        <xsl:variable name="labelContent">
2095                                            <xsl:choose>
2096                                                <xsl:when test="text:number">
2097                                                    <xsl:apply-templates select="text:number" mode="listnumber"/>
2098                                                </xsl:when>
2099                                                <xsl:when test="name($listLevelStyle) = 'text:list-level-style-bullet'">
2100                                                    <!-- not viewed in LO similar to tdf146264
2101                                                    <xsl:value-of select="$listLevelStyle/@style:num-prefix"/>-->
2102                                                    <xsl:value-of select="$listLevelStyle/@text:bullet-char"/>
2103                                                    <!-- not viewed in LO see tdf146264
2104                                                    <xsl:value-of select="$listLevelStyle/@style:num-suffix"/>-->
2105                                                </xsl:when>
2106                                                <xsl:when test="name($listLevelStyle) = 'text:list-level-style-number'">
2107                                                    <xsl:value-of select="$listLevelStyle/@style:num-prefix"/>
2108                                                    <xsl:value-of select="$itemLabelNew"/>
2109                                                    <xsl:value-of select="$listLevelStyle/@style:num-suffix"/>
2110                                                </xsl:when>
2111                                                <xsl:otherwise>
2112                                                <!-- Listing with image as bullets, taken from the list style's href -->
2113                                                    <xsl:value-of select="$listLevelStyle/@xlink:href"/>
2114                                                </xsl:otherwise>
2115                                            </xsl:choose>
2116                                        </xsl:variable>
2117                                        <!-- Some browsers have problem with stand-alone elements (e.g. <span/>)
2118                                            Therefore a comment is being inserted into an empty label -->
2119                                        <xsl:choose>
2120                                            <xsl:when test="$labelContent != ''">
2121                                                <xsl:value-of select="$labelContent"/>
2122                                            </xsl:when>
2123                                            <xsl:otherwise>
2124                                                <xsl:comment>&#160;</xsl:comment>
2125                                            </xsl:otherwise>
2126                                        </xsl:choose>
2127                                    </xsl:element>
2128                                </xsl:otherwise>
2129                            </xsl:choose>
2130                        </xsl:with-param>
2131                        <xsl:with-param name="listLabelEmptyElement">
2132                            <xsl:element name="span">
2133                                <xsl:if test="$listLevelStyle/@text:style-name">
2134                                    <xsl:attribute name="class">
2135                                        <xsl:value-of select="$listLevelStyle/@text:style-name"/>
2136                                    </xsl:attribute>
2137                                </xsl:if>
2138                                <xsl:attribute name="style">
2139                                    <xsl:text>display:block;float:</xsl:text>
2140                                    <xsl:call-template name="getOppositeWritingDirection">
2141                                        <xsl:with-param name="globalData" select="$globalData"/>
2142                                        <xsl:with-param name="paraStyleName" select="descendant-or-self::*/@text:style-name"/>
2143                                    </xsl:call-template>
2144                                    <xsl:text>;min-width:</xsl:text>
2145                                    <xsl:choose>
2146                                        <xsl:when test="$minLabelWidth and not($minLabelWidth='') and not($minLabelWidth='NaN')">
2147                                            <xsl:value-of select="translate($minLabelWidth,',','.')"/>
2148                                        </xsl:when>
2149                                        <xsl:otherwise>0</xsl:otherwise>
2150                                    </xsl:choose>
2151                                    <xsl:text>cm</xsl:text>
2152                                    <xsl:if test="$minLabelDist &gt; 0">
2153                                        <xsl:text>padding-right:</xsl:text><xsl:value-of select="$minLabelDist"/><xsl:text>cm;</xsl:text>
2154                                    </xsl:if>
2155                                </xsl:attribute>
2156                                <xsl:comment>&#160;</xsl:comment>
2157                            </xsl:element>
2158                        </xsl:with-param>
2159                        <xsl:with-param name="listLevel" select="$listLevel + 1"/>
2160                        <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2161                        <xsl:with-param name="listRestart" select="$listRestart"/>
2162                        <xsl:with-param name="listStyle" select="$listStyle"/>
2163                        <xsl:with-param name="listStyleName" select="$listStyleName"/>
2164                        <xsl:with-param name="listIndent" select="$listIndentNew"/>
2165                        <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2166                    </xsl:apply-templates>
2167                </xsl:otherwise>
2168            </xsl:choose>
2169        </xsl:element>
2170        <xsl:apply-templates select="following-sibling::*[1]" mode="listItemSibling">
2171            <xsl:with-param name="globalData" select="$globalData"/>
2172            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2173            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2174            <xsl:with-param name="itemNumber" select="$itemNumberNew"/>
2175            <xsl:with-param name="listIndent">
2176                <xsl:choose>
2177                    <xsl:when test="not($isEmptyList)">
2178                        <xsl:value-of select="$listIndentNew"/>
2179                    </xsl:when>
2180                </xsl:choose>
2181            </xsl:with-param>
2182            <!-- Receives the same parent label -->
2183            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2184            <xsl:with-param name="listLevel" select="$listLevel"/>
2185            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2186            <xsl:with-param name="listStyle" select="$listStyle"/>
2187            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2188            <xsl:with-param name="minLabelDist" select="$minLabelDist"/>
2189            <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2190        </xsl:apply-templates>
2191    </xsl:template>
2192
2193    <xsl:template name="getOppositeWritingDirection">
2194        <xsl:param name="globalData"/>
2195        <xsl:param name="paraStyleName"/>
2196
2197        <xsl:variable name="imageParagraphStyle" select="$globalData/all-styles/style[@style:name = $paraStyleName]/final-properties"/>
2198
2199        <xsl:choose>
2200            <xsl:when test="contains($imageParagraphStyle, 'writing-mode:')">
2201                <xsl:choose>
2202                    <xsl:when test="contains(substring-before(substring-after($imageParagraphStyle, 'writing-mode:'), ';'), 'rl')">right</xsl:when>
2203                    <xsl:otherwise>left</xsl:otherwise>
2204                </xsl:choose>
2205            </xsl:when>
2206            <xsl:otherwise>left</xsl:otherwise>
2207        </xsl:choose>
2208    </xsl:template>
2209
2210    <xsl:template match="text:number" mode="listnumber">
2211        <xsl:apply-templates/>
2212    </xsl:template>
2213
2214    <xsl:template match="text:number" mode="list-item-children">
2215        <xsl:param name="globalData"/>
2216        <xsl:param name="listLabelElement"/>
2217        <xsl:param name="listLabelEmptyElement"/>
2218        <xsl:param name="isEmptyList"/>
2219        <xsl:param name="isListNumberingReset"/>
2220        <xsl:param name="isNextLevelNumberingReset"/>
2221        <xsl:param name="itemLabel"/>
2222        <xsl:param name="itemNumber"/>
2223        <xsl:param name="listIndent"/>
2224        <xsl:param name="listLevel"/>
2225        <xsl:param name="listLevelStyle" />
2226        <xsl:param name="listRestart"/>
2227        <xsl:param name="listStyle"/>
2228        <xsl:param name="listStyleName"/>
2229        <xsl:param name="minLabelWidth"/>
2230        <xsl:param name="minLabelDist"/>
2231
2232        <xsl:apply-templates mode="list-item-children" select="following-sibling::*[1]">
2233            <xsl:with-param name="globalData" select="$globalData"/>
2234            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2235            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2236            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2237            <xsl:with-param name="listLabelElement" select="$listLabelElement"/>
2238            <xsl:with-param name="listLabelEmptyElement" select="$listLabelEmptyElement"/>
2239            <xsl:with-param name="listLevel" select="$listLevel"/>
2240            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2241            <xsl:with-param name="listRestart" select="$listRestart"/>
2242            <xsl:with-param name="listStyle" select="$listStyle"/>
2243            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2244            <xsl:with-param name="listIndent" select="$listIndent"/>
2245            <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2246            <xsl:with-param name="minLabelDist" select="$minLabelDist"/>
2247        </xsl:apply-templates>
2248    </xsl:template>
2249
2250    <!-- Each key element holds the set of all text:list-item/text:list-header of a certain level and a certain style -->
2251    <xsl:key name="getListItemsByLevelAndStyle" use="concat(count(ancestor::text:list), ancestor::text:list/@text:style-name)" match="text:list-item | text:list-header"/>
2252    <!-- Each key element holds the set of all text:list-item/text:list-header of a certain style -->
2253    <xsl:key name="getListItemsByStyle" use="ancestor::text:list/@text:style-name" match="text:list-item | text:list-header"/>
2254
2255
2256    <!-- The Numbering start value (or offset from regular counteing) is used at the first item of offset,
2257    but have to be reused on following items with no text:start-value -->
2258    <xsl:template name="getItemNumber">
2259        <xsl:param name="listLevel"/>
2260        <xsl:param name="listLevelStyle"/>
2261        <xsl:param name="listStyleName"/>
2262        <xsl:param name="listStyle"/>
2263
2264        <xsl:call-template name="countListItemTillStartValue">
2265            <xsl:with-param name="listLevel" select="$listLevel"/>
2266            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2267            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2268            <xsl:with-param name="listStyle" select="$listStyle"/>
2269            <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="preceding::text:list-item[generate-id(key('getListItemsByLevelAndStyle', concat($listLevel, $listStyleName))) = generate-id(key('getListItemsByLevelAndStyle', concat(count(ancestor::text:list), ancestor::text:list/@text:style-name)))]"/>
2270
2271            <xsl:with-param name="precedingListItemsOfSameStyle" select="preceding::text:list-item[generate-id(key('getListItemsByStyle', $listStyleName)) = generate-id(key('getListItemsByStyle', ancestor::text:list/@text:style-name))]"/>
2272        </xsl:call-template>
2273    </xsl:template>
2274
2275    <!-- When there is a text:start-value the last have to be found and added to the number -->
2276    <xsl:template name="countListItemTillStartValue">
2277        <xsl:param name="IteratorSameLevelAndStyle" select="1"/>
2278        <xsl:param name="IteratorSameStyle" select="1"/>
2279        <xsl:param name="itemNumber" select="1"/>
2280        <xsl:param name="listLevel"/>
2281        <xsl:param name="listLevelStyle"/>
2282        <xsl:param name="listStyle"/>
2283        <xsl:param name="listStyleName"/>
2284        <xsl:param name="precedingListItemsOfSameLevelAndStyle" />
2285        <xsl:param name="precedingListItemsOfSameLevelAndStyleCount" select="count($precedingListItemsOfSameLevelAndStyle)"/>
2286        <xsl:param name="precedingListItemsOfSameStyle" />
2287        <xsl:param name="precedingListItemsOfSameStyleCount" select="count($precedingListItemsOfSameStyle)"/>
2288        <!-- E.g.: If a list level 2 number is searched, a level 3 with content found with only a level 1 parent with content,
2289            the level 3 gets a 'pseudoLevel' -->
2290        <xsl:param name="pseudoLevel" select="0" />
2291
2292        <xsl:variable name="isListHeader" select="boolean(self::text:list-header)"/>
2293        <xsl:variable name="isEmptyList" select="not(*[name() = 'text:h' or name() = 'text:p'])"/>
2294
2295        <!-- set the next of preceding list items. Starting from the current to the next previous text:list-item -->
2296        <xsl:variable name="precedingListItemOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle[$precedingListItemsOfSameLevelAndStyleCount - $IteratorSameLevelAndStyle + 1]"/>
2297        <xsl:variable name="precedingListItemOfSameStyle" select="$precedingListItemsOfSameStyle[$precedingListItemsOfSameStyleCount - $IteratorSameStyle + 1]"/>
2298        <xsl:choose>
2299            <xsl:when test="($precedingListItemOfSameStyle and $precedingListItemOfSameLevelAndStyle) or ($precedingListItemOfSameStyle and $listStyle/text:list-style/@text:consecutive-numbering)">
2300                <xsl:for-each select="$precedingListItemOfSameStyle">
2301                    <xsl:choose>
2302                        <!-- if it is a higher list level element  -->
2303                        <xsl:when test="$listStyle/text:list-style/@text:consecutive-numbering">
2304
2305                            <xsl:call-template name="countListItem">
2306                                <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle" />
2307                                <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle"/>
2308                                <xsl:with-param name="itemNumber" select="$itemNumber"/>
2309                                <xsl:with-param name="listLevel" select="$listLevel"/>
2310                                <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2311                                <xsl:with-param name="listStyle" select="$listStyle"/>
2312                                <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2313                                <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2314                                <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2315                                <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2316                                <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2317                            </xsl:call-template>
2318                        </xsl:when>
2319                        <xsl:otherwise>
2320                            <!-- NOT CONSECUTIVE NUMBERING -->
2321                            <xsl:variable name="currentListLevel" select="count(ancestor::text:list)"/>
2322                            <xsl:choose>
2323                                <!-- IF IT IS A HIGHER LIST LEVEL ELEMENT -->
2324                                <xsl:when test="$currentListLevel &lt; $listLevel">
2325                                    <xsl:choose>
2326                                        <!-- if it has content the counting is ended -->
2327                                        <xsl:when test="*[name() = 'text:h' or name() = 'text:p'] or $isListHeader">
2328                                            <!-- TODO: Perhaps the children still have to be processed -->
2329                                            <xsl:value-of select="$itemNumber + $pseudoLevel"/>
2330                                        </xsl:when>
2331                                        <xsl:otherwise>
2332                                        <!-- if it is empty the counting continues -->
2333                                            <xsl:call-template name="countListItemTillStartValue">
2334                                                <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle" />
2335                                                <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2336                                                <xsl:with-param name="itemNumber" select="$itemNumber"/>
2337                                                <xsl:with-param name="listLevel" select="$listLevel"/>
2338                                                <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2339                                                <xsl:with-param name="listStyle" select="$listStyle"/>
2340                                                <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2341                                                <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2342                                                <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2343                                                <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2344                                                <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2345                                            </xsl:call-template>
2346                                        </xsl:otherwise>
2347                                    </xsl:choose>
2348                                </xsl:when>
2349                                <!-- IF IT IS A LIST LEVEL ELEMENT OF THE COUNTING LEVEL -->
2350                                <xsl:when test="$currentListLevel = $listLevel">
2351                                    <xsl:call-template name="countListItem">
2352                                        <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle" />
2353                                        <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle"/>
2354                                        <xsl:with-param name="itemNumber" select="$itemNumber"/>
2355                                        <xsl:with-param name="listLevel" select="$listLevel"/>
2356                                        <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2357                                        <xsl:with-param name="listStyle" select="$listStyle"/>
2358                                        <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2359                                        <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2360                                        <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2361                                        <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2362                                        <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2363                                    </xsl:call-template>
2364                                </xsl:when>
2365                                <xsl:otherwise>
2366                                    <!-- list item below the current level does not count -->
2367                                    <xsl:call-template name="countListItemTillStartValue">
2368                                        <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle" />
2369                                        <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2370                                        <xsl:with-param name="itemNumber" select="$itemNumber"/>
2371                                        <xsl:with-param name="listLevel" select="$listLevel"/>
2372                                        <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2373                                        <xsl:with-param name="listStyle" select="$listStyle"/>
2374                                        <xsl:with-param name="listStyleName" select="$listStyleName"/>
2375                                        <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2376                                        <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2377                                        <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2378                                        <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2379                                        <xsl:with-param name="pseudoLevel">
2380                                            <xsl:choose>
2381                                                <!-- empty list item does not count -->
2382                                                <xsl:when test="not(*[name() = 'text:h' or name() = 'text:p']) or $isListHeader">
2383                                                    <xsl:value-of select="$pseudoLevel"/>
2384                                                </xsl:when>
2385                                                <xsl:otherwise>1</xsl:otherwise>
2386                                            </xsl:choose>
2387                                        </xsl:with-param>
2388                                    </xsl:call-template>
2389                                </xsl:otherwise>
2390                            </xsl:choose>
2391                        </xsl:otherwise>
2392                    </xsl:choose>
2393                </xsl:for-each>
2394            </xsl:when>
2395            <xsl:otherwise>
2396                <xsl:value-of select="$itemNumber"/>
2397            </xsl:otherwise>
2398        </xsl:choose>
2399    </xsl:template>
2400
2401    <xsl:template name="countListItem">
2402        <xsl:param name="IteratorSameLevelAndStyle"/>
2403        <xsl:param name="IteratorSameStyle"/>
2404        <xsl:param name="itemNumber"/>
2405        <xsl:param name="listLevel"/>
2406        <xsl:param name="listLevelStyle"/>
2407        <xsl:param name="listStyle"/>
2408        <xsl:param name="listStyleName"/>
2409        <xsl:param name="precedingListItemsOfSameLevelAndStyle"/>
2410        <xsl:param name="precedingListItemsOfSameLevelAndStyleCount"/>
2411        <xsl:param name="precedingListItemsOfSameStyle"/>
2412        <xsl:param name="precedingListItemsOfSameStyleCount"/>
2413        <xsl:param name="pseudoLevel" />
2414
2415        <xsl:variable name="isListHeader" select="boolean(self::text:list-header)"/>
2416        <xsl:variable name="isEmptyList" select="not(*[name() = 'text:h' or name() = 'text:p'])"/>
2417
2418        <xsl:choose>
2419            <xsl:when test="@text:start-value">
2420                <xsl:choose>
2421                    <xsl:when test="$isEmptyList or $isListHeader">
2422                        <!-- empty list item does not count. neither does list header -->
2423                        <xsl:call-template name="countListItemTillStartValue">
2424                            <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle + 1" />
2425                            <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2426                            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2427                            <xsl:with-param name="listLevel" select="$listLevel"/>
2428                            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2429                            <xsl:with-param name="listStyle" select="$listStyle"/>
2430                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2431                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2432                            <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2433                            <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2434                            <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2435                        </xsl:call-template>
2436                    </xsl:when>
2437                    <xsl:otherwise>
2438                        <xsl:value-of select="$itemNumber + @text:start-value"/>
2439                    </xsl:otherwise>
2440                </xsl:choose>
2441            </xsl:when>
2442            <xsl:when test="$listLevelStyle/@text:start-value">
2443                <xsl:choose>
2444                    <xsl:when test="$isEmptyList or $isListHeader">
2445                        <!-- empty list item does not count. neither does list header -->
2446                        <xsl:call-template name="countListItemTillStartValue">
2447                            <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle + 1" />
2448                            <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2449                            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2450                            <xsl:with-param name="listLevel" select="$listLevel"/>
2451                            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2452                            <xsl:with-param name="listStyle" select="$listStyle"/>
2453                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2454                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2455                            <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2456                            <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2457                            <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2458                        </xsl:call-template>
2459                    </xsl:when>
2460                    <xsl:otherwise>
2461                        <xsl:value-of select="$itemNumber + $listLevelStyle/@text:start-value"/>
2462                    </xsl:otherwise>
2463                </xsl:choose>
2464            </xsl:when>
2465            <xsl:otherwise>
2466                <xsl:choose>
2467                    <xsl:when test="$isEmptyList or $isListHeader">
2468                        <!-- empty list item does not count. neither does list header -->
2469                        <xsl:call-template name="countListItemTillStartValue">
2470                            <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle + 1" />
2471                            <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2472                            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2473                            <xsl:with-param name="listLevel" select="$listLevel"/>
2474                            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2475                            <xsl:with-param name="listStyle" select="$listStyle"/>
2476                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2477                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2478                            <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2479                            <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2480                            <xsl:with-param name="pseudoLevel" select="$pseudoLevel" />
2481                        </xsl:call-template>
2482                    </xsl:when>
2483                    <xsl:otherwise>
2484                        <!-- count on till you find a start-value or the end is reached -->
2485                        <xsl:call-template name="countListItemTillStartValue">
2486                            <xsl:with-param name="IteratorSameLevelAndStyle" select="$IteratorSameLevelAndStyle + 1" />
2487                            <xsl:with-param name="IteratorSameStyle" select="$IteratorSameStyle + 1"/>
2488                            <xsl:with-param name="itemNumber" select="$itemNumber + 1"/>
2489                            <xsl:with-param name="listLevel" select="$listLevel"/>
2490                            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2491                            <xsl:with-param name="listStyle" select="$listStyle"/>
2492                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyle" select="$precedingListItemsOfSameLevelAndStyle"/>
2493                            <xsl:with-param name="precedingListItemsOfSameLevelAndStyleCount" select="$precedingListItemsOfSameLevelAndStyleCount"/>
2494                            <xsl:with-param name="precedingListItemsOfSameStyle" select="$precedingListItemsOfSameStyle"/>
2495                            <xsl:with-param name="precedingListItemsOfSameStyleCount" select="$precedingListItemsOfSameStyleCount"/>
2496                            <xsl:with-param name="pseudoLevel" select="0" />
2497                        </xsl:call-template>
2498                    </xsl:otherwise>
2499                </xsl:choose>
2500            </xsl:otherwise>
2501        </xsl:choose>
2502    </xsl:template>
2503
2504
2505    <!-- Creates the list label containing the number, which is separated by '.' between the levels.
2506        Depending on the levels to display (listLevelsToDisplay) -->
2507    <xsl:template name="createItemLabel">
2508        <xsl:param name="itemLabel" select="''"/>
2509        <xsl:param name="itemNumber" />
2510        <xsl:param name="listLevel" />
2511        <xsl:param name="listLevelStyle" />
2512        <xsl:param name="listLevelsToDisplay" />
2513
2514        <xsl:choose>
2515            <xsl:when test="$listLevelsToDisplay &lt; $listLevel">
2516                <xsl:call-template name="truncLabel">
2517                    <xsl:with-param name="itemLabel" select="$itemLabel"/>
2518                    <xsl:with-param name="itemNumber" select="$itemNumber" />
2519                    <xsl:with-param name="listLevel" select="$listLevel"/>
2520                    <xsl:with-param name="listLevelStyle" select="$listLevelStyle" />
2521                    <xsl:with-param name="listLevelsToDisplay" select="$listLevelsToDisplay"/>
2522                </xsl:call-template>
2523            </xsl:when>
2524            <xsl:otherwise>
2525                <xsl:variable name="numberedSymbol">
2526                    <!-- only give out a number when number format is not empty -->
2527                    <xsl:if test="$listLevelStyle/@style:num-format != ''">
2528                        <xsl:number value="$itemNumber" format="{$listLevelStyle/@style:num-format}"/>
2529                    </xsl:if>
2530                </xsl:variable>
2531                <xsl:choose>
2532                    <xsl:when test="$listLevelsToDisplay != 1">
2533                        <xsl:value-of select="concat($itemLabel, $listLevelStyle/@style:num-prefix , $numberedSymbol, $listLevelStyle/@style:num-suffix)"/>
2534                    </xsl:when>
2535                    <xsl:otherwise>
2536                        <xsl:value-of select="concat($listLevelStyle/@style:num-prefix , $numberedSymbol, $listLevelStyle/@style:num-suffix)"/>
2537                    </xsl:otherwise>
2538                </xsl:choose>
2539            </xsl:otherwise>
2540        </xsl:choose>
2541    </xsl:template>
2542
2543    <xsl:template name="truncLabel">
2544        <xsl:param name="itemLabel" />
2545        <xsl:param name="itemNumber" />
2546        <xsl:param name="listLevel" />
2547        <xsl:param name="listLevelStyle" />
2548        <xsl:param name="listLevelsToDisplay" />
2549        <xsl:param name="listStyle" />
2550        <xsl:param name="listStyleName" />
2551
2552        <xsl:call-template name="createItemLabel">
2553            <xsl:with-param name="itemLabel">
2554                <xsl:if test="contains($itemLabel, '.')">
2555                    <xsl:value-of select="substring-after($itemLabel, '.')"/>
2556                </xsl:if>
2557            </xsl:with-param>
2558            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2559            <xsl:with-param name="listLevel" select="$listLevel - 1"/>
2560            <xsl:with-param name="listLevelStyle" select="$listLevelStyle"/>
2561            <xsl:with-param name="listLevelsToDisplay" select="$listLevelsToDisplay"/>
2562        </xsl:call-template>
2563    </xsl:template>
2564
2565
2566    <xsl:template match="text:p" mode="list-item-children">
2567        <xsl:param name="globalData"/>
2568        <xsl:param name="listLabelElement"/>
2569        <xsl:param name="listLabelEmptyElement"/>
2570        <xsl:param name="isEmptyList"/>
2571        <xsl:param name="isListNumberingReset"/>
2572        <xsl:param name="isNextLevelNumberingReset"/>
2573        <xsl:param name="itemLabel"/>
2574        <xsl:param name="itemNumber"/>
2575        <xsl:param name="listIndent"/>
2576        <xsl:param name="listLevel"/>
2577        <xsl:param name="listRestart"/>
2578        <xsl:param name="listStyle"/>
2579        <xsl:param name="listStyleName"/>
2580        <xsl:param name="minLabelDist"/>
2581        <xsl:param name="minLabelWidth"/>
2582
2583        <!-- TODO page alignment fix - PART1 -->
2584
2585        <!-- xhtml:p may only contain inline elements.
2586             If there is one frame beyond, div must be used! -->
2587        <xsl:variable name="elementName">
2588            <xsl:choose>
2589                <xsl:when test="descendant::draw:frame[1] or descendant::text:p[1]">div</xsl:when>
2590                <xsl:otherwise>p</xsl:otherwise>
2591            </xsl:choose>
2592        </xsl:variable>
2593        <xsl:element name="{$elementName}">
2594            <xsl:call-template name="create-list-style">
2595                <xsl:with-param name="globalData" select="$globalData"/>
2596                <xsl:with-param name="listIndent" select="$listIndent"/>
2597                <xsl:with-param name="styleName" select="@text:style-name"/>
2598            </xsl:call-template>
2599            <xsl:choose>
2600                <xsl:when test="$listLabelElement">
2601                    <xsl:copy-of select="$listLabelElement"/>
2602                </xsl:when>
2603                <xsl:otherwise>
2604                    <xsl:copy-of select="$listLabelEmptyElement"/>
2605                </xsl:otherwise>
2606            </xsl:choose>
2607            <xsl:apply-templates>
2608                <xsl:with-param name="globalData" select="$globalData"/>
2609                <xsl:with-param name="listIndent" select="$minLabelWidth"/>
2610            </xsl:apply-templates>
2611            <!-- this span disables the float necessary to bring two block elements on one line. It contains a space as IE6 bug workaround -->
2612            <span class="odfLiEnd"></span>
2613            <xsl:text>&#160;</xsl:text>
2614        </xsl:element>
2615
2616        <xsl:apply-templates mode="list-item-children" select="following-sibling::*[1]">
2617            <xsl:with-param name="globalData" select="$globalData"/>
2618            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2619            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2620            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2621            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2622            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2623            <xsl:with-param name="listLabelEmptyElement" select="$listLabelEmptyElement"/>
2624            <xsl:with-param name="listLevel" select="$listLevel"/>
2625            <xsl:with-param name="listRestart" select="$listRestart"/>
2626            <xsl:with-param name="listStyle" select="$listStyle"/>
2627            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2628            <xsl:with-param name="listIndent" select="$listIndent"/>
2629            <xsl:with-param name="minLabelDist" select="$minLabelDist"/>
2630            <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2631        </xsl:apply-templates>
2632    </xsl:template>
2633
2634
2635    <!-- Neglecting the left margin behavior for headings for now -->
2636    <xsl:template match="text:h" mode="list-item-children">
2637        <xsl:param name="globalData"/>
2638        <xsl:param name="listLabelElement"/>
2639        <xsl:param name="listLabelEmptyElement"/>
2640        <xsl:param name="isEmptyList"/>
2641        <xsl:param name="isListNumberingReset"/>
2642        <xsl:param name="isNextLevelNumberingReset"/>
2643        <xsl:param name="itemLabel"/>
2644        <xsl:param name="itemNumber"/>
2645        <xsl:param name="listIndent"/>
2646        <xsl:param name="listLevel"/>
2647        <xsl:param name="listRestart"/>
2648        <xsl:param name="listStyle"/>
2649        <xsl:param name="listStyleName"/>
2650        <xsl:param name="minLabelWidth"/>
2651
2652        <xsl:variable name="headingName" select="concat('h', $listLevel - 1)"/>
2653        <xsl:element name="{$headingName}">
2654            <xsl:call-template name="create-list-style">
2655                <xsl:with-param name="globalData" select="$globalData"/>
2656                <xsl:with-param name="listIndent" select="$listIndent"/>
2657                <xsl:with-param name="styleName" select="@text:style-name"/>
2658            </xsl:call-template>
2659            <xsl:variable name="title">
2660                <xsl:apply-templates mode="concatenate"/>
2661            </xsl:variable>
2662            <xsl:choose>
2663                <xsl:when test="$listLabelElement">
2664                    <xsl:copy-of select="$listLabelElement"/>
2665                </xsl:when>
2666                <xsl:otherwise>
2667                    <xsl:copy-of select="$listLabelEmptyElement"/>
2668                </xsl:otherwise>
2669            </xsl:choose>
2670
2671            <!-- REFERENCE HANDLING - ANCHOR -->
2672            <xsl:element namespace="{$namespace}" name="a">
2673                <xsl:attribute name="id">
2674                    <xsl:value-of select="translate(concat('a_',$listLabelElement, '_', normalize-space($title)), '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
2675                </xsl:attribute>
2676                <xsl:apply-templates>
2677                    <xsl:with-param name="globalData" select="$globalData"/>
2678                    <xsl:with-param name="listIndent" select="$minLabelWidth"/>
2679                </xsl:apply-templates>
2680            </xsl:element>
2681
2682            <!-- this span disables the float necessary to bring two block elements on one line. It contains a space as IE6 bug workaround -->
2683            <span class="odfLiEnd"></span>
2684            <xsl:text>&#160;</xsl:text>
2685        </xsl:element>
2686
2687        <xsl:apply-templates mode="list-item-children" select="following-sibling::*[1]">
2688            <xsl:with-param name="globalData" select="$globalData"/>
2689            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2690            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2691            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2692            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2693            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2694            <xsl:with-param name="listLabelEmptyElement" select="$listLabelEmptyElement"/>
2695            <xsl:with-param name="listLevel" select="$listLevel"/>
2696            <xsl:with-param name="listRestart" select="$listRestart"/>
2697            <xsl:with-param name="listStyle" select="$listStyle"/>
2698            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2699            <xsl:with-param name="listIndent" select="$listIndent"/>
2700            <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2701        </xsl:apply-templates>
2702    </xsl:template>
2703
2704
2705    <xsl:template match="*" mode="list-item-children">
2706        <xsl:param name="globalData"/>
2707        <xsl:param name="isEmptyList"/>
2708        <xsl:param name="listLabelEmptyElement"/>
2709        <xsl:param name="isListNumberingReset"/>
2710        <xsl:param name="isNextLevelNumberingReset"/>
2711        <xsl:param name="itemLabel"/>
2712        <xsl:param name="itemNumber"/>
2713        <xsl:param name="listIndent"/>
2714        <xsl:param name="listLevel"/>
2715        <xsl:param name="listRestart"/>
2716        <xsl:param name="listStyle"/>
2717        <xsl:param name="listStyleName"/>
2718        <xsl:param name="minLabelWidth"/>
2719
2720        <xsl:apply-templates select="self::*">
2721            <xsl:with-param name="globalData" select="$globalData"/>
2722            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2723            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2724            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2725            <xsl:with-param name="listLabelEmptyElement" select="$listLabelEmptyElement"/>
2726            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2727            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2728            <xsl:with-param name="listIndent" select="$listIndent"/>
2729            <xsl:with-param name="listLevel" select="$listLevel"/>
2730            <xsl:with-param name="listRestart" select="$listRestart"/>
2731            <xsl:with-param name="listStyle" select="$listStyle"/>
2732            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2733        </xsl:apply-templates>
2734
2735        <xsl:apply-templates mode="list-item-children" select="following-sibling::*[1]">
2736            <xsl:with-param name="globalData" select="$globalData"/>
2737            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2738            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2739            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2740            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2741            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2742            <xsl:with-param name="listLabelEmptyElement" select="$listLabelEmptyElement"/>
2743            <xsl:with-param name="listLevel" select="$listLevel"/>
2744            <xsl:with-param name="listRestart" select="$listRestart"/>
2745            <xsl:with-param name="listStyle" select="$listStyle"/>
2746            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2747            <xsl:with-param name="listIndent" select="$listIndent"/>
2748            <xsl:with-param name="minLabelWidth" select="$minLabelWidth"/>
2749        </xsl:apply-templates>
2750    </xsl:template>
2751
2752    <xsl:template match="*" mode="listItemSibling">
2753        <xsl:param name="globalData"/>
2754        <xsl:param name="isEmptyList"/>
2755        <xsl:param name="isListNumberingReset"/>
2756        <xsl:param name="isNextLevelNumberingReset"/>
2757        <xsl:param name="itemLabel"/>
2758        <xsl:param name="itemNumber"/>
2759        <xsl:param name="listIndent"/>
2760        <xsl:param name="listLevel"/>
2761        <xsl:param name="listRestart"/>
2762        <xsl:param name="listStyle"/>
2763        <xsl:param name="listLevelStyle"/>
2764        <xsl:param name="listStyleName"/>
2765
2766        <xsl:apply-templates select="self::*">
2767            <xsl:with-param name="globalData" select="$globalData"/>
2768            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2769            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2770            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2771            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2772            <xsl:with-param name="listIndent" select="$listIndent"/>
2773            <!-- receives the same parent label, only with a different itemNumber -->
2774            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2775            <xsl:with-param name="listLevel" select="$listLevel"/>
2776            <xsl:with-param name="listStyle" select="$listStyle"/>
2777            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2778        </xsl:apply-templates>
2779        <xsl:apply-templates select="following-sibling::*[1]" mode="listItemSibling">
2780            <xsl:with-param name="globalData" select="$globalData"/>
2781            <xsl:with-param name="isEmptyList" select="$isEmptyList"/>
2782            <xsl:with-param name="isListNumberingReset" select="$isListNumberingReset"/>
2783            <xsl:with-param name="isNextLevelNumberingReset" select="$isNextLevelNumberingReset"/>
2784            <xsl:with-param name="itemNumber" select="$itemNumber"/>
2785            <xsl:with-param name="listIndent" select="$listIndent"/>
2786            <!-- receives the same parent label, only with a different itemNumber -->
2787            <xsl:with-param name="itemLabel" select="$itemLabel"/>
2788            <xsl:with-param name="listLevel" select="$listLevel"/>
2789            <xsl:with-param name="listStyle" select="$listStyle"/>
2790            <xsl:with-param name="listStyleName" select="$listStyleName"/>
2791        </xsl:apply-templates>
2792    </xsl:template>
2793
2794    <xsl:template match="text()" mode="list-item-children">
2795        <xsl:value-of select="."/>
2796    </xsl:template>
2797
2798
2799    <xsl:template name="create-list-style">
2800        <xsl:param name="globalData"/>
2801        <xsl:param name="listIndent" select="0"/>
2802        <xsl:param name="styleName"/>
2803
2804        <xsl:if test="$styleName">
2805            <xsl:attribute name="class">
2806                <xsl:value-of select="translate($styleName, '.,;: %()[]/\+', '_____________')"/>
2807            </xsl:attribute>
2808        </xsl:if>
2809        <xsl:attribute name="style">
2810            <xsl:text>margin-</xsl:text>
2811            <xsl:call-template name="getOppositeWritingDirection">
2812                <xsl:with-param name="globalData" select="$globalData"/>
2813                <xsl:with-param name="paraStyleName" select="descendant-or-self::*/@text:style-name"/>
2814            </xsl:call-template>
2815            <xsl:text>:</xsl:text>
2816            <xsl:value-of select="$listIndent"/>
2817            <xsl:text>cm;</xsl:text>
2818        </xsl:attribute>
2819    </xsl:template>
2820
2821
2822    <!-- ********************************************** -->
2823    <!-- *** Text Section (contains: draw:text-box) *** -->
2824    <!-- ********************************************** -->
2825
2826    <xsl:template match="text:section">
2827        <xsl:param name="globalData"/>
2828
2829        <xsl:if test="not(contains(@text:display, 'none'))">
2830            <xsl:text>&#xa;</xsl:text>
2831            <xsl:comment>Next 'div' was a 'text:section'.</xsl:comment>
2832            <xsl:text>&#xa;</xsl:text>
2833            <xsl:element name="div">
2834                <xsl:call-template name="apply-styles-and-content">
2835                    <xsl:with-param name="globalData" select="$globalData"/>
2836                </xsl:call-template>
2837            </xsl:element>
2838            <xsl:text>&#xa;</xsl:text>
2839        </xsl:if>
2840    </xsl:template>
2841
2842
2843    <!-- Hidden text dependent on Office variables:
2844         The text is not shown, if condition is 'true'.
2845         Implemented solely for conditions as '<VARIABLE>==0' or '<VARIABLE>==1'
2846    -->
2847    <xsl:key match="text:variable-set" name="varSet" use="@text:name"/>
2848    <xsl:template match="text:hidden-text">
2849        <xsl:param name="globalData"/>
2850
2851        <xsl:variable name="varName" select="substring-before(@text:condition, '==')"/>
2852        <xsl:variable name="varValue" select="substring-after(@text:condition, '==')"/>
2853        <xsl:choose>
2854            <xsl:when test="key('varSet', $varName)/@text:value != $varValue">
2855                <xsl:value-of select="@text:string-value"/>
2856            </xsl:when>
2857            <xsl:otherwise>
2858                <xsl:comment>
2859                    <xsl:value-of select="$varName"/>
2860                    <xsl:value-of select="@text:string-value"/>
2861                    <xsl:value-of select="$varName"/>
2862                </xsl:comment>
2863            </xsl:otherwise>
2864        </xsl:choose>
2865    </xsl:template>
2866
2867    <xsl:template match="@text:style-name | @draw:style-name | @draw:text-style-name | @table:style-name | @presentation:style-name">
2868        <xsl:param name="globalData"/>
2869
2870        <!-- the problem there can be more than one style-name attribute! We need to write class once with all style-name attribute values -->
2871        <xsl:variable name="classAttributeValue">
2872            <xsl:if test="parent::*/@text:style-name != ''">
2873                <xsl:call-template name="create-unique-style-id">
2874                    <xsl:with-param name="styleName" select="parent::*/@text:style-name"/>
2875                    <xsl:with-param name="styleFamily">
2876                        <xsl:call-template name="get-style-family-name">
2877                            <xsl:with-param name="parentName" select="name(..)"/>
2878                        </xsl:call-template>
2879                    </xsl:with-param>
2880                </xsl:call-template><xsl:text> </xsl:text>
2881            </xsl:if>
2882            <xsl:if test="parent::*/@draw:style-name != ''">
2883                <xsl:call-template name="create-unique-style-id">
2884                    <xsl:with-param name="styleName" select="parent::*/@draw:style-name"/>
2885                    <xsl:with-param name="styleFamily">
2886                        <xsl:call-template name="get-style-family-name">
2887                            <xsl:with-param name="parentName" select="name(..)"/>
2888                        </xsl:call-template>
2889                    </xsl:with-param>
2890                </xsl:call-template><xsl:text> </xsl:text>
2891            </xsl:if>
2892            <xsl:if test="parent::*/@draw:text-style-name != ''">
2893                <xsl:call-template name="create-unique-style-id">
2894                    <xsl:with-param name="styleName" select="parent::*/@draw:text-style-name"/>
2895                    <xsl:with-param name="styleFamily">
2896                        <xsl:call-template name="get-style-family-name">
2897                            <xsl:with-param name="parentName" select="name(..)"/>
2898                        </xsl:call-template>
2899                    </xsl:with-param>
2900                </xsl:call-template><xsl:text> </xsl:text>
2901            </xsl:if>
2902            <xsl:if test="parent::*/@table:style-name != ''">
2903                <xsl:call-template name="create-unique-style-id">
2904                    <xsl:with-param name="styleName" select="parent::*/@table:style-name"/>
2905                    <xsl:with-param name="styleFamily">
2906                        <xsl:call-template name="get-style-family-name">
2907                            <xsl:with-param name="parentName" select="name(..)"/>
2908                        </xsl:call-template>
2909                    </xsl:with-param>
2910                </xsl:call-template><xsl:text> </xsl:text>
2911            </xsl:if>
2912            <xsl:if test="parent::*/@presentation:style-name != ''">
2913                <xsl:call-template name="create-unique-style-id">
2914                    <xsl:with-param name="styleName" select="parent::*/@presentation:style-name"/>
2915                    <xsl:with-param name="styleFamily">
2916                        <xsl:call-template name="get-style-family-name">
2917                            <xsl:with-param name="parentName" select="name(..)"/>
2918                        </xsl:call-template>
2919                    </xsl:with-param>
2920                </xsl:call-template><xsl:text> </xsl:text>
2921            </xsl:if>
2922        </xsl:variable>
2923
2924        <xsl:attribute name="class"><xsl:value-of select="normalize-space($classAttributeValue)"/></xsl:attribute>
2925    </xsl:template>
2926
2927
2928    <xsl:template name="create-unique-style-id">
2929        <xsl:param name="styleName" />
2930        <xsl:param name="styleFamily" />
2931
2932        <xsl:call-template name="abbreviate-style-family-name">
2933            <xsl:with-param name="styleFamily" select="$styleFamily"/>
2934        </xsl:call-template>
2935        <xsl:text>-</xsl:text>
2936        <xsl:value-of select="translate($styleName, '.,;: %()[]/\+', '_____________')"/>
2937    </xsl:template>
2938
2939
2940    <xsl:template name="abbreviate-style-family-name">
2941            <xsl:param name="styleFamily" />
2942        <!--<xsl:message>abbreviate-style-family-name: The style family is '<xsl:value-of select="$styleFamily"/>'</xsl:message>-->
2943
2944        <!--
2945        	The complete set of family types (aka @style:family) is defined in the ODF specification:
2946            	https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part3-schema/OpenDocument-v1.3-os-part3-schema.html#attribute-style_family
2947            (realized style family 'section' is missing, see https://docs.oasis-open.org/office/OpenDocument/v1.3/os/schemas/OpenDocument-v1.3-schema-rng.html#12668
2948                and wrote an issue to ODF TC: https://github.com/oasis-tcs/odf-tc/issues/49
2949        -->
2950        <xsl:choose>
2951            <!-- chart: family name of styles for charts. -->
2952            <xsl:when test="$styleFamily='chart'">
2953                <xsl:text>chart</xsl:text>
2954            </xsl:when>
2955            <!-- drawing-page: family name of styles for drawing pages. -->
2956            <xsl:when test="$styleFamily='drawing-page'">
2957                <xsl:text>page</xsl:text>
2958            </xsl:when>
2959            <!-- graphic: family name of styles for graphic elements. -->
2960            <xsl:when test="$styleFamily='graphic'">
2961                <xsl:text>graphic</xsl:text>
2962            </xsl:when>
2963            <!-- paragraph: family name of styles for paragraphs. -->
2964            <xsl:when test="$styleFamily='paragraph'">
2965                <xsl:text>paragraph</xsl:text>
2966            </xsl:when>
2967            <!-- presentation: family name of styles for presentations. -->
2968            <xsl:when test="$styleFamily='presentation'">
2969                <xsl:text>presentation</xsl:text>
2970            </xsl:when>
2971            <!-- ruby: family name of styles for ruby text. -->
2972            <xsl:when test="$styleFamily='ruby'">
2973                <xsl:text>ruby</xsl:text>
2974            </xsl:when>
2975            <!-- section: family name of styles for sections. -->
2976            <xsl:when test="$styleFamily='section'">
2977                <xsl:text>section</xsl:text>
2978            </xsl:when>
2979            <!-- table: family name of styles for tables. -->
2980            <xsl:when test="$styleFamily='table'">
2981                <xsl:text>table</xsl:text>
2982            </xsl:when>
2983            <!-- table-cell: family name of styles for table cells. -->
2984            <xsl:when test="$styleFamily='table-cell'">
2985                <xsl:text>cell</xsl:text>
2986            </xsl:when>
2987            <!-- table-column: family name of styles for table columns. -->
2988            <xsl:when test="$styleFamily='table-column'">
2989                <xsl:text>col</xsl:text>
2990            </xsl:when>
2991            <!-- table-row: family name of styles for table rows. -->
2992            <xsl:when test="$styleFamily='table-row'">
2993                <xsl:text>row</xsl:text>
2994            </xsl:when>
2995            <!-- text: family name of styles for text. -->
2996            <xsl:when test="$styleFamily='text'">
2997                <xsl:text>text</xsl:text>
2998            </xsl:when>
2999            <xsl:otherwise>
3000                <xsl:message>WARNING: No style family found for <xsl:value-of select="$styleFamily"/></xsl:message>
3001                <xsl:text>unknown-family</xsl:text>
3002            </xsl:otherwise>
3003        </xsl:choose>
3004    </xsl:template>
3005
3006    <xsl:template name="get-style-family-name">
3007        <xsl:param name="parentName" />
3008
3009
3010        <!--<xsl:message>get-style-family-name: The style parent is '<xsl:value-of select="name(..)"/>'</xsl:message>-->
3011        <!--
3012        	The complete set of family types (aka @style:family) is defined in the ODF specification:
3013            	https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part3-schema/OpenDocument-v1.3-os-part3-schema.html#attribute-style_family
3014            (realized style family 'section' is missing, see https://docs.oasis-open.org/office/OpenDocument/v1.3/os/schemas/OpenDocument-v1.3-schema-rng.html#12668
3015                and wrote an issue to ODF TC: https://github.com/oasis-tcs/odf-tc/issues/49
3016
3017            in addition the mapping of styleable ODF elements to their @style:family attribute is available in structured form (XML) in the ODF Toolkit generator project:
3018            	https://github.com/tdf/odftoolkit/blob/master/generator/schema2template/src/test/resources/test-input/odf/generation/odfdom-java/dom/grammar-additions.xml#LL43C52-L43C52r-additions.xml#LL43C52-L43C52
3019        -->
3020        <xsl:choose>
3021            <!-- chart: family name of styles for charts. -->
3022            <xsl:when test="
3023            		$parentName='chart:axis' or
3024					$parentName='chart:chart' or
3025					$parentName='chart:data-point' or
3026					$parentName='chart:error-indicator' or
3027					$parentName='chart:floor' or
3028					$parentName='chart:footer' or
3029					$parentName='chart:grid' or
3030					$parentName='chart:legend' or
3031					$parentName='chart:mean-value' or
3032					$parentName='chart:plot-area' or
3033					$parentName='chart:regression-curve' or
3034					$parentName='chart:series' or
3035					$parentName='chart:stock-gain-marker' or
3036					$parentName='chart:stock-loss-marker' or
3037					$parentName='chart:stock-range-line' or
3038					$parentName='chart:subtitle' or
3039					$parentName='chart:title' or
3040					$parentName='chart:wall'">
3041                <xsl:text>chart</xsl:text>
3042            </xsl:when>
3043            <!-- drawing-page: family name of styles for drawing pages. -->
3044            <xsl:when test="
3045            		$parentName='draw:page' or
3046            		$parentName='style:handout-master' or
3047            		$parentName='style:master-page' or
3048        			$parentName='presentation:notes'">
3049                <xsl:text>drawing-page</xsl:text>
3050            </xsl:when>
3051            <!-- graphic: family name of styles for graphic elements. -->
3052            <xsl:when test="
3053            		$parentName='dr3d:cube' or
3054					$parentName='dr3d:extrude' or
3055					$parentName='dr3d:rotate' or
3056					$parentName='dr3d:scene' or
3057					$parentName='dr3d:sphere' or
3058					$parentName='draw:caption' or
3059					$parentName='draw:circle' or
3060					$parentName='draw:connector' or
3061					$parentName='draw:control' or
3062					$parentName='draw:custom-shape' or
3063					$parentName='draw:ellipse' or
3064					$parentName='draw:frame' or
3065					$parentName='draw:g' or
3066					$parentName='draw:line' or
3067					$parentName='draw:measure' or
3068					$parentName='draw:page-thumbnail' or
3069					$parentName='draw:path' or
3070					$parentName='draw:polygon' or
3071					$parentName='draw:polyline' or
3072					$parentName='draw:rect' or
3073					$parentName='draw:regular-polygon' or
3074					$parentName='office:annotation'">
3075                <xsl:text>graphic</xsl:text>
3076            </xsl:when>
3077            <!-- paragraph: family name of styles for paragraphs. -->
3078            <xsl:when test="
3079					$parentName='text:alphabetical-index-entry-template' or
3080					$parentName='text:bibliography-entry-template' or
3081					$parentName='text:h' or
3082					$parentName='text:illustration-index-entry-template' or
3083					$parentName='text:index-source-style' or
3084					$parentName='text:index-title-template' or
3085					$parentName='text:object-index-entry-template' or
3086					$parentName='text:p' or
3087					$parentName='text:table-index-entry-template' or
3088					$parentName='text:table-of-content-entry-template' or
3089					$parentName='text:user-index-entry-template'">
3090                <xsl:text>paragraph</xsl:text>
3091            </xsl:when>
3092            <!-- presentation: family name of styles for presentations. -->
3093            <xsl:when test="
3094            		$parentName='dr3d:cube' or
3095					$parentName='dr3d:extrude' or
3096					$parentName='dr3d:rotate' or
3097					$parentName='dr3d:scene' or
3098					$parentName='dr3d:sphere' or
3099					$parentName='draw:caption' or
3100					$parentName='draw:circle' or
3101					$parentName='draw:connector' or
3102					$parentName='draw:control' or
3103					$parentName='draw:custom-shape' or
3104					$parentName='draw:ellipse' or
3105					$parentName='draw:frame' or
3106					$parentName='draw:g' or
3107					$parentName='draw:line' or
3108					$parentName='draw:measure' or
3109					$parentName='draw:page-thumbnail' or
3110					$parentName='draw:path' or
3111					$parentName='draw:polygon' or
3112					$parentName='draw:polyline' or
3113					$parentName='draw:rect' or
3114					$parentName='draw:regular-polygon' or
3115					$parentName='office:annotation'">
3116                <xsl:text>presentation</xsl:text>
3117            </xsl:when>
3118            <!-- ruby: family name of styles for ruby text. -->
3119            <xsl:when test="$parentName='text:ruby' or
3120            				$parentName='text:ruby-text'">
3121                <xsl:text>ruby</xsl:text>
3122            </xsl:when>
3123            <!-- section: family name of styles for sections. -->
3124            <xsl:when test="
3125					$parentName='text:alphabetical-index' or
3126					$parentName='text:bibliography' or
3127					$parentName='text:illustration-index' or
3128					$parentName='text:index-title' or
3129					$parentName='text:object-index' or
3130					$parentName='text:page' or
3131					$parentName='text:section' or
3132					$parentName='text:s' or
3133					$parentName='text:table-index' or
3134					$parentName='text:table-of-content' or
3135					$parentName='text:user-index'">
3136                <xsl:text>section</xsl:text>
3137            </xsl:when>
3138            <!-- table: family name of styles for tables. -->
3139            <xsl:when test="$parentName='table:table'">
3140                <xsl:text>table</xsl:text>
3141            </xsl:when>
3142            <!-- table-cell: family name of styles for table cells. -->
3143            <xsl:when test="
3144            	$parentName='table:table-cell' or
3145				$parentName='table:body' or
3146				$parentName='table:even-columns' or
3147				$parentName='table:even-rows' or
3148				$parentName='table:first-column' or
3149				$parentName='table:first-row' or
3150				$parentName='table:last-column' or
3151				$parentName='table:last-row' or
3152				$parentName='table:odd-columns' or
3153				$parentName='table:odd-rows' or
3154				$parentName='table:covered-table-cell'">
3155                <xsl:text>table-cell</xsl:text>
3156            </xsl:when>
3157            <!-- table-column: family name of styles for table columns. -->
3158            <xsl:when test="$parentName='table:table-column'">
3159                <xsl:text>table-column</xsl:text>
3160            </xsl:when>
3161            <!-- table-row: family name of styles for table rows. -->
3162            <xsl:when test="$parentName='table:table-row'">
3163                <xsl:text>table-row</xsl:text>
3164            </xsl:when>
3165            <!-- text: family name of styles for text. -->
3166            <xsl:when test="
3167            	$parentName='text:index-entry-bibliography' or
3168				$parentName='text:index-entry-chapter' or
3169				$parentName='text:index-entry-link-end' or
3170				$parentName='text:index-entry-link-start' or
3171				$parentName='text:index-entry-page-number' or
3172				$parentName='text:index-entry-span' or
3173				$parentName='text:index-entry-tab-stop' or
3174				$parentName='text:index-entry-text' or
3175				$parentName='text:a' or
3176				$parentName='text:span' or
3177				$parentName='style:drop-cap' or
3178				$parentName='text:line-break' or
3179				$parentName='text:tab' or
3180				$parentName='text:linenumbering-configuration'">
3181                <xsl:text>text</xsl:text>
3182            </xsl:when>
3183            <xsl:otherwise>
3184                <xsl:message>WARNING: No style family found for parent element <xsl:value-of select="$parentName"/></xsl:message>
3185                <xsl:text>unknown-family-parent</xsl:text>
3186            </xsl:otherwise>
3187        </xsl:choose>
3188    </xsl:template>
3189
3190
3191    <!-- ***************** -->
3192    <!-- *** Footnotes *** -->
3193    <!-- ***************** -->
3194
3195    <xsl:template match="text:note">
3196        <xsl:param name="globalData"/>
3197
3198        <!-- get style configuration -->
3199        <xsl:variable name="footnoteConfig" select="$globalData/office:styles/text:notes-configuration[@text:note-class=current()/@text:note-class]" />
3200
3201        <xsl:variable name="titlePrefix">
3202            <xsl:choose>
3203                <xsl:when test="@text:note-class = 'footnote'">
3204                    <xsl:text>Footnote: </xsl:text>
3205                </xsl:when>
3206                <xsl:otherwise>
3207                    <xsl:text>Endnote: </xsl:text>
3208                </xsl:otherwise>
3209            </xsl:choose>
3210        </xsl:variable>
3211
3212        <!-- write anchor -->
3213        <xsl:element name="span">
3214            <xsl:attribute name="class">
3215                <xsl:value-of select="$footnoteConfig/@text:citation-body-style-name"/>
3216            </xsl:attribute>
3217            <xsl:attribute name="title">
3218                <xsl:value-of select="$titlePrefix"/>
3219                <xsl:apply-templates mode="textOnly" select="text:note-body"/>
3220            </xsl:attribute>
3221            <xsl:element name="a">
3222                <xsl:attribute name="href">
3223                    <xsl:value-of select="concat('#', @text:id)"/>
3224                </xsl:attribute>
3225                <xsl:attribute name="id">
3226                    <xsl:value-of select="concat('body_', @text:id)"/>
3227                </xsl:attribute>
3228                <xsl:apply-templates mode="textOnly" select="text:note-citation"/>
3229            </xsl:element>
3230        </xsl:element>
3231    </xsl:template>
3232
3233    <xsl:template match="*" mode="textOnly">
3234        <xsl:apply-templates select="* | text()" mode="textOnly" />
3235    </xsl:template>
3236
3237    <xsl:template match="text()" mode="textOnly">
3238        <xsl:value-of select="."/>
3239    </xsl:template>
3240
3241    <!-- Useful in case of 'style:map', conditional formatting, where a style references to another -->
3242    <xsl:key name="textNotes" match="text:note" use="@text:note-class"/>
3243
3244    <!-- writing the footer- and endnotes beyond the body -->
3245    <xsl:template name="write-text-nodes">
3246        <xsl:param name="globalData"/>
3247
3248        <!-- write footnote body -->
3249        <xsl:for-each select="key('textNotes', 'footnote')">
3250            <xsl:call-template name="write-text-node">
3251                <xsl:with-param name="globalData" select="$globalData"/>
3252                <xsl:with-param name="footnoteConfig" select="$globalData/office:styles/text:notes-configuration[@text:note-class=current()/@text:note-class]" />
3253            </xsl:call-template>
3254        </xsl:for-each>
3255
3256        <!-- write endnote body -->
3257        <xsl:for-each select="key('textNotes', 'endnote')">
3258            <xsl:call-template name="write-text-node">
3259
3260                <xsl:with-param name="globalData" select="$globalData"/>
3261                <xsl:with-param name="footnoteConfig" select="$globalData/office:styles/text:notes-configuration[@text:note-class=current()/@text:note-class]" />
3262            </xsl:call-template>
3263        </xsl:for-each>
3264    </xsl:template>
3265
3266    <xsl:template name="write-text-node">
3267        <xsl:param name="globalData"/>
3268        <xsl:param name="footnoteConfig"/>
3269
3270        <xsl:apply-templates select="text:note-body/*[1]">
3271            <xsl:with-param name="globalData" select="$globalData" />
3272            <xsl:with-param name="footnotePrefix">
3273                <xsl:element name="span">
3274                    <xsl:attribute name="class">footnodeNumber</xsl:attribute>
3275                    <xsl:element name="a">
3276                        <xsl:attribute name="class">
3277                            <xsl:value-of select="$footnoteConfig/@text:citation-style-name"/>
3278                        </xsl:attribute>
3279                        <xsl:attribute name="id">
3280                            <xsl:value-of select="@text:id"/>
3281                        </xsl:attribute>
3282                        <xsl:attribute name="href">
3283                            <xsl:value-of select="concat('#body_', @text:id)"/>
3284                        </xsl:attribute>
3285                        <xsl:apply-templates mode="textOnly" select="text:note-citation"/>
3286                    </xsl:element>
3287                </xsl:element>
3288            </xsl:with-param>
3289        </xsl:apply-templates>
3290        <xsl:apply-templates select="text:note-body/*[position()&gt;1]">
3291            <xsl:with-param name="globalData" select="$globalData" />
3292        </xsl:apply-templates>
3293    </xsl:template>
3294
3295    <!-- ***************** -->
3296    <!-- *** Bookmarks *** -->
3297    <!-- ***************** -->
3298
3299    <xsl:template match="text:bookmark|text:bookmark-start">
3300        <xsl:element name="a">
3301            <xsl:attribute name="id">
3302                <xsl:value-of select="@text:name"/>
3303            </xsl:attribute>
3304        </xsl:element>
3305    </xsl:template>
3306
3307    <xsl:template match="text:bookmark-end"/>
3308
3309    <!-- DISABLING this tab handling as the tab width is only relative
3310    <xsl:template match="text:tab">
3311        <xsl:param name="globalData"/>
3312
3313        <xsl:variable name="tabNo">
3314            <xsl:choose>
3315                <xsl:when test="preceding-sibling::text:line-break">
3316                    <xsl:call-template name="countTextTab"/>
3317                </xsl:when>
3318                <xsl:when test="preceding-sibling::text:tab">
3319                    <xsl:value-of select="count(preceding-sibling::text:tab)"/>
3320                </xsl:when>
3321                <xsl:otherwise>1</xsl:otherwise>
3322            </xsl:choose>
3323        </xsl:variable>
3324
3325        <xsl:element name="span">
3326             <xsl:attribute name="style">margin-left:<xsl:value-of select="$globalData/all-doc-styles/style[@style:name = current()/parent::*/@text:style-name]/*/style:tab-stops/style:tab-stop[$tabNo]/@style:position"/>;</xsl:attribute>
3327        </xsl:element>
3328    </xsl:template>
3329
3330    <xsl:template name="countTextTab">
3331        <xsl:param name="tabCount" select="1"/>
3332        <xsl:param name="context" select="."/>
3333
3334        <xsl:choose>
3335            <xsl:when test="preceding-sibling::*[1]">
3336                <xsl:for-each select="preceding-sibling::*[1]">
3337                    <xsl:call-template name="countTextTab">
3338                        <xsl:with-param name="tabCout">
3339                            <xsl:choose>
3340                                <xsl:when test="name(.) = 'text:tab'">
3341                                    <xsl:value-of select="$tabCount + 1"/>
3342                                </xsl:when>
3343                                <xsl:otherwise>
3344                                    <xsl:value-of select="$tabCount"/>
3345                                </xsl:otherwise>
3346                            </xsl:choose>
3347                        </xsl:with-param>
3348                        <xsl:with-param name="context" select="preceding-sibling::*[1]" />
3349                    </xsl:call-template>
3350                </xsl:for-each>
3351            </xsl:when>
3352            <xsl:otherwise>
3353                <xsl:value-of select="$tabCount"/>
3354            </xsl:otherwise>
3355        </xsl:choose>
3356    </xsl:template>
3357-->
3358    <!-- MathML -->
3359    <xsl:template match="draw:object[math:math]">
3360        <xsl:apply-templates select="math:math" mode="math"/>
3361    </xsl:template>
3362
3363    <xsl:template match="*" mode="math">
3364        <xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
3365            <xsl:apply-templates select="@*|node()" mode="math"/>
3366        </xsl:element>
3367    </xsl:template>
3368
3369    <xsl:template match="@*" mode="math">
3370        <xsl:attribute name="{local-name()}">
3371            <xsl:value-of select="."/>
3372        </xsl:attribute>
3373    </xsl:template>
3374
3375    <!-- our mathml should always be inline the text flow -->
3376    <xsl:template match="@display" mode="math">
3377        <xsl:attribute name="{local-name()}">inline</xsl:attribute>
3378    </xsl:template>
3379
3380    <!-- Ignore semantic annotations -->
3381    <xsl:template match="math:semantics" mode="math">
3382        <xsl:apply-templates select="*[1]" mode="math"/>
3383    </xsl:template>
3384
3385</xsl:stylesheet>
3386