dbk2wordml.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:w='http://schemas.microsoft.com/office/word/2003/wordml'
  4. xmlns:v='urn:schemas-microsoft-com:vml'
  5. xmlns:w10="urn:schemas-microsoft-com:office:word"
  6. xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
  7. xmlns:wx='http://schemas.microsoft.com/office/word/2003/auxHint'
  8. xmlns:o="urn:schemas-microsoft-com:office:office"
  9. xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
  10. xmlns:sl='http://schemas.microsoft.com/schemaLibrary/2003/core'
  11. xmlns:doc='http://docbook.org/ns/docbook'
  12. exclude-result-prefixes='doc'>
  13. <xsl:import href='dbk2wp.xsl'/>
  14. <xsl:output method="xml" indent='yes' standalone='yes' encoding='UTF-8'/>
  15. <!-- ********************************************************************
  16. $Id: dbk2wordml.xsl 9651 2012-10-26 20:44:10Z bobstayton $
  17. ********************************************************************
  18. This file is part of the XSL DocBook Stylesheet distribution.
  19. See ../README or http://docbook.sf.net/release/xsl/current/ for
  20. copyright and other information.
  21. ******************************************************************** -->
  22. <xsl:include href='../VERSION.xsl'/>
  23. <xsl:include href='param.xsl'/>
  24. <xsl:strip-space elements='*'/>
  25. <xsl:preserve-space elements='literallayout doc:literallayout
  26. programlisting doc:programlisting'/>
  27. <xsl:variable name='templatedoc' select='document($wordml.template)'/>
  28. <xsl:template match="/" name='wordml.top'>
  29. <xsl:param name='doc' select='/'/>
  30. <xsl:if test='not($wordml.template)'>
  31. <xsl:message terminate='yes'>Please specify the template document with the "wordml.template" parameter</xsl:message>
  32. </xsl:if>
  33. <xsl:if test='not($templatedoc)'>
  34. <xsl:message terminate='yes'>Unable to open template document "<xsl:value-of select='$wordml.template'/>"</xsl:message>
  35. </xsl:if>
  36. <xsl:processing-instruction name='mso-application'>
  37. <xsl:text>progid="Word.Document"</xsl:text>
  38. </xsl:processing-instruction>
  39. <xsl:text>&#xa;</xsl:text>
  40. <xsl:variable name='info'
  41. select='$doc/book/bookinfo|$doc/article/articleinfo'/>
  42. <xsl:variable name='authors' select='$info/author|$info/authorinitials|$info/authorgroup/author|$info/authorgroup/editor'/>
  43. <w:wordDocument
  44. w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no">
  45. <xsl:attribute name='xml:space'>preserve</xsl:attribute>
  46. <o:DocumentProperties>
  47. <o:Author>
  48. <xsl:choose>
  49. <xsl:when test='$authors'>
  50. <xsl:variable name="content">
  51. <xsl:apply-templates select='$authors[1]' mode='doc:docprop.author'/>
  52. </xsl:variable>
  53. <xsl:value-of select="$content"/>
  54. </xsl:when>
  55. <xsl:otherwise>Unknown</xsl:otherwise>
  56. </xsl:choose>
  57. </o:Author>
  58. <o:LastAuthor>
  59. <xsl:variable name="content">
  60. <xsl:choose>
  61. <xsl:when test='$info/revhistory/revision[1]/*[self::author|self::authorinitials]'>
  62. <xsl:apply-templates select='$info/revhistory/revision[1]/*[self::author|self::authorinitials]' mode='doc:docprop.author'/>
  63. </xsl:when>
  64. <xsl:when test='$authors'>
  65. <xsl:apply-templates select='$authors[1]' mode='doc:docprop.author'/>
  66. </xsl:when>
  67. <xsl:otherwise>Unknown</xsl:otherwise>
  68. </xsl:choose>
  69. </xsl:variable>
  70. <xsl:value-of select="$content"/>
  71. </o:LastAuthor>
  72. <o:Revision>1</o:Revision>
  73. <o:TotalTime></o:TotalTime>
  74. <!-- dummy values -->
  75. <o:Created>2004-01-01T07:07:00Z</o:Created>
  76. <o:LastSaved>2004-01-01T08:08:00Z</o:LastSaved>
  77. <o:Pages>1</o:Pages>
  78. <o:Words>1</o:Words>
  79. <o:Characters>1</o:Characters>
  80. <!-- could derive this from author -->
  81. <o:Company>DocBook</o:Company>
  82. <o:Lines>1</o:Lines>
  83. <o:Paragraphs>1</o:Paragraphs>
  84. <o:CharactersWithSpaces>1</o:CharactersWithSpaces>
  85. <o:Version>11.6113</o:Version>
  86. </o:DocumentProperties>
  87. <xsl:apply-templates select='$templatedoc/w:wordDocument/o:CustomDocumentProperties|$templatedoc/w:wordDocument/w:fonts|$templatedoc/w:wordDocument/w:lists|$templatedoc/w:wordDocument/w:styles' mode='doc:copy'/>
  88. <w:docPr>
  89. <w:view w:val="print"/>
  90. <w:zoom w:percent="100"/>
  91. <w:doNotEmbedSystemFonts/>
  92. <w:attachedTemplate w:val=""/>
  93. <w:documentProtection w:formatting='on' w:enforcement='on'
  94. w:unprotectPassword='CAA7FF77'/>
  95. <w:defaultTabStop w:val="720"/>
  96. <w:autoHyphenation/>
  97. <w:hyphenationZone w:val="357"/>
  98. <w:doNotHyphenateCaps/>
  99. <w:evenAndOddHeaders/>
  100. <w:characterSpacingControl w:val="DontCompress"/>
  101. <w:optimizeForBrowser/>
  102. <w:validateAgainstSchema/>
  103. <w:saveInvalidXML w:val="off"/>
  104. <w:ignoreMixedContent w:val="off"/>
  105. <w:alwaysShowPlaceholderText w:val="off"/>
  106. <w:footnotePr>
  107. <w:footnote w:type="separator">
  108. <w:p>
  109. <w:r>
  110. <w:separator/>
  111. </w:r>
  112. </w:p>
  113. </w:footnote>
  114. <w:footnote w:type="continuation-separator">
  115. <w:p>
  116. <w:r>
  117. <w:continuationSeparator/>
  118. </w:r>
  119. </w:p>
  120. </w:footnote>
  121. </w:footnotePr>
  122. <w:endnotePr>
  123. <w:endnote w:type="separator">
  124. <w:p>
  125. <w:r>
  126. <w:separator/>
  127. </w:r>
  128. </w:p>
  129. </w:endnote>
  130. <w:endnote w:type="continuation-separator">
  131. <w:p>
  132. <w:r>
  133. <w:continuationSeparator/>
  134. </w:r>
  135. </w:p>
  136. </w:endnote>
  137. </w:endnotePr>
  138. <w:compat>
  139. <w:breakWrappedTables/>
  140. <w:snapToGridInCell/>
  141. <w:wrapTextWithPunct/>
  142. <w:useAsianBreakRules/>
  143. <w:useWord2002TableStyleRules/>
  144. </w:compat>
  145. <w:docVars>
  146. </w:docVars>
  147. </w:docPr>
  148. <xsl:apply-templates select='$doc/*' mode='doc:toplevel'/>
  149. </w:wordDocument>
  150. </xsl:template>
  151. <xsl:template name='doc:make-body'>
  152. <xsl:param name='content'>
  153. <xsl:apply-templates mode='doc:body'/>
  154. </xsl:param>
  155. <w:body>
  156. <wx:sect>
  157. <wx:sub-section>
  158. <xsl:copy-of select='$content'/>
  159. </wx:sub-section>
  160. </wx:sect>
  161. </w:body>
  162. </xsl:template>
  163. <xsl:template name='doc:make-subsection'>
  164. <xsl:param name='content'>
  165. <xsl:apply-templates mode='doc:body'/>
  166. </xsl:param>
  167. <wx:sub-section>
  168. <xsl:copy-of select='$content'/>
  169. </wx:sub-section>
  170. </xsl:template>
  171. <xsl:template name='doc:make-paragraph'>
  172. <xsl:param name='style' select='"unknown"'/>
  173. <xsl:param name='content'>
  174. <xsl:apply-templates mode='doc:body'/>
  175. </xsl:param>
  176. <xsl:param name='outline.level' select='0'/>
  177. <xsl:param name='attributes.node' select='.'/>
  178. <w:p>
  179. <xsl:if test='$style != "" or
  180. $outline.level != 0'>
  181. <w:pPr>
  182. <xsl:if test='$style != ""'>
  183. <w:pStyle w:val='{$style}'/>
  184. </xsl:if>
  185. <xsl:if test='$outline.level != 0'>
  186. <w:outlineLvl w:val='{$outline.level}'/>
  187. </xsl:if>
  188. </w:pPr>
  189. </xsl:if>
  190. <xsl:call-template name='attributes'>
  191. <xsl:with-param name='node' select='$attributes.node'/>
  192. </xsl:call-template>
  193. <xsl:copy-of select='$content'/>
  194. </w:p>
  195. </xsl:template>
  196. <xsl:template name='doc:make-phrase'>
  197. <xsl:param name='style' select='""'/>
  198. <xsl:param name='italic' select='0'/>
  199. <xsl:param name='bold' select='0'/>
  200. <xsl:param name='content'>
  201. <xsl:apply-templates mode='doc:phrase'/>
  202. </xsl:param>
  203. <w:r>
  204. <xsl:if test='$style != "" or
  205. $bold = 1 or
  206. $italic = 1'>
  207. <w:rPr>
  208. <xsl:if test='$style != ""'>
  209. <w:rStyle w:val='{$style}'/>
  210. </xsl:if>
  211. <xsl:if test='$italic = 1'>
  212. <w:i/>
  213. </xsl:if>
  214. <xsl:if test='$bold = 1'>
  215. <w:b/>
  216. </xsl:if>
  217. </w:rPr>
  218. </xsl:if>
  219. <w:t>
  220. <xsl:copy-of select='$content'/>
  221. </w:t>
  222. </w:r>
  223. </xsl:template>
  224. <xsl:template name='doc:make-hyperlink'>
  225. <xsl:param name='target'/>
  226. <xsl:param name='content'>
  227. <xsl:apply-templates mode='doc:body'/>
  228. </xsl:param>
  229. <w:hlink w:dest='{$target}'>
  230. <xsl:copy-of select='$content'/>
  231. </w:hlink>
  232. </xsl:template>
  233. <xsl:template name='doc:make-table'>
  234. <xsl:param name='columns'/>
  235. <xsl:param name='content'>
  236. <xsl:apply-templates select='*[not(self::caption|self::doc:caption|self::textobject|self::doc:textobject)]'
  237. mode='doc:body'/>
  238. </xsl:param>
  239. <w:tbl>
  240. <w:tblPr>
  241. <w:tblW w:w="0" w:type="auto"/>
  242. <w:tblInd w:w="108" w:type="dxa"/>
  243. <w:tblLayout w:type="Fixed"/>
  244. </w:tblPr>
  245. <w:tblGrid>
  246. <xsl:copy-of select='$columns'/>
  247. </w:tblGrid>
  248. <xsl:copy-of select='$content'/>
  249. </w:tbl>
  250. </xsl:template>
  251. <xsl:template name='doc:make-column'>
  252. <xsl:param name='width' select='0'/>
  253. <w:gridcol w:w='{$width}'/>
  254. </xsl:template>
  255. <xsl:template name='doc:make-table-row'>
  256. <xsl:param name='content'>
  257. <xsl:apply-templates mode='doc:body'/>
  258. </xsl:param>
  259. <xsl:param name='is-header' select='false()'/>
  260. <w:tr>
  261. <w:trPr>
  262. <xsl:if test='$is-header'>
  263. <w:tblHeader/>
  264. </xsl:if>
  265. </w:trPr>
  266. <xsl:copy-of select='$content'/>
  267. </w:tr>
  268. </xsl:template>
  269. <xsl:template name='doc:make-table-cell'>
  270. <xsl:param name='width' select='0'/>
  271. <xsl:param name='hidden' select='false()'/>
  272. <xsl:param name='rowspan' select='1'/>
  273. <xsl:param name='colspan' select='1'/>
  274. <xsl:param name='content'>
  275. <xsl:apply-templates mode='doc:body'/>
  276. </xsl:param>
  277. <w:tc>
  278. <xsl:if test='$colspan != 1 or
  279. $width != 0'>
  280. <w:tcPr>
  281. <xsl:if test='$colspan != 1 or
  282. $width != 0'>
  283. <w:tcW w:w='{$width}' w:type='dxa'/>
  284. </xsl:if>
  285. <xsl:if test='$hidden'>
  286. <w:vmerge w:val='{$hidden}'/>
  287. </xsl:if>
  288. <xsl:if test='$rowspan != 1'>
  289. <w:vmerge w:val='restart'/>
  290. </xsl:if>
  291. <xsl:if test='$colspan != 1'>
  292. <w:gridspan w:val='{$colspan}'/>
  293. </xsl:if>
  294. </w:tcPr>
  295. </xsl:if>
  296. <xsl:copy-of select='$content'/>
  297. </w:tc>
  298. </xsl:template>
  299. <xsl:template name='doc:make-soft-break'>
  300. <w:br/>
  301. </xsl:template>
  302. <xsl:template name='attributes'>
  303. <xsl:param name='node' select='.'/>
  304. <xsl:if test='$node/@*'>
  305. <aml:annotation aml:id='{count(preceding::*) + 1}' w:type='Word.Comment.Start'/>
  306. <w:r>
  307. <w:rPr>
  308. <w:rStyle w:val='attributes'/>
  309. </w:rPr>
  310. <w:t>
  311. <xsl:text> </xsl:text>
  312. </w:t>
  313. </w:r>
  314. <aml:annotation aml:id='{count(preceding::*) + 1}' w:type='Word.Comment.End'/>
  315. <w:r>
  316. <w:rPr>
  317. <w:rStyle w:val='CommentReference'/>
  318. </w:rPr>
  319. <aml:annotation aml:id='{count(preceding::*) + 1}' aml:author="DocBook" aml:createdate='2004-12-23T00:01:00' w:type='Word.Comment' w:initials='DBK'>
  320. <aml:content>
  321. <w:p>
  322. <w:pPr>
  323. <w:pStyle w:val='CommentText'/>
  324. </w:pPr>
  325. <w:r>
  326. <w:rPr>
  327. <w:rStyle w:val='CommentReference'/>
  328. </w:rPr>
  329. <w:annotationRef/>
  330. </w:r>
  331. <xsl:for-each select='$node/@*'>
  332. <w:r>
  333. <w:rPr>
  334. <w:rStyle w:val='attribute-name'/>
  335. </w:rPr>
  336. <w:t>
  337. <xsl:value-of select='name()'/>
  338. </w:t>
  339. </w:r>
  340. <w:r>
  341. <w:t>=</w:t>
  342. </w:r>
  343. <w:r>
  344. <w:rPr>
  345. <w:rStyle w:val='attribute-value'/>
  346. </w:rPr>
  347. <w:t>
  348. <xsl:value-of select='.'/>
  349. </w:t>
  350. </w:r>
  351. </xsl:for-each>
  352. </w:p>
  353. </aml:content>
  354. </aml:annotation>
  355. </w:r>
  356. </xsl:if>
  357. </xsl:template>
  358. </xsl:stylesheet>