ooo2wordml.xsl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. * This file incorporates work covered by the following license notice:
  10. *
  11. * Licensed to the Apache Software Foundation (ASF) under one or more
  12. * contributor license agreements. See the NOTICE file distributed
  13. * with this work for additional information regarding copyright
  14. * ownership. The ASF licenses this file to you under the Apache
  15. * License, Version 2.0 (the "License"); you may not use this file
  16. * except in compliance with the License. You may obtain a copy of
  17. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  18. -->
  19. <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">
  20. <xsl:output method="xml" indent="no" encoding="UTF-8" version="1.0" standalone="yes"/>
  21. <xsl:include href="../../common/measure_conversion.xsl"/>
  22. <xsl:include href="../common/ooo2ms_docpr.xsl"/>
  23. <xsl:include href="ooo2wordml_settings.xsl"/>
  24. <xsl:include href="ooo2wordml_border.xsl"/>
  25. <xsl:include href="ooo2wordml_page.xsl"/>
  26. <xsl:include href="ooo2wordml_text.xsl"/>
  27. <xsl:include href="ooo2wordml_list.xsl"/>
  28. <xsl:include href="ooo2wordml_field.xsl"/>
  29. <xsl:include href="ooo2wordml_table.xsl"/>
  30. <xsl:include href="ooo2wordml_draw.xsl"/>
  31. <xsl:include href="ooo2wordml_path.xsl"/>
  32. <xsl:key name="paragraph-style" match="style:style[@style:family='paragraph']" use="@style:name"/>
  33. <xsl:key name="text-style" match="style:style[@style:family='text']" use="@style:name"/>
  34. <xsl:key name="section-style" match="style:style[@style:family='section']" use="@style:name"/>
  35. <xsl:key name="master-page" match="style:master-page" use="@style:name"/>
  36. <xsl:key name="page-layout" match="style:page-layout" use="@style:name"/>
  37. <xsl:key name="slave-style" match="style:style[string-length(normalize-space(@style:master-page-name)) &gt; 0]" use="@style:name"/>
  38. <xsl:key name="list-style" match="office:styles/text:list-style | office:automatic-styles/text:list-style" use="@style:name"/>
  39. <xsl:key name="graphics-style" match="style:style[@style:family='graphic']" use="@style:name"/>
  40. <xsl:template match="/">
  41. <xsl:apply-templates select="office:document"/>
  42. </xsl:template>
  43. <xsl:template match="office:document">
  44. <xsl:processing-instruction name="mso-application">progid="Word.Document"</xsl:processing-instruction>
  45. <xsl:variable name="embeddedObjPresent">
  46. <xsl:choose>
  47. <xsl:when test="//draw:object-ole[1]">yes</xsl:when>
  48. <xsl:otherwise>no</xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:variable>
  51. <w:wordDocument xml:space="preserve" w:embeddedObjPresent="{$embeddedObjPresent}">
  52. <xsl:apply-templates select="office:meta"/>
  53. <xsl:apply-templates select="office:font-face-decls"/>
  54. <xsl:if test="office:styles/text:outline-style | office:styles/text:list-style | office:automatic-styles/text:list-style">
  55. <xsl:call-template name="ListStyles"/>
  56. </xsl:if>
  57. <w:styles>
  58. <xsl:apply-templates select="office:styles"/>
  59. <xsl:apply-templates select="office:automatic-styles"/>
  60. <xsl:call-template name="add_hyperlink_style"/>
  61. <!--add for hyperlink character style G.Y.-->
  62. <xsl:call-template name="add_comments_style"/>
  63. <!--add for comments style G.Y.-->
  64. </w:styles>
  65. <xsl:call-template name="export-oledata"/>
  66. <xsl:apply-templates select="office:settings"/>
  67. <xsl:apply-templates select="office:body"/>
  68. </w:wordDocument>
  69. </xsl:template>
  70. <xsl:template match="office:body">
  71. <xsl:call-template name="page-background"/>
  72. <xsl:apply-templates select="office:text"/>
  73. </xsl:template>
  74. <xsl:template match="office:font-face-decls">
  75. <!-- get default font from default paragraph properties -->
  76. <w:fonts>
  77. <xsl:variable name="default-paragraph-properties" select="/office:document/office:styles/style:default-style[@style:family = 'paragraph']/style:paragraph-properties"/>
  78. <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}"/>
  79. <xsl:for-each select="style:font-face">
  80. <w:font w:name="{@style:name}">
  81. <xsl:if test="@style:font-charset = 'x-symbol'">
  82. <w:charset w:val="02"/>
  83. </xsl:if>
  84. <xsl:choose>
  85. <xsl:when test="@style:font-family-generic = 'swiss'">
  86. <w:family w:val="Swiss"/>
  87. </xsl:when>
  88. <xsl:when test="@style:font-family-generic = 'modern'">
  89. <w:family w:val="Modern"/>
  90. </xsl:when>
  91. <xsl:when test="@style:font-family-generic = 'roman'">
  92. <w:family w:val="Roman"/>
  93. </xsl:when>
  94. <xsl:when test="@style:font-family-generic = 'script'">
  95. <w:family w:val="Script"/>
  96. </xsl:when>
  97. <xsl:when test="@style:font-family-generic = 'decorative'">
  98. <w:family w:val="Decorative"/>
  99. </xsl:when>
  100. <xsl:when test="@style:font-family-generic = 'system'">
  101. <w:family w:val="System"/>
  102. </xsl:when>
  103. <xsl:otherwise>
  104. <w:family w:val="System"/>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. <w:pitch w:val="{@style:font-pitch}"/>
  108. </w:font>
  109. </xsl:for-each>
  110. </w:fonts>
  111. </xsl:template>
  112. <xsl:template match="office:styles | office:automatic-styles">
  113. <xsl:for-each select="*[(name()='style:style' or name()='style:default-style') and (@style:family= 'paragraph' or @style:family= 'text' or @style:family='table')]">
  114. <xsl:variable name="style-name">
  115. <xsl:choose>
  116. <xsl:when test="name() = 'style:default-style'">
  117. <xsl:value-of select="concat('default-', @style:family, '-style')"/>
  118. </xsl:when>
  119. <xsl:otherwise>
  120. <xsl:value-of select="@style:name"/>
  121. </xsl:otherwise>
  122. </xsl:choose>
  123. </xsl:variable>
  124. <w:style w:styleId="{$style-name}">
  125. <xsl:choose>
  126. <xsl:when test="@style:family = 'paragraph'">
  127. <xsl:attribute name="w:type">paragraph</xsl:attribute>
  128. </xsl:when>
  129. <xsl:when test="@style:family = 'text'">
  130. <xsl:attribute name="w:type">character</xsl:attribute>
  131. </xsl:when>
  132. <xsl:when test="@style:family = 'table'">
  133. <xsl:attribute name="w:type">table</xsl:attribute>
  134. </xsl:when>
  135. </xsl:choose>
  136. <xsl:if test="name() = 'style:default-style'">
  137. <xsl:attribute name="w:default">on</xsl:attribute>
  138. </xsl:if>
  139. <xsl:choose>
  140. <xsl:when test="@style:parent-style-name">
  141. <w:basedOn w:val="{@style:parent-style-name}"/>
  142. </xsl:when>
  143. <xsl:when test="name() = 'style:style' and @style:family= 'paragraph'">
  144. <w:basedOn w:val="{concat('default-', @style:family, '-style')}"/>
  145. </xsl:when>
  146. </xsl:choose>
  147. <w:name w:val="{$style-name}"/>
  148. <xsl:if test="parent::office:automatic-styles">
  149. <w:hidden w:val="on"/>
  150. </xsl:if>
  151. <xsl:if test="@style:next-style-name">
  152. <w:next w:val="{@style:next-style-name}"/>
  153. </xsl:if>
  154. <xsl:choose>
  155. <xsl:when test="@style:family = 'paragraph'">
  156. <xsl:apply-templates select="style:paragraph-properties" mode="paragraph"/>
  157. </xsl:when>
  158. <xsl:when test="@style:family = 'table'">
  159. <w:tblPr>
  160. <xsl:apply-templates select="style:table-properties" mode="table"/>
  161. </w:tblPr>
  162. </xsl:when>
  163. </xsl:choose>
  164. <xsl:apply-templates select="style:text-properties" mode="character"/>
  165. </w:style>
  166. </xsl:for-each>
  167. </xsl:template>
  168. <xsl:template match="office:text">
  169. <w:body>
  170. <xsl:apply-templates select="text:p | text:h | text:section | text:unordered-list | text:ordered-list | text:list |table:table"/>
  171. <xsl:variable name="paragraph-heading-table" select=".//*[name() = 'text:p' or name() = 'text:h' or name() = 'table:table']"/>
  172. <xsl:variable name="page" select="$paragraph-heading-table[key( 'slave-style', @*[name()='text:style-name' or name()='table:style-name'])]"/>
  173. <w:sectPr>
  174. <!--w:type w:val="continuous"/ -->
  175. <xsl:apply-templates select="/office:document/office:styles/text:footnotes-configuration">
  176. <xsl:with-param name="within-section" select="'yes'"/>
  177. </xsl:apply-templates>
  178. <xsl:apply-templates select="/office:document/office:styles/text:endnotes-configuration">
  179. <xsl:with-param name="within-section" select="'yes'"/>
  180. </xsl:apply-templates>
  181. <xsl:choose>
  182. <xsl:when test="count($page) &gt; 0">
  183. <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)"/>
  184. <xsl:if test="key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number">
  185. <!-- 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 -->
  186. <xsl:variable name="pagenumber_start">
  187. <xsl:value-of select=" key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number"/>
  188. </xsl:variable>
  189. <xsl:if test=" number($pagenumber_start) &gt; 0 ">
  190. <w:pgNumType w:start="{$pagenumber_start}"/>
  191. </xsl:if>
  192. <!-- comment out the below line to enable the header and footer display normally when style:page-number =0 -->
  193. <!-- w:pgNumType w:start="{key( 'slave-style', $page[last()]/@*[name()='text:style-name' or name()='table:style-name'])/style:paragraph-properties/@style:page-number}"/-->
  194. </xsl:if>
  195. </xsl:when>
  196. <xsl:otherwise>
  197. <xsl:apply-templates select="/office:document/office:master-styles/style:master-page[1]"/>
  198. </xsl:otherwise>
  199. </xsl:choose>
  200. <xsl:if test="$paragraph-heading-table[last()]/ancestor::text:section">
  201. <xsl:apply-templates select="key('section-style',$paragraph-heading-table[last()]/ancestor::text:section[1]/@text:style-name)" mode="section"/>
  202. </xsl:if>
  203. </w:sectPr>
  204. </w:body>
  205. </xsl:template>
  206. <xsl:template match="text:section">
  207. <xsl:apply-templates select="text:p | text:h | text:section | text:unordered-list | text:ordered-list | text:list | table:table"/>
  208. </xsl:template>
  209. </xsl:stylesheet>