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