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    <xsl:output method="xml" indent="no" encoding="UTF-8" version="1.0" standalone="yes"/>
26    <xsl:include href="../../common/measure_conversion.xsl"/>
27    <xsl:include href="../common/ooo2ms_docpr.xsl"/>
28    <xsl:include href="ooo2wordml_settings.xsl"/>
29    <xsl:include href="ooo2wordml_border.xsl"/>
30    <xsl:include href="ooo2wordml_page.xsl"/>
31    <xsl:include href="ooo2wordml_text.xsl"/>
32    <xsl:include href="ooo2wordml_list.xsl"/>
33    <xsl:include href="ooo2wordml_field.xsl"/>
34    <xsl:include href="ooo2wordml_table.xsl"/>
35    <xsl:include href="ooo2wordml_draw.xsl"/>
36    <xsl:include href="ooo2wordml_path.xsl"/>
37    <xsl:key name="paragraph-style" match="style:style[@style:family='paragraph']" use="@style:name"/>
38    <xsl:key name="text-style" match="style:style[@style:family='text']" use="@style:name"/>
39    <xsl:key name="section-style" match="style:style[@style:family='section']" use="@style:name"/>
40    <xsl:key name="master-page" match="style:master-page" use="@style:name"/>
41    <xsl:key name="page-layout" match="style:page-layout" use="@style:name"/>
42    <xsl:key name="slave-style" match="style:style[string-length(normalize-space(@style:master-page-name)) &gt; 0]" use="@style:name"/>
43    <xsl:key name="list-style" match="office:styles/text:list-style | office:automatic-styles/text:list-style" use="@style:name"/>
44    <xsl:key name="graphics-style" match="style:style[@style:family='graphic']" use="@style:name"/>
45    <xsl:template match="/">
46        <xsl:apply-templates select="office:document"/>
47    </xsl:template>
48    <xsl:template match="office:document">
49        <xsl:processing-instruction name="mso-application">progid="Word.Document"</xsl:processing-instruction>
50        <xsl:variable name="embeddedObjPresent">
51            <xsl:choose>
52                <xsl:when test="//draw:object-ole[1]">yes</xsl:when>
53                <xsl:otherwise>no</xsl:otherwise>
54            </xsl:choose>
55        </xsl:variable>
56        <w:wordDocument xml:space="preserve" w:embeddedObjPresent="{$embeddedObjPresent}">
57            <xsl:apply-templates select="office:meta"/>
58            <xsl:apply-templates select="office:font-face-decls"/>
59            <xsl:if test="office:styles/text:outline-style | office:styles/text:list-style | office:automatic-styles/text:list-style">
60                <xsl:call-template name="ListStyles"/>
61            </xsl:if>
62            <w:styles>
63                <xsl:apply-templates select="office:styles"/>
64                <xsl:apply-templates select="office:automatic-styles"/>
65                <xsl:call-template name="add_hyperlink_style"/>
66                <!--add for hyperlink character style G.Y.-->
67                <xsl:call-template name="add_comments_style"/>
68                <!--add for comments style G.Y.-->
69            </w:styles>
70            <xsl:call-template name="export-oledata"/>
71            <xsl:apply-templates select="office:settings"/>
72            <xsl:apply-templates select="office:body"/>
73        </w:wordDocument>
74    </xsl:template>
75    <xsl:template match="office:body">
76        <xsl:call-template name="page-background"/>
77        <xsl:apply-templates select="office:text"/>
78    </xsl:template>
79    <xsl:template match="office:font-face-decls">
80        <!-- get default font from default paragraph properties -->
81        <w:fonts>
82            <xsl:variable name="default-paragraph-properties" select="/office:document/office:styles/style:default-style[@style:family = 'paragraph']/style:paragraph-properties"/>
83            <w:defaultFonts w:ascii="{$default-paragraph-properties/@style:font-name}" w:h-ansi="{$default-paragraph-properties/@style:font-name}" w:fareast="{$default-paragraph-properties/@style:font-name-asian}" w:cs="{$default-paragraph-properties/@style:font-name-complex}"/>
84            <xsl:for-each select="style:font-face">
85                <w:font w:name="{@style:name}">
86                    <xsl:if test="@style:font-charset = 'x-symbol'">
87                        <w:charset w:val="02"/>
88                    </xsl:if>
89                    <xsl:choose>
90                        <xsl:when test="@style:font-family-generic = 'swiss'">
91                            <w:family w:val="Swiss"/>
92                        </xsl:when>
93                        <xsl:when test="@style:font-family-generic = 'modern'">
94                            <w:family w:val="Modern"/>
95                        </xsl:when>
96                        <xsl:when test="@style:font-family-generic = 'roman'">
97                            <w:family w:val="Roman"/>
98                        </xsl:when>
99                        <xsl:when test="@style:font-family-generic = 'script'">
100                            <w:family w:val="Script"/>
101                        </xsl:when>
102                        <xsl:when test="@style:font-family-generic = 'decorative'">
103                            <w:family w:val="Decorative"/>
104                        </xsl:when>
105                        <xsl:when test="@style:font-family-generic = 'system'">
106                            <w:family w:val="System"/>
107                        </xsl:when>
108                        <xsl:otherwise>
109                            <w:family w:val="System"/>
110                        </xsl:otherwise>
111                    </xsl:choose>
112                    <w:pitch w:val="{@style:font-pitch}"/>
113                </w:font>
114            </xsl:for-each>
115        </w:fonts>
116    </xsl:template>
117    <xsl:template match="office:styles | office:automatic-styles">
118        <xsl:for-each select="*[(name()='style:style' or name()='style:default-style') and (@style:family= 'paragraph' or @style:family= 'text' or @style:family='table')]">
119            <xsl:variable name="style-name">
120                <xsl:choose>
121                    <xsl:when test="name() = 'style:default-style'">
122                        <xsl:value-of select="concat('default-', @style:family, '-style')"/>
123                    </xsl:when>
124                    <xsl:otherwise>
125                        <xsl:value-of select="@style:name"/>
126                    </xsl:otherwise>
127                </xsl:choose>
128            </xsl:variable>
129            <w:style w:styleId="{$style-name}">
130                <xsl:choose>
131                    <xsl:when test="@style:family = 'paragraph'">
132                        <xsl:attribute name="w:type">paragraph</xsl:attribute>
133                    </xsl:when>
134                    <xsl:when test="@style:family = 'text'">
135                        <xsl:attribute name="w:type">character</xsl:attribute>
136                    </xsl:when>
137                    <xsl:when test="@style:family = 'table'">
138                        <xsl:attribute name="w:type">table</xsl:attribute>
139                    </xsl:when>
140                </xsl:choose>
141                <xsl:if test="name() = 'style:default-style'">
142                    <xsl:attribute name="w:default">on</xsl:attribute>
143                </xsl:if>
144                <xsl:choose>
145                    <xsl:when test="@style:parent-style-name">
146                        <w:basedOn w:val="{@style:parent-style-name}"/>
147                    </xsl:when>
148                    <xsl:when test="name() = 'style:style' and @style:family= 'paragraph'">
149                        <w:basedOn w:val="{concat('default-', @style:family, '-style')}"/>
150                    </xsl:when>
151                </xsl:choose>
152                <w:name w:val="{$style-name}"/>
153                <xsl:if test="parent::office:automatic-styles">
154                    <w:hidden w:val="on"/>
155                </xsl:if>
156                <xsl:if test="@style:next-style-name">
157                    <w:next w:val="{@style:next-style-name}"/>
158                </xsl:if>
159                <xsl:choose>
160                    <xsl:when test="@style:family = 'paragraph'">
161                        <xsl:apply-templates select="style:paragraph-properties" mode="paragraph"/>
162                    </xsl:when>
163                    <xsl:when test="@style:family = 'table'">
164                        <w:tblPr>
165                            <xsl:apply-templates select="style:table-properties" mode="table"/>
166                        </w:tblPr>
167                    </xsl:when>
168                </xsl:choose>
169                <xsl:apply-templates select="style:text-properties" mode="character"/>
170            </w:style>
171        </xsl:for-each>
172    </xsl:template>
173    <xsl:template match="office:text">
174        <w:body>
175            <xsl:apply-templates select="text:p | text:h | text:section | text:unordered-list | text:ordered-list | text:list |table:table"/>
176            <xsl:variable name="paragraph-heading-table" select=".//*[name() = 'text:p' or name() = 'text:h' or name() = 'table:table']"/>
177            <xsl:variable name="page" select="$paragraph-heading-table[key( 'slave-style', @*[name()='text:style-name' or name()='table:style-name'])]"/>
178            <w:sectPr>
179                <!--w:type w:val="continuous"/ -->
180                <xsl:apply-templates select="/office:document/office:styles/text:footnotes-configuration">
181                    <xsl:with-param name="within-section" select="'yes'"/>
182                </xsl:apply-templates>
183                <xsl:apply-templates select="/office:document/office:styles/text:endnotes-configuration">
184                    <xsl:with-param name="within-section" select="'yes'"/>
185                </xsl:apply-templates>
186                <xsl:choose>
187                    <xsl:when test="count($page) &gt; 0">
188                        <xsl:apply-templates select="key('master-page', key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/@style:master-page-name)"/>
189                        <xsl:if test="key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number">
190                            <!-- in M$ word the header and footer associate with the w:sectPr, but in StarOffice writer the header and footer associate with the style:master-page -->
191                            <xsl:variable name="pagenumber_start">
192                                <xsl:value-of select=" key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number"/>
193                            </xsl:variable>
194                            <xsl:if test=" number($pagenumber_start)  &gt; 0 ">
195                                <w:pgNumType w:start="{$pagenumber_start}"/>
196                            </xsl:if>
197                            <!-- comment out the below line to enable the header and footer display normally when style:page-number =0  -->
198                            <!-- w:pgNumType w:start="{key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number}"/-->
199                        </xsl:if>
200                    </xsl:when>
201                    <xsl:otherwise>
202                        <xsl:apply-templates select="/office:document/office:master-styles/style:master-page[1]"/>
203                    </xsl:otherwise>
204                </xsl:choose>
205                <xsl:if test="$paragraph-heading-table[last()]/ancestor::text:section">
206                    <xsl:apply-templates select="key('section-style',$paragraph-heading-table[last()]/ancestor::text:section[1]/@text:style-name)" mode="section"/>
207                </xsl:if>
208            </w:sectPr>
209        </w:body>
210    </xsl:template>
211    <xsl:template match="text:section">
212        <xsl:apply-templates select="text:p | text:h | text:section | text:unordered-list | text:ordered-list | text:list | table:table"/>
213    </xsl:template>
214</xsl:stylesheet>
215