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