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