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