1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" exclude-result-prefixes="office table style text draw svg   dc config xlink meta oooc dom ooo chart math dr3d form script ooow draw">
25    <!-- the following are common used  fields -->
26    <xsl:template match="text:page-number | text:page-count | text:subject | text:initial-creator |  text:title  | text:date
27     | text:time | text:page-variable-get | text:author-name | text:author-initials | text:file-name  | text:sender-company
28     | text:sender-initials | text:sender-phone-work | text:word-count  | text:paragraph-count | text:character-count
29     | text:description | text:creation-time | text:creation-date | text:editing-cycles | text:editing-duration
30     | text:keywords | text:print-time | text:print-date | text:creator | text:modification-time | text:modification-date
31     | text:user-defined  | text:variable-get | text:user-field-get | text:sequence | text:database-name ">
32        <w:fldSimple>
33            <xsl:variable name="attribute_value1">
34                <xsl:choose>
35                    <xsl:when test="name() = 'text:page-number' or name() = 'text:page-variable-get' ">
36                        <xsl:text> PAGE  </xsl:text>
37                    </xsl:when>
38                    <xsl:when test="name() = 'text:page-count' ">
39                        <xsl:text> NUMPAGES </xsl:text>
40                    </xsl:when>
41                    <xsl:when test=" name() = 'text:subject' ">
42                        <xsl:text> SUBJECT  </xsl:text>
43                    </xsl:when>
44                    <xsl:when test="name() = 'text:initial-creator' ">
45                        <xsl:text> AUTHOR  </xsl:text>
46                    </xsl:when>
47                    <xsl:when test=" name() = 'text:title' ">
48                        <xsl:text> TITLE    </xsl:text>
49                    </xsl:when>
50                    <xsl:when test="name() = 'text:date' ">
51                        <xsl:text> DATE   </xsl:text>
52                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
53                        <xsl:call-template name="field_get_date_format">
54                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
55                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
56                        </xsl:call-template>
57                    </xsl:when>
58                    <xsl:when test=" name() = 'text:time' ">
59                        <xsl:text> TIME   </xsl:text>
60                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
61                        <xsl:call-template name="field_get_time_format">
62                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
63                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
64                        </xsl:call-template>
65                    </xsl:when>
66                    <xsl:when test="name() = 'text:author-name' ">
67                        <xsl:text> AUTHOR   </xsl:text>
68                    </xsl:when>
69                    <xsl:when test="name() = 'text:author-initials' ">
70                        <xsl:text> USERINITIALS </xsl:text>
71                    </xsl:when>
72                    <xsl:when test="name() = 'text:file-name' ">
73                        <xsl:choose>
74                            <xsl:when test="@text:display='name-and-extension' or  @text:display='name' ">
75                                <xsl:text> FILENAME   </xsl:text>
76                            </xsl:when>
77                            <xsl:when test=" @text:display='full' or @text:display='path' ">
78                                <xsl:text>FILENAME    \p </xsl:text>
79                            </xsl:when>
80                        </xsl:choose>
81                    </xsl:when>
82                    <xsl:when test=" name() = 'text:sender-company' ">
83                        <xsl:text> DOCPROPERTY  Company  </xsl:text>
84                    </xsl:when>
85                    <xsl:when test="name() = 'text:sender-initials' ">
86                        <xsl:text> USERINITIALS  </xsl:text>
87                    </xsl:when>
88                    <xsl:when test="name() = 'text:sender-phone-work' ">
89                        <xsl:text> DOCPROPERTY  &quot;Telephone number&quot; </xsl:text>
90                    </xsl:when>
91                    <xsl:when test="name() = 'text:word-count' ">
92                        <xsl:text> DOCPROPERTY  Words </xsl:text>
93                    </xsl:when>
94                    <xsl:when test="name() = 'text:paragraph-count'  ">
95                        <xsl:text> DOCPROPERTY  Paragraphs </xsl:text>
96                    </xsl:when>
97                    <xsl:when test="name() = 'text:character-count' ">
98                        <xsl:text> DOCPROPERTY  CharactersWithSpaces </xsl:text>
99                    </xsl:when>
100                    <xsl:when test="name() = 'text:description' ">
101                        <xsl:text> COMMENTS  </xsl:text>
102                    </xsl:when>
103                    <xsl:when test="name() = 'text:creation-time' ">
104                        <xsl:text> DOCPROPERTY  CreateTime </xsl:text>
105                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
106                        <xsl:call-template name="field_get_time_format">
107                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
108                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
109                        </xsl:call-template>
110                    </xsl:when>
111                    <xsl:when test=" name()= 'text:creation-date' ">
112                        <xsl:text> CREATEDATE </xsl:text>
113                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
114                        <xsl:call-template name="field_get_date_format">
115                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
116                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
117                        </xsl:call-template>
118                    </xsl:when>
119                    <xsl:when test=" name() = 'text:editing-cycles' ">
120                        <xsl:text> REVNUM \* Arabic </xsl:text>
121                    </xsl:when>
122                    <xsl:when test=" name() = 'text:editing-duration' ">
123                        <xsl:text> EDITTIME </xsl:text>
124                    </xsl:when>
125                    <xsl:when test=" name() = 'text:keywords' ">
126                        <xsl:text> KEYWORDS </xsl:text>
127                    </xsl:when>
128                    <xsl:when test=" name() = 'text:print-time' ">
129                        <xsl:text>DOCPROPERTY  LastPrinted  </xsl:text>
130                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
131                        <xsl:call-template name="field_get_time_format">
132                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
133                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
134                        </xsl:call-template>
135                    </xsl:when>
136                    <xsl:when test=" name() = 'text:print-date' ">
137                        <xsl:text>DOCPROPERTY  LastPrinted </xsl:text>
138                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
139                        <xsl:call-template name="field_get_date_format">
140                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
141                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
142                        </xsl:call-template>
143                    </xsl:when>
144                    <xsl:when test=" name() = 'text:creator' ">
145                        <xsl:text> LASTSAVEDBY  </xsl:text>
146                    </xsl:when>
147                    <xsl:when test=" name() = 'text:modification-time' ">
148                        <xsl:text> DOCPROPERTY  LastSavedTime </xsl:text>
149                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
150                        <xsl:call-template name="field_get_time_format">
151                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
152                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
153                        </xsl:call-template>
154                    </xsl:when>
155                    <xsl:when test=" name() = 'text:modification-date' ">
156                        <xsl:text> SAVEDATE  </xsl:text>
157                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
158                        <xsl:call-template name="field_get_date_format">
159                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
160                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
161                        </xsl:call-template>
162                    </xsl:when>
163                    <xsl:when test=" name() = 'text:user-defined' ">
164                        <xsl:text>  DOCPROPERTY </xsl:text>
165                        <xsl:text>&quot;</xsl:text>
166                        <xsl:value-of select="translate(string(@text:name), ' ', '')"/>
167                        <xsl:text>&quot;</xsl:text>
168                    </xsl:when>
169                    <xsl:when test="name() = 'text:variable-get' or name() = 'text:user-field-get' ">
170                        <xsl:value-of select="concat ('DOCVARIABLE ', @text:name)"/>
171                    </xsl:when>
172                    <xsl:when test=" name() = 'text:sequence' ">
173                        <xsl:value-of select="concat(' SEQ  &quot;',@text:name, '&quot;') "/>
174                    </xsl:when>
175                    <xsl:when test="name() = 'text:database-name' ">
176                        <xsl:value-of select="concat (' DATABASE ', @text:database-name, '.' , @text:table-name)"/>
177                    </xsl:when>
178                </xsl:choose>
179                <!-- Get number style format for number fields -->
180                <xsl:if test="@style:num-format">
181                    <xsl:call-template name="field_get_number_format">
182                        <xsl:with-param name="field_number_format_style" select="@style:num-format"/>
183                    </xsl:call-template>
184                </xsl:if>
185                <xsl:text>  \* MERGEFORMAT </xsl:text>
186            </xsl:variable>
187            <xsl:attribute name="w:instr">
188                <xsl:value-of select="$attribute_value1"/>
189            </xsl:attribute>
190            <w:r>
191                <w:rPr>
192                    <xsl:choose>
193                        <xsl:when test="@style:num-format = '가, 나, 다, ...' or @style:num-format ='일, 이, 삼, ...' or @style:num-format ='ㄱ, ㄴ, ㄷ, ...' ">
194                            <w:rFonts w:fareast="Batang" w:hint="fareast"/>
195                            <!--wx:font wx:val="Batang"/ -->
196                            <w:lang w:fareast="KO"/>
197                        </xsl:when>
198                        <xsl:when test="@style:num-format = 'ア, イ, ウ, ...' or @style:num-format = 'ア, イ, ウ, ...' or @style:num-format = 'イ, ロ, ハ, ...' or @style:num-format = 'イ, ロ, ハ, ...' or @style:num-format ='壱, 弐, 参, ...' ">
199                            <w:rFonts w:fareast="MS Mincho" w:hint="fareast"/>
200                            <!--wx:font wx:val="MS Mincho"/ -->
201                            <w:lang w:fareast="JA"/>
202                        </xsl:when>
203                        <xsl:when test=" @style:num-format  ='壹, 	貳, 參, ...' or @style:num-format  ='壹, 貳, 參, ...' or @style:num-format  ='壹, 贰, 	叁, ...'or  @style:num-format  = '一, 二, 三, ...' ">
204                            <w:rFonts w:hint="fareast"/>
205                            <!--wx:font wx:val="宋体"/ -->
206                        </xsl:when>
207                    </xsl:choose>
208                    <w:noProof/>
209                </w:rPr>
210                <w:t>
211                    <xsl:value-of select="."/>
212                </w:t>
213            </w:r>
214        </w:fldSimple>
215    </xsl:template>
216    <xsl:template name="field_get_number_format">
217        <!-- this template get the various of number formats for number type field-->
218        <xsl:param name="field_number_format_style"/>
219        <xsl:choose>
220            <xsl:when test=" $field_number_format_style = '1, 2, 3, ...' or $field_number_format_style = '1'  	">
221                <xsl:text>  \* Arabic </xsl:text>
222            </xsl:when>
223            <xsl:when test="$field_number_format_style = '①, ②, ③, ...' ">
224                <xsl:text> \* CircleNum </xsl:text>
225            </xsl:when>
226            <xsl:when test="$field_number_format_style = 'i' ">
227                <xsl:text>  \* roman  </xsl:text>
228            </xsl:when>
229            <xsl:when test="$field_number_format_style = 'I' ">
230                <xsl:text>  \* ROMAN </xsl:text>
231            </xsl:when>
232            <xsl:when test="$field_number_format_style = '一, 二, 三, ...'">
233                <xsl:text>  \* CHINESENUM3  </xsl:text>
234            </xsl:when>
235            <xsl:when test="  $field_number_format_style ='壹, 	貳, 參, ...' or $field_number_format_style ='壹, 貳, 參, ...' or
236$field_number_format_style ='壹, 贰, 叁, ...' ">
237                <xsl:text>  \* CHINESENUM2  </xsl:text>
238            </xsl:when>
239            <xsl:when test="$field_number_format_style = '壱, 弐, 参, ...' ">
240                <xsl:text>  \* DBNUM3  </xsl:text>
241            </xsl:when>
242            <xsl:when test="$field_number_format_style = '子, 丑, 寅, ...' ">
243                <xsl:text>  \* ZODIAC2 </xsl:text>
244            </xsl:when>
245            <xsl:when test=" $field_number_format_style ='甲, 乙, 丙, ...' ">
246                <xsl:text>  \* ZODIAC1 </xsl:text>
247            </xsl:when>
248            <xsl:when test="$field_number_format_style = 'イ, ロ, ハ, ...' or $field_number_format_style = 'イ, ロ, ハ, ...' ">
249                <xsl:text> \* Iroha </xsl:text>
250            </xsl:when>
251            <xsl:when test="$field_number_format_style ='ア, イ, ウ, ...' or $field_number_format_style ='ア, イ, ウ, ...' ">
252                <xsl:text> \* Aiueo </xsl:text>
253            </xsl:when>
254            <xsl:when test="$field_number_format_style = '일, 이, 삼, ...' ">
255                <xsl:text> \* DBNUM1 </xsl:text>
256            </xsl:when>
257            <xsl:when test="$field_number_format_style ='ㄱ, ㄴ, ㄷ, ...' or $field_number_format_style = '㉠, ㉡, ㉢, ...' ">
258                <xsl:text> \* Chosung  </xsl:text>
259            </xsl:when>
260            <xsl:when test="$field_number_format_style = '가, 나, 다, ...' or $field_number_format_style = '㉮, ㉯, ㉰, ...' ">
261                <xsl:text>  \* Ganada </xsl:text>
262            </xsl:when>
263            <xsl:when test="$field_number_format_style = 'ア, イ, ウ, ...' or $field_number_format_style = 'ア, イ, ウ, ...' ">
264                <xsl:text>  \* Aiueo </xsl:text>
265            </xsl:when>
266            <xsl:when test="$field_number_format_style ='a' ">
267                <xsl:text>  \* alphabetic </xsl:text>
268            </xsl:when>
269            <xsl:when test="$field_number_format_style ='A' ">
270                <xsl:text>  \* ALPHABETIC </xsl:text>
271            </xsl:when>
272            <xsl:when test="$field_number_format_style = 'א, ב, ג, ...' ">
273                <xsl:text>  \* hebrew2  </xsl:text>
274            </xsl:when>
275            <xsl:when test="$field_number_format_style = 'أ, ب, ت, ...' ">
276                <xsl:text>  \* ArabicAlpha </xsl:text>
277            </xsl:when>
278            <xsl:when test="$field_number_format_style = 'ก, ข, ฃ, ...' ">
279                <xsl:text>  \* ThaiLetter </xsl:text>
280            </xsl:when>
281            <xsl:otherwise>
282                <xsl:text> </xsl:text>
283            </xsl:otherwise>
284        </xsl:choose>
285    </xsl:template>
286    <xsl:template name="field_get_date_format">
287        <xsl:param name="field_date_stylename"/>
288        <xsl:param name="field_date_value"/>
289        <!-- this template retun null date format ATM-->
290        <xsl:text/>
291    </xsl:template>
292    <xsl:template name="field_get_time_format">
293        <xsl:param name="field_time_stylename"/>
294        <xsl:param name="field_time_value"/>
295        <!-- this template retun null date format ATM-->
296        <xsl:text/>
297    </xsl:template>
298    <xsl:template match="text:template-name">
299        <xsl:choose>
300            <xsl:when test="@text:display='title' or @text:display= 'area' ">
301                <!-- directly export the content -->
302                <w:r>
303                    <w:rPr>
304                        <w:noProof/>
305                    </w:rPr>
306                    <w:t>
307                        <xsl:value-of select="."/>
308                    </w:t>
309                </w:r>
310            </xsl:when>
311            <xsl:otherwise>
312                <w:fldSimple>
313                    <xsl:variable name="template_attribute_value">
314                        <xsl:choose>
315                            <xsl:when test="@text:display='name-and-extension' or          @text:display= 'name' ">
316                                <xsl:text> TEMPLATE </xsl:text>
317                            </xsl:when>
318                            <xsl:when test=" @text:display='full' or @text:display='path' ">
319                                <xsl:text>TEMPLATE  \p </xsl:text>
320                            </xsl:when>
321                        </xsl:choose>
322                        <xsl:text>\* MERGEFORMAT </xsl:text>
323                    </xsl:variable>
324                    <xsl:attribute name="w:instr">
325                        <xsl:value-of select="$template_attribute_value"/>
326                    </xsl:attribute>
327                    <w:r>
328                        <w:rPr>
329                            <w:noProof/>
330                        </w:rPr>
331                        <w:t>
332                            <xsl:value-of select="."/>
333                        </w:t>
334                    </w:r>
335                </w:fldSimple>
336            </xsl:otherwise>
337        </xsl:choose>
338    </xsl:template>
339    <xsl:template match="text:text-input | text:variable-input | text:user-field-input">
340        <w:fldSimple>
341            <xsl:variable name="text-input-attribute">
342                <xsl:text>FILLIN  </xsl:text>
343                <xsl:if test="@text:description">
344                    <xsl:value-of select="@text:description"/>
345                </xsl:if>
346                <xsl:text> \* MERGEFORMAT</xsl:text>
347            </xsl:variable>
348            <xsl:attribute name="w:instr">
349                <xsl:value-of select="$text-input-attribute"/>
350            </xsl:attribute>
351            <w:r>
352                <w:rPr>
353                    <w:noProof/>
354                </w:rPr>
355                <xsl:call-template name="field_convert_linebreak">
356                    <xsl:with-param name="field_input_text" select="text()"/>
357                </xsl:call-template>
358            </w:r>
359        </w:fldSimple>
360    </xsl:template>
361    <xsl:template name="field_convert_linebreak">
362        <!-- this template convert the linebreak (&#x0A; and &#x0D;) in continous text to Ms word element<w:br/> -->
363        <xsl:param name="field_input_text"/>
364        <xsl:if test="not (contains($field_input_text,'&#x0A;'))">
365            <w:t>
366                <xsl:value-of select="$field_input_text"/>
367            </w:t>
368        </xsl:if>
369        <xsl:if test="contains($field_input_text,'&#x0A;')">
370            <w:t>
371                <xsl:value-of select="translate(substring-before($field_input_text,'&#x0A;'),'&#x0D;','')"/>
372            </w:t>
373            <w:br/>
374            <xsl:call-template name="field_convert_linebreak">
375                <xsl:with-param name="field_input_text" select="substring-after($field_input_text,'&#x0A;')"/>
376            </xsl:call-template>
377        </xsl:if>
378    </xsl:template>
379    <xsl:template name="field_declare">
380        <!-- this template export the field declaration to w:docpr -->
381        <xsl:param name="simple_field_variable_declares"/>
382        <xsl:param name="user_field_variable_declares"/>
383        <xsl:param name="field_sequence_declares"/>
384        <w:docVars>
385            <xsl:if test="$simple_field_variable_declares/text:variable-decl">
386                <xsl:for-each select="$simple_field_variable_declares/text:variable-decl">
387                    <w:docVar w:name="{@text:name}" w:val="default value"/>
388                </xsl:for-each>
389            </xsl:if>
390            <xsl:if test="$user_field_variable_declares/text:user-field-decl">
391                <xsl:for-each select="$user_field_variable_declares/text:user-field-decl">
392                    <w:docVar w:name="{@text:name}" w:val="{@text:string-value}"/>
393                </xsl:for-each>
394            </xsl:if>
395            <xsl:if test="$field_sequence_declares/text:sequence-decl">
396                <!-- do nothing for sequence declares when exporting to MS word-->
397            </xsl:if>
398        </w:docVars>
399    </xsl:template>
400    <xsl:template match="text:reference-ref | text:bookmark-ref | text:footnote-ref
401                                | text:endnote-ref ">
402        <!-- this template is for reference fields -->
403        <w:r>
404            <w:fldChar w:fldCharType="begin"/>
405        </w:r>
406        <xsl:variable name="complicate_field_instruction">
407            <xsl:choose>
408                <xsl:when test=" name() = 'text:reference-ref'  ">
409                    <xsl:choose>
410                        <xsl:when test=" string(@text:reference-format) = 'page' ">
411                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
412                        </xsl:when>
413                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
414                            <xsl:value-of select="concat(' REF ',  @text:ref-name, '\n \h') "/>
415                        </xsl:when>
416                        <xsl:when test="string(@text:reference-format) = 'text' ">
417                            <xsl:value-of select="concat ( ' REF ' , @text:ref-name, ' \h') "/>
418                        </xsl:when>
419                        <xsl:when test="string(@text:reference-format) = 'direction' ">
420                            <xsl:value-of select="concat(' REF ', @text:ref-name, ' \p \h' ) "/>
421                        </xsl:when>
422                        <xsl:otherwise>
423                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
424                        </xsl:otherwise>
425                    </xsl:choose>
426                </xsl:when>
427                <xsl:when test="name() = 'text:footnote-ref' or name() = 'text:endnote-ref' ">
428                    <xsl:choose>
429                        <xsl:when test=" string(@text:reference-format) = 'page' ">
430                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
431                        </xsl:when>
432                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
433                            <xsl:value-of select="concat(' REF ',  @text:ref-name, '\n  \h') "/>
434                        </xsl:when>
435                        <xsl:when test="string(@text:reference-format) = 'text' ">
436                            <xsl:value-of select="concat ( ' NOTEREF ' , @text:ref-name, ' \h') "/>
437                        </xsl:when>
438                        <xsl:when test="string(@text:reference-format) = 'direction' ">
439                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, ' \p \h' ) "/>
440                        </xsl:when>
441                        <xsl:otherwise>
442                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
443                        </xsl:otherwise>
444                    </xsl:choose>
445                </xsl:when>
446                <xsl:when test="name() = 'text:bookmark-ref' ">
447                    <xsl:choose>
448                        <xsl:when test=" string(@text:reference-format) = 'page' ">
449                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
450                        </xsl:when>
451                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
452                            <xsl:value-of select="concat(' PAGEREF ',  @text:ref-name, '  \h') "/>
453                        </xsl:when>
454                        <xsl:when test="string(@text:reference-format) = 'text' ">
455                            <xsl:value-of select="concat ( ' REF ' , @text:ref-name, ' \h') "/>
456                        </xsl:when>
457                        <xsl:when test="string(@text:reference-format) = 'direction' ">
458                            <xsl:value-of select="concat(' REF ', @text:ref-name, ' \p \h' ) "/>
459                        </xsl:when>
460                        <xsl:otherwise>
461                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
462                        </xsl:otherwise>
463                    </xsl:choose>
464                </xsl:when>
465            </xsl:choose>
466        </xsl:variable>
467        <!--start to combine the complicate field instruction -->
468        <w:r>
469            <w:instrText>
470                <xsl:value-of select="$complicate_field_instruction"/>
471            </w:instrText>
472        </w:r>
473        <w:r>
474            <w:fldChar w:fldCharType="separate"/>
475        </w:r>
476        <w:r>
477            <w:rPr>
478                <w:noProof/>
479            </w:rPr>
480            <w:t>
481                <xsl:value-of select="."/>
482            </w:t>
483        </w:r>
484        <w:r>
485            <w:fldChar w:fldCharType="end"/>
486        </w:r>
487    </xsl:template>
488    <xsl:template match="text:chapter | text:sender-firstname | text:sender-lastname
489                                    | text:sender-street | text:sender-country | text:sender-postal-code
490                                    | text:sender-city | text:sender-title | text:sender-position
491                                    | text:sender-phone-private | text:sender-email | text:sender-fax
492                                    | text:sender-state-or-province | text:table-count | text:image-count
493                                    | text:object-count | text:printed-by | text:hidden-paragraph
494                                    | text:placeholder | text:drop-down | text:conditional-text
495                                    | text:variable-set | text:table-formula | text:database-display
496                                    | text:database-next | text:database-select | text:database-row-number
497                                    | text:sequence-ref | text:expression | text:sheet-name | text:dde-connection">
498        <!-- this template just export content of staroffice fields that do not have the corresponding fields in MS word  ATM -->
499        <w:r>
500            <w:rPr>
501                <w:noProof/>
502            </w:rPr>
503            <w:t>
504                <xsl:value-of select="."/>
505            </w:t>
506        </w:r>
507    </xsl:template>
508    <xsl:template match="text:execute-macro | text:variable-decls | text:variable-decl | text:user-field-decls | text:variable-decl | text:sequence-decls | text:sequence-decl | text:page-variable-set |  text:bibliography-mark | text:script | text:page-continuation ">
509        <!-- this template is to ignore matched elements when exporting writer to word -->
510    </xsl:template>
511    <xsl:template match="text:a ">
512        <xsl:call-template name="export_hyoerlink"/>
513    </xsl:template>
514    <xsl:template name="export_hyoerlink">
515        <!-- all params are useed by draw -->
516        <xsl:param name="TargetMeasure"/>
517        <xsl:param name="x-adjust"/>
518        <xsl:param name="y-adjust"/>
519        <xsl:param name="force-draw"/>
520        <!-- this template processes the hyperlink in writer -->
521        <xsl:variable name="hyperlink_filename">
522            <xsl:choose>
523                <xsl:when test="contains(@xlink:href, '#')">
524                    <xsl:value-of select="substring-before(@xlink:href, '#')"/>
525                </xsl:when>
526                <xsl:otherwise>
527                    <xsl:value-of select="@xlink:href"/>
528                </xsl:otherwise>
529            </xsl:choose>
530        </xsl:variable>
531        <xsl:variable name="hyperlink_bookmark">
532            <xsl:if test="contains(@xlink:href, '#')">
533                <xsl:choose>
534                    <xsl:when test="contains(@xlink:href, '%7C')">
535                        <xsl:call-template name="translate_string">
536                            <xsl:with-param name="t_input_string" select="substring-before( substring-after(@xlink:href, '#'), '%7C')"/>
537                            <xsl:with-param name="t_pattern_string" select=" '%20' "/>
538                            <xsl:with-param name="t_substitute_string" select=" ' ' "/>
539                            <xsl:with-param name="t_output_string" select=" '' "/>
540                        </xsl:call-template>
541                    </xsl:when>
542                    <xsl:otherwise>
543                        <xsl:call-template name="translate_string">
544                            <xsl:with-param name="t_input_string" select="substring-after(@xlink:href, '#')"/>
545                            <xsl:with-param name="t_pattern_string" select=" '%20' "/>
546                            <xsl:with-param name="t_substitute_string" select=" ' ' "/>
547                            <xsl:with-param name="t_output_string" select=" '' "/>
548                        </xsl:call-template>
549                    </xsl:otherwise>
550                </xsl:choose>
551            </xsl:if>
552        </xsl:variable>
553        <w:hlink>
554            <xsl:if test="@xlink:href">
555                <xsl:attribute name="w:dest">
556                    <xsl:value-of select="$hyperlink_filename"/>
557                </xsl:attribute>
558            </xsl:if>
559            <xsl:if test="contains(@xlink:href, '#')">
560                <xsl:attribute name="w:bookmark">
561                    <xsl:value-of select="$hyperlink_bookmark"/>
562                </xsl:attribute>
563            </xsl:if>
564            <xsl:if test="@office:target-frame-name">
565                <xsl:attribute name="w:target">
566                    <xsl:value-of select="@office:target-frame-name"/>
567                </xsl:attribute>
568            </xsl:if>
569            <xsl:if test="@office:name">
570                <xsl:attribute name="w:screenTip">
571                    <xsl:value-of select="@office:name"/>
572                </xsl:attribute>
573            </xsl:if>
574            <w:r>
575                <w:rPr>
576                    <w:rStyle w:val="Hyperlink"/>
577                </w:rPr>
578                <!--apply inline-text-elements, many many many ...  -->
579                <xsl:apply-templates select="text:a | text:span | text() | text:hidden-text
580            | text:line-break | text:tab-stop | text:s | text:page-number | text:page-count | text:subject
581            | text:initial-creator | text:title | text:date | text:time | text:author-name
582            | text:author-initials | text:chapter | text:file-name | text:sender-company
583            | text:sender-firstname | text:sender-lastname | text:sender-initials | text:sender-street
584            | text:sender-country | text:sender-postal-code | text:sender-city | text:sender-title
585            | text:sender-position | text:sender-phone-private | text:sender-phone-work
586            | text:sender-email | text:sender-fax | text:sender-state-or-province | text:word-count
587            | text:paragraph-count | text:character-count | text:table-count | text:image-count
588            | text:object-count | text:template-name | text:description | text:creation-time
589            | text:creation-date | text:editing-cycles | text:editing-duration | text:keywords
590            | text:print-time | text:print-date | text:creator | text:modification-time
591            | text:modification-date | text:user-defined | text:printed-by | text:hidden-paragraph
592            | text:placeholder | text:drop-down | text:conditional-text  | text:text-input
593            | text:execute-macro | text:variable-set | text:variable-input
594            | text:user-field-input | text:variable-get | text:user-field-get | text:sequence
595            | text:page-variable-set | text:page-variable-get | text:table-formula
596            | text:database-display | text:database-next| text:database-select
597            | text:database-row-number | text:database-name | text:reference-ref
598            | text:bookmark-ref | text:footnote-ref  | text:endnote-ref | text:sequence-ref
599            | text:expression | text:measure | text:dde-connection | text:sheet-name
600            | text:bibliography-mark | text:script | text:page-continuation | office:annotation
601            | draw:*">
602                    <xsl:with-param name="TargetMeasure" select="$TargetMeasure"/>
603                    <xsl:with-param name="x-adjust" select="$x-adjust"/>
604                    <xsl:with-param name="y-adjust" select="$y-adjust"/>
605                    <xsl:with-param name="force-draw" select="$force-draw"/>
606                </xsl:apply-templates>
607            </w:r>
608        </w:hlink>
609    </xsl:template>
610    <xsl:template name="translate_string">
611        <!-- this template is to replace  the substring  matched t_pattern_string  in t_t_input_string with t_substitute_string  G.Y.-->
612        <xsl:param name="t_input_string"/>
613        <xsl:param name="t_pattern_string"/>
614        <xsl:param name="t_substitute_string"/>
615        <xsl:param name="t_output_string"/>
616        <xsl:variable name="t_temp_output_string">
617            <xsl:if test="contains($t_input_string, $t_pattern_string) ">
618                <xsl:value-of select="concat($t_output_string, substring-before($t_input_string,$t_pattern_string), $t_substitute_string) "/>
619            </xsl:if>
620            <xsl:if test="not (contains($t_input_string, $t_pattern_string)) ">
621                <xsl:value-of select="$t_output_string"/>
622            </xsl:if>
623        </xsl:variable>
624        <xsl:if test="contains($t_input_string, $t_pattern_string) ">
625            <xsl:call-template name="translate_string">
626                <xsl:with-param name="t_input_string" select="substring-after($t_input_string,$t_pattern_string)"/>
627                <xsl:with-param name="t_pattern_string" select="$t_pattern_string"/>
628                <xsl:with-param name="t_substitute_string" select="$t_substitute_string"/>
629                <xsl:with-param name="t_output_string" select="$t_temp_output_string"/>
630            </xsl:call-template>
631        </xsl:if>
632        <xsl:if test="not (contains($t_input_string, $t_pattern_string))">
633            <xsl:value-of select="concat($t_temp_output_string, $t_input_string)"/>
634        </xsl:if>
635    </xsl:template>
636    <xsl:template name="add_hyperlink_style">
637        <!--this template is to add the hyperlink related style -->
638        <w:style w:type="character" w:styleId="Hyperlink">
639            <w:name w:val="Hyperlink"/>
640            <w:rsid w:val="006A55B0"/>
641            <w:rPr>
642                <w:color w:val="000080"/>
643                <w:u w:val="single"/>
644            </w:rPr>
645        </w:style>
646        <w:style w:type="character" w:styleId="FollowedHyperlink">
647            <w:name w:val="FollowedHyperlink"/>
648            <w:rsid w:val="006A55B0"/>
649            <w:rPr>
650                <w:color w:val="800000"/>
651                <w:u w:val="single"/>
652            </w:rPr>
653        </w:style>
654    </xsl:template>
655    <xsl:template match="office:annotation">
656        <!-- this template export writer note to word comments -->
657        <xsl:variable name="comments_aml_id">
658            <xsl:call-template name="unique_amlid_generator"/>
659        </xsl:variable>
660        <aml:annotation w:type="Word.Comment.Start">
661            <xsl:attribute name="aml:id">
662                <xsl:value-of select="$comments_aml_id"/>
663            </xsl:attribute>
664        </aml:annotation>
665        <aml:annotation w:type="Word.Comment.End">
666            <xsl:attribute name="aml:id">
667                <xsl:value-of select="$comments_aml_id"/>
668            </xsl:attribute>
669        </aml:annotation>
670        <!-- export aml:annotation content-->
671        <w:r>
672            <w:rPr>
673                <w:rStyle w:val="CommentReference"/>
674            </w:rPr>
675            <aml:annotation aml:author="{@office:author}" aml:createdate="{@office:create-date}" w:type="Word.Comment" w:initials="{@office:author}">
676                <xsl:attribute name="aml:id">
677                    <xsl:value-of select="$comments_aml_id"/>
678                </xsl:attribute>
679                <aml:content>
680                    <xsl:apply-templates select="text:p"/>
681                </aml:content>
682            </aml:annotation>
683        </w:r>
684        <!-- end of  export aml:annotation content-->
685    </xsl:template>
686    <xsl:template name="unique_amlid_generator">
687        <!-- this template generate unique id for aml:id, ATM it only counts the office:annotation, some other elements might be added later -->
688        <xsl:number count="office:annotation" from="/office:document/office:body" level="any" format="1"/>
689    </xsl:template>
690    <xsl:template name="add_comments_style">
691        <w:style w:type="character" w:styleId="CommentReference">
692            <w:name w:val="annotation reference"/>
693            <w:basedOn w:val="DefaultParagraphFont"/>
694            <w:semiHidden/>
695            <w:rsid w:val="007770B7"/>
696            <w:rPr>
697                <w:sz w:val="16"/>
698                <w:sz-cs w:val="16"/>
699            </w:rPr>
700        </w:style>
701        <w:style w:type="paragraph" w:styleId="CommentText">
702            <w:name w:val="annotation text"/>
703            <w:basedOn w:val="Normal"/>
704            <w:semiHidden/>
705            <w:rsid w:val="007770B7"/>
706            <w:pPr>
707                <w:pStyle w:val="CommentText"/>
708            </w:pPr>
709            <w:rPr>
710                <w:sz w:val="20"/>
711                <w:sz-cs w:val="20"/>
712            </w:rPr>
713        </w:style>
714        <w:style w:type="paragraph" w:styleId="CommentSubject">
715            <w:name w:val="annotation subject"/>
716            <w:basedOn w:val="CommentText"/>
717            <w:next w:val="CommentText"/>
718            <w:semiHidden/>
719            <w:rsid w:val="007770B7"/>
720            <w:pPr>
721                <w:pStyle w:val="CommentSubject"/>
722            </w:pPr>
723            <w:rPr>
724                <w:b/>
725                <w:b-cs/>
726            </w:rPr>
727        </w:style>
728    </xsl:template>
729</xsl:stylesheet>
730