summaryrefslogtreecommitdiff
path: root/filter/source/xslt/export/wordml/ooo2wordml_field.xsl
blob: 6909b71aa07d0b030d85ce9fd87dfc6a50da4597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
<?xml version="1.0" encoding="UTF-8"?>
<!--***********************************************************
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 ***********************************************************-->


<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">
    <!-- the following are common used  fields -->
    <xsl:template match="text:page-number | text:page-count | text:subject | text:initial-creator |  text:title  | text:date
     | text:time | text:page-variable-get | text:author-name | text:author-initials | text:file-name  | text:sender-company
     | text:sender-initials | text:sender-phone-work | text:word-count  | text:paragraph-count | text:character-count
     | text:description | text:creation-time | text:creation-date | text:editing-cycles | text:editing-duration
     | text:keywords | text:print-time | text:print-date | text:creator | text:modification-time | text:modification-date
     | text:user-defined  | text:variable-get | text:user-field-get | text:sequence | text:database-name ">
        <w:fldSimple>
            <xsl:variable name="attribute_value1">
                <xsl:choose>
                    <xsl:when test="name() = 'text:page-number' or name() = 'text:page-variable-get' ">
                        <xsl:text> PAGE  </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:page-count' ">
                        <xsl:text> NUMPAGES </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:subject' ">
                        <xsl:text> SUBJECT  </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:initial-creator' ">
                        <xsl:text> AUTHOR  </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:title' ">
                        <xsl:text> TITLE    </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:date' ">
                        <xsl:text> DATE   </xsl:text>
                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_date_format">
                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:time' ">
                        <xsl:text> TIME   </xsl:text>
                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_time_format">
                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="name() = 'text:author-name' ">
                        <xsl:text> AUTHOR   </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:author-initials' ">
                        <xsl:text> USERINITIALS </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:file-name' ">
                        <xsl:choose>
                            <xsl:when test="@text:display='name-and-extension' or  @text:display='name' ">
                                <xsl:text> FILENAME   </xsl:text>
                            </xsl:when>
                            <xsl:when test=" @text:display='full' or @text:display='path' ">
                                <xsl:text>FILENAME    \p </xsl:text>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:sender-company' ">
                        <xsl:text> DOCPROPERTY  Company  </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:sender-initials' ">
                        <xsl:text> USERINITIALS  </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:sender-phone-work' ">
                        <xsl:text> DOCPROPERTY  &quot;Telephone number&quot; </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:word-count' ">
                        <xsl:text> DOCPROPERTY  Words </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:paragraph-count'  ">
                        <xsl:text> DOCPROPERTY  Paragraphs </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:character-count' ">
                        <xsl:text> DOCPROPERTY  CharactersWithSpaces </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:description' ">
                        <xsl:text> COMMENTS  </xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:creation-time' ">
                        <xsl:text> DOCPROPERTY  CreateTime </xsl:text>
                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_time_format">
                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name()= 'text:creation-date' ">
                        <xsl:text> CREATEDATE </xsl:text>
                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_date_format">
                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:editing-cycles' ">
                        <xsl:text> REVNUM \* Arabic </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:editing-duration' ">
                        <xsl:text> EDITTIME </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:keywords' ">
                        <xsl:text> KEYWORDS </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:print-time' ">
                        <xsl:text>DOCPROPERTY  LastPrinted  </xsl:text>
                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_time_format">
                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:print-date' ">
                        <xsl:text>DOCPROPERTY  LastPrinted </xsl:text>
                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_date_format">
                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:creator' ">
                        <xsl:text> LASTSAVEDBY  </xsl:text>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:modification-time' ">
                        <xsl:text> DOCPROPERTY  LastSavedTime </xsl:text>
                        <!-- ATM, this template just return null time format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_time_format">
                            <xsl:with-param name="field_time_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_time_value" select="@text:time-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:modification-date' ">
                        <xsl:text> SAVEDATE  </xsl:text>
                        <!-- ATM, this template just return null date format, it might be  developed in the future -->
                        <xsl:call-template name="field_get_date_format">
                            <xsl:with-param name="field_date_stylename" select="@style:data-style-name"/>
                            <xsl:with-param name="field_date_value" select="@text:date-value"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:user-defined' ">
                        <xsl:text>  DOCPROPERTY </xsl:text>
                        <xsl:text>&quot;</xsl:text>
                        <xsl:value-of select="translate(string(@text:name), ' ', '')"/>
                        <xsl:text>&quot;</xsl:text>
                    </xsl:when>
                    <xsl:when test="name() = 'text:variable-get' or name() = 'text:user-field-get' ">
                        <xsl:value-of select="concat ('DOCVARIABLE ', @text:name)"/>
                    </xsl:when>
                    <xsl:when test=" name() = 'text:sequence' ">
                        <xsl:value-of select="concat(' SEQ  &quot;',@text:name, '&quot;') "/>
                    </xsl:when>
                    <xsl:when test="name() = 'text:database-name' ">
                        <xsl:value-of select="concat (' DATABASE ', @text:database-name, '.' , @text:table-name)"/>
                    </xsl:when>
                </xsl:choose>
                <!-- Get number style format for number fields -->
                <xsl:if test="@style:num-format">
                    <xsl:call-template name="field_get_number_format">
                        <xsl:with-param name="field_number_format_style" select="@style:num-format"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>  \* MERGEFORMAT </xsl:text>
            </xsl:variable>
            <xsl:attribute name="w:instr">
                <xsl:value-of select="$attribute_value1"/>
            </xsl:attribute>
            <w:r>
                <w:rPr>
                    <xsl:choose>
                        <xsl:when test="@style:num-format = '가, 나, 다, ...' or @style:num-format ='일, 이, 삼, ...' or @style:num-format ='ㄱ, ㄴ, ㄷ, ...' ">
                            <w:rFonts w:fareast="Batang" w:hint="fareast"/>
                            <!--wx:font wx:val="Batang"/ -->
                            <w:lang w:fareast="KO"/>
                        </xsl:when>
                        <xsl:when test="@style:num-format = 'ア, イ, ウ, ...' or @style:num-format = 'ア, イ, ウ, ...' or @style:num-format = 'イ, ロ, ハ, ...' or @style:num-format = 'イ, ロ, ハ, ...' or @style:num-format ='壱, 弐, 参, ...' ">
                            <w:rFonts w:fareast="MS Mincho" w:hint="fareast"/>
                            <!--wx:font wx:val="MS Mincho"/ -->
                            <w:lang w:fareast="JA"/>
                        </xsl:when>
                        <xsl:when test=" @style:num-format  ='壹, 	貳, 參, ...' or @style:num-format  ='壹, 貳, 參, ...' or @style:num-format  ='壹, 贰, 	叁, ...'or  @style:num-format  = '一, 二, 三, ...' ">
                            <w:rFonts w:hint="fareast"/>
                            <!--wx:font wx:val="宋体"/ -->
                        </xsl:when>
                    </xsl:choose>
                    <w:noProof/>
                </w:rPr>
                <w:t>
                    <xsl:value-of select="."/>
                </w:t>
            </w:r>
        </w:fldSimple>
    </xsl:template>
    <xsl:template name="field_get_number_format">
        <!-- this template get the various of number formats for number type field-->
        <xsl:param name="field_number_format_style"/>
        <xsl:choose>
            <xsl:when test=" $field_number_format_style = '1, 2, 3, ...' or $field_number_format_style = '1'  	">
                <xsl:text>  \* Arabic </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '①, ②, ③, ...' ">
                <xsl:text> \* CircleNum </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'i' ">
                <xsl:text>  \* roman  </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'I' ">
                <xsl:text>  \* ROMAN </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '一, 二, 三, ...'">
                <xsl:text>  \* CHINESENUM3  </xsl:text>
            </xsl:when>
            <xsl:when test="  $field_number_format_style ='壹, 	貳, 參, ...' or $field_number_format_style ='壹, 貳, 參, ...' or
$field_number_format_style ='壹, 贰, 叁, ...' ">
                <xsl:text>  \* CHINESENUM2  </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '壱, 弐, 参, ...' ">
                <xsl:text>  \* DBNUM3  </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '子, 丑, 寅, ...' ">
                <xsl:text>  \* ZODIAC2 </xsl:text>
            </xsl:when>
            <xsl:when test=" $field_number_format_style ='甲, 乙, 丙, ...' ">
                <xsl:text>  \* ZODIAC1 </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'イ, ロ, ハ, ...' or $field_number_format_style = 'イ, ロ, ハ, ...' ">
                <xsl:text> \* Iroha </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style ='ア, イ, ウ, ...' or $field_number_format_style ='ア, イ, ウ, ...' ">
                <xsl:text> \* Aiueo </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '일, 이, 삼, ...' ">
                <xsl:text> \* DBNUM1 </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style ='ㄱ, ㄴ, ㄷ, ...' or $field_number_format_style = '㉠, ㉡, ㉢, ...' ">
                <xsl:text> \* Chosung  </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = '가, 나, 다, ...' or $field_number_format_style = '㉮, ㉯, ㉰, ...' ">
                <xsl:text>  \* Ganada </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'ア, イ, ウ, ...' or $field_number_format_style = 'ア, イ, ウ, ...' ">
                <xsl:text>  \* Aiueo </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style ='a' ">
                <xsl:text>  \* alphabetic </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style ='A' ">
                <xsl:text>  \* ALPHABETIC </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'א, ב, ג, ...' ">
                <xsl:text>  \* hebrew2  </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'أ, ب, ت, ...' ">
                <xsl:text>  \* ArabicAlpha </xsl:text>
            </xsl:when>
            <xsl:when test="$field_number_format_style = 'ก, ข, ฃ, ...' ">
                <xsl:text>  \* ThaiLetter </xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text> </xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="field_get_date_format">
        <xsl:param name="field_date_stylename"/>
        <xsl:param name="field_date_value"/>
        <!-- this template retun null date format ATM-->
        <xsl:text/>
    </xsl:template>
    <xsl:template name="field_get_time_format">
        <xsl:param name="field_time_stylename"/>
        <xsl:param name="field_time_value"/>
        <!-- this template retun null date format ATM-->
        <xsl:text/>
    </xsl:template>
    <xsl:template match="text:template-name">
        <xsl:choose>
            <xsl:when test="@text:display='title' or @text:display= 'area' ">
                <!-- directly export the content -->
                <w:r>
                    <w:rPr>
                        <w:noProof/>
                    </w:rPr>
                    <w:t>
                        <xsl:value-of select="."/>
                    </w:t>
                </w:r>
            </xsl:when>
            <xsl:otherwise>
                <w:fldSimple>
                    <xsl:variable name="template_attribute_value">
                        <xsl:choose>
                            <xsl:when test="@text:display='name-and-extension' or          @text:display= 'name' ">
                                <xsl:text> TEMPLATE </xsl:text>
                            </xsl:when>
                            <xsl:when test=" @text:display='full' or @text:display='path' ">
                                <xsl:text>TEMPLATE  \p </xsl:text>
                            </xsl:when>
                        </xsl:choose>
                        <xsl:text>\* MERGEFORMAT </xsl:text>
                    </xsl:variable>
                    <xsl:attribute name="w:instr">
                        <xsl:value-of select="$template_attribute_value"/>
                    </xsl:attribute>
                    <w:r>
                        <w:rPr>
                            <w:noProof/>
                        </w:rPr>
                        <w:t>
                            <xsl:value-of select="."/>
                        </w:t>
                    </w:r>
                </w:fldSimple>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="text:text-input | text:variable-input | text:user-field-input">
        <w:fldSimple>
            <xsl:variable name="text-input-attribute">
                <xsl:text>FILLIN  </xsl:text>
                <xsl:if test="@text:description">
                    <xsl:value-of select="@text:description"/>
                </xsl:if>
                <xsl:text> \* MERGEFORMAT</xsl:text>
            </xsl:variable>
            <xsl:attribute name="w:instr">
                <xsl:value-of select="$text-input-attribute"/>
            </xsl:attribute>
            <w:r>
                <w:rPr>
                    <w:noProof/>
                </w:rPr>
                <xsl:call-template name="field_convert_linebreak">
                    <xsl:with-param name="field_input_text" select="text()"/>
                </xsl:call-template>
            </w:r>
        </w:fldSimple>
    </xsl:template>
    <xsl:template name="field_convert_linebreak">
        <!-- this template convert the linebreak (&#x0A; and &#x0D;) in continuous text to Ms word element<w:br/> -->
        <xsl:param name="field_input_text"/>
        <xsl:if test="not (contains($field_input_text,'&#x0A;'))">
            <w:t>
                <xsl:value-of select="$field_input_text"/>
            </w:t>
        </xsl:if>
        <xsl:if test="contains($field_input_text,'&#x0A;')">
            <w:t>
                <xsl:value-of select="translate(substring-before($field_input_text,'&#x0A;'),'&#x0D;','')"/>
            </w:t>
            <w:br/>
            <xsl:call-template name="field_convert_linebreak">
                <xsl:with-param name="field_input_text" select="substring-after($field_input_text,'&#x0A;')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template name="field_declare">
        <!-- this template export the field declaration to w:docpr -->
        <xsl:param name="simple_field_variable_declares"/>
        <xsl:param name="user_field_variable_declares"/>
        <xsl:param name="field_sequence_declares"/>
        <w:docVars>
            <xsl:if test="$simple_field_variable_declares/text:variable-decl">
                <xsl:for-each select="$simple_field_variable_declares/text:variable-decl">
                    <w:docVar w:name="{@text:name}" w:val="default value"/>
                </xsl:for-each>
            </xsl:if>
            <xsl:if test="$user_field_variable_declares/text:user-field-decl">
                <xsl:for-each select="$user_field_variable_declares/text:user-field-decl">
                    <w:docVar w:name="{@text:name}" w:val="{@text:string-value}"/>
                </xsl:for-each>
            </xsl:if>
            <xsl:if test="$field_sequence_declares/text:sequence-decl">
                <!-- do nothing for sequence declares when exporting to MS word-->
            </xsl:if>
        </w:docVars>
    </xsl:template>
    <xsl:template match="text:reference-ref | text:bookmark-ref | text:footnote-ref
                                | text:endnote-ref ">
        <!-- this template is for reference fields -->
        <w:r>
            <w:fldChar w:fldCharType="begin"/>
        </w:r>
        <xsl:variable name="complicate_field_instruction">
            <xsl:choose>
                <xsl:when test=" name() = 'text:reference-ref'  ">
                    <xsl:choose>
                        <xsl:when test=" string(@text:reference-format) = 'page' ">
                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
                            <xsl:value-of select="concat(' REF ',  @text:ref-name, '\n \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'text' ">
                            <xsl:value-of select="concat ( ' REF ' , @text:ref-name, ' \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'direction' ">
                            <xsl:value-of select="concat(' REF ', @text:ref-name, ' \p \h' ) "/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:when test="name() = 'text:footnote-ref' or name() = 'text:endnote-ref' ">
                    <xsl:choose>
                        <xsl:when test=" string(@text:reference-format) = 'page' ">
                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
                            <xsl:value-of select="concat(' REF ',  @text:ref-name, '\n  \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'text' ">
                            <xsl:value-of select="concat ( ' NOTEREF ' , @text:ref-name, ' \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'direction' ">
                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, ' \p \h' ) "/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:when test="name() = 'text:bookmark-ref' ">
                    <xsl:choose>
                        <xsl:when test=" string(@text:reference-format) = 'page' ">
                            <xsl:value-of select="concat(' PAGEREF ', @text:ref-name, '\h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'chapter' ">
                            <xsl:value-of select="concat(' PAGEREF ',  @text:ref-name, '  \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'text' ">
                            <xsl:value-of select="concat ( ' REF ' , @text:ref-name, ' \h') "/>
                        </xsl:when>
                        <xsl:when test="string(@text:reference-format) = 'direction' ">
                            <xsl:value-of select="concat(' REF ', @text:ref-name, ' \p \h' ) "/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat ( ' PAGEREF ', @text:ref-name, '\h')"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>
        <!--start to combine the complicate field instruction -->
        <w:r>
            <w:instrText>
                <xsl:value-of select="$complicate_field_instruction"/>
            </w:instrText>
        </w:r>
        <w:r>
            <w:fldChar w:fldCharType="separate"/>
        </w:r>
        <w:r>
            <w:rPr>
                <w:noProof/>
            </w:rPr>
            <w:t>
                <xsl:value-of select="."/>
            </w:t>
        </w:r>
        <w:r>
            <w:fldChar w:fldCharType="end"/>
        </w:r>
    </xsl:template>
    <xsl:template match="text:chapter | text:sender-firstname | text:sender-lastname
                                    | text:sender-street | text:sender-country | text:sender-postal-code
                                    | text:sender-city | text:sender-title | text:sender-position
                                    | text:sender-phone-private | text:sender-email | text:sender-fax
                                    | text:sender-state-or-province | text:table-count | text:image-count
                                    | text:object-count | text:printed-by | text:hidden-paragraph
                                    | text:placeholder | text:drop-down | text:conditional-text
                                    | text:variable-set | text:table-formula | text:database-display
                                    | text:database-next | text:database-select | text:database-row-number
                                    | text:sequence-ref | text:expression | text:sheet-name | text:dde-connection">
        <!-- this template just export content of staroffice fields that do not have the corresponding fields in MS word  ATM -->
        <w:r>
            <w:rPr>
                <w:noProof/>
            </w:rPr>
            <w:t>
                <xsl:value-of select="."/>
            </w:t>
        </w:r>
    </xsl:template>
    <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 ">
        <!-- this template is to ignore matched elements when exporting writer to word -->
    </xsl:template>
    <xsl:template match="text:a ">
        <xsl:call-template name="export_hyoerlink"/>
    </xsl:template>
    <xsl:template name="export_hyoerlink">
        <!-- all params are useed by draw -->
        <xsl:param name="TargetMeasure"/>
        <xsl:param name="x-adjust"/>
        <xsl:param name="y-adjust"/>
        <xsl:param name="force-draw"/>
        <!-- this template processes the hyperlink in writer -->
        <xsl:variable name="hyperlink_filename">
            <xsl:choose>
                <xsl:when test="contains(@xlink:href, '#')">
                    <xsl:value-of select="substring-before(@xlink:href, '#')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@xlink:href"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="hyperlink_bookmark">
            <xsl:if test="contains(@xlink:href, '#')">
                <xsl:choose>
                    <xsl:when test="contains(@xlink:href, '%7C')">
                        <xsl:call-template name="translate_string">
                            <xsl:with-param name="t_input_string" select="substring-before( substring-after(@xlink:href, '#'), '%7C')"/>
                            <xsl:with-param name="t_pattern_string" select=" '%20' "/>
                            <xsl:with-param name="t_substitute_string" select=" ' ' "/>
                            <xsl:with-param name="t_output_string" select=" '' "/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="translate_string">
                            <xsl:with-param name="t_input_string" select="substring-after(@xlink:href, '#')"/>
                            <xsl:with-param name="t_pattern_string" select=" '%20' "/>
                            <xsl:with-param name="t_substitute_string" select=" ' ' "/>
                            <xsl:with-param name="t_output_string" select=" '' "/>
                        </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:variable>
        <w:hlink>
            <xsl:if test="@xlink:href">
                <xsl:attribute name="w:dest">
                    <xsl:value-of select="$hyperlink_filename"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="contains(@xlink:href, '#')">
                <xsl:attribute name="w:bookmark">
                    <xsl:value-of select="$hyperlink_bookmark"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="@office:target-frame-name">
                <xsl:attribute name="w:target">
                    <xsl:value-of select="@office:target-frame-name"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="@office:name">
                <xsl:attribute name="w:screenTip">
                    <xsl:value-of select="@office:name"/>
                </xsl:attribute>
            </xsl:if>
            <w:r>
                <w:rPr>
                    <w:rStyle w:val="Hyperlink"/>
                </w:rPr>
                <!--apply inline-text-elements, many many many ...  -->
                <xsl:apply-templates select="text:a | text:span | text() | text:hidden-text
            | text:line-break | text:tab-stop | text:s | text:page-number | text:page-count | text:subject
            | text:initial-creator | text:title | text:date | text:time | text:author-name
            | text:author-initials | text:chapter | text:file-name | text:sender-company
            | text:sender-firstname | text:sender-lastname | text:sender-initials | text:sender-street
            | text:sender-country | text:sender-postal-code | text:sender-city | text:sender-title
            | text:sender-position | text:sender-phone-private | text:sender-phone-work
            | text:sender-email | text:sender-fax | text:sender-state-or-province | text:word-count
            | text:paragraph-count | text:character-count | text:table-count | text:image-count
            | text:object-count | text:template-name | text:description | text:creation-time
            | text:creation-date | text:editing-cycles | text:editing-duration | text:keywords
            | text:print-time | text:print-date | text:creator | text:modification-time
            | text:modification-date | text:user-defined | text:printed-by | text:hidden-paragraph
            | text:placeholder | text:drop-down | text:conditional-text  | text:text-input
            | text:execute-macro | text:variable-set | text:variable-input
            | text:user-field-input | text:variable-get | text:user-field-get | text:sequence
            | text:page-variable-set | text:page-variable-get | text:table-formula
            | text:database-display | text:database-next| text:database-select
            | text:database-row-number | text:database-name | text:reference-ref
            | text:bookmark-ref | text:footnote-ref  | text:endnote-ref | text:sequence-ref
            | text:expression | text:measure | text:dde-connection | text:sheet-name
            | text:bibliography-mark | text:script | text:page-continuation | office:annotation
            | draw:*">
                    <xsl:with-param name="TargetMeasure" select="$TargetMeasure"/>
                    <xsl:with-param name="x-adjust" select="$x-adjust"/>
                    <xsl:with-param name="y-adjust" select="$y-adjust"/>
                    <xsl:with-param name="force-draw" select="$force-draw"/>
                </xsl:apply-templates>
            </w:r>
        </w:hlink>
    </xsl:template>
    <xsl:template name="translate_string">
        <!-- this template is to replace  the substring  matched t_pattern_string  in t_t_input_string with t_substitute_string  G.Y.-->
        <xsl:param name="t_input_string"/>
        <xsl:param name="t_pattern_string"/>
        <xsl:param name="t_substitute_string"/>
        <xsl:param name="t_output_string"/>
        <xsl:variable name="t_temp_output_string">
            <xsl:if test="contains($t_input_string, $t_pattern_string) ">
                <xsl:value-of select="concat($t_output_string, substring-before($t_input_string,$t_pattern_string), $t_substitute_string) "/>
            </xsl:if>
            <xsl:if test="not (contains($t_input_string, $t_pattern_string)) ">
                <xsl:value-of select="$t_output_string"/>
            </xsl:if>
        </xsl:variable>
        <xsl:if test="contains($t_input_string, $t_pattern_string) ">
            <xsl:call-template name="translate_string">
                <xsl:with-param name="t_input_string" select="substring-after($t_input_string,$t_pattern_string)"/>
                <xsl:with-param name="t_pattern_string" select="$t_pattern_string"/>
                <xsl:with-param name="t_substitute_string" select="$t_substitute_string"/>
                <xsl:with-param name="t_output_string" select="$t_temp_output_string"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="not (contains($t_input_string, $t_pattern_string))">
            <xsl:value-of select="concat($t_temp_output_string, $t_input_string)"/>
        </xsl:if>
    </xsl:template>
    <xsl:template name="add_hyperlink_style">
        <!--this template is to add the hyperlink related style -->
        <w:style w:type="character" w:styleId="Hyperlink">
            <w:name w:val="Hyperlink"/>
            <w:rsid w:val="006A55B0"/>
            <w:rPr>
                <w:color w:val="000080"/>
                <w:u w:val="single"/>
            </w:rPr>
        </w:style>
        <w:style w:type="character" w:styleId="FollowedHyperlink">
            <w:name w:val="FollowedHyperlink"/>
            <w:rsid w:val="006A55B0"/>
            <w:rPr>
                <w:color w:val="800000"/>
                <w:u w:val="single"/>
            </w:rPr>
        </w:style>
    </xsl:template>
    <xsl:template match="office:annotation">
        <!-- this template export writer note to word comments -->
        <xsl:variable name="comments_aml_id">
            <xsl:call-template name="unique_amlid_generator"/>
        </xsl:variable>
        <aml:annotation w:type="Word.Comment.Start">
            <xsl:attribute name="aml:id">
                <xsl:value-of select="$comments_aml_id"/>
            </xsl:attribute>
        </aml:annotation>
        <aml:annotation w:type="Word.Comment.End">
            <xsl:attribute name="aml:id">
                <xsl:value-of select="$comments_aml_id"/>
            </xsl:attribute>
        </aml:annotation>
        <!-- export aml:annotation content-->
        <w:r>
            <w:rPr>
                <w:rStyle w:val="CommentReference"/>
            </w:rPr>
            <aml:annotation aml:author="{@office:author}" aml:createdate="{@office:create-date}" w:type="Word.Comment" w:initials="{@office:author}">
                <xsl:attribute name="aml:id">
                    <xsl:value-of select="$comments_aml_id"/>
                </xsl:attribute>
                <aml:content>
                    <xsl:apply-templates select="text:p"/>
                </aml:content>
            </aml:annotation>
        </w:r>
        <!-- end of  export aml:annotation content-->
    </xsl:template>
    <xsl:template name="unique_amlid_generator">
        <!-- this template generate unique id for aml:id, ATM it only counts the office:annotation, some other elements might be added later -->
        <xsl:number count="office:annotation" from="/office:document/office:body" level="any" format="1"/>
    </xsl:template>
    <xsl:template name="add_comments_style">
        <w:style w:type="character" w:styleId="CommentReference">
            <w:name w:val="annotation reference"/>
            <w:basedOn w:val="DefaultParagraphFont"/>
            <w:semiHidden/>
            <w:rsid w:val="007770B7"/>
            <w:rPr>
                <w:sz w:val="16"/>
                <w:sz-cs w:val="16"/>
            </w:rPr>
        </w:style>
        <w:style w:type="paragraph" w:styleId="CommentText">
            <w:name w:val="annotation text"/>
            <w:basedOn w:val="Normal"/>
            <w:semiHidden/>
            <w:rsid w:val="007770B7"/>
            <w:pPr>
                <w:pStyle w:val="CommentText"/>
            </w:pPr>
            <w:rPr>
                <w:sz w:val="20"/>
                <w:sz-cs w:val="20"/>
            </w:rPr>
        </w:style>
        <w:style w:type="paragraph" w:styleId="CommentSubject">
            <w:name w:val="annotation subject"/>
            <w:basedOn w:val="CommentText"/>
            <w:next w:val="CommentText"/>
            <w:semiHidden/>
            <w:rsid w:val="007770B7"/>
            <w:pPr>
                <w:pStyle w:val="CommentSubject"/>
            </w:pPr>
            <w:rPr>
                <w:b/>
                <w:b-cs/>
            </w:rPr>
        </w:style>
    </xsl:template>
</xsl:stylesheet>