]> git.stg.codes - stg.git/blob - doc/xslt/roundtrip/dbk2wordml.xsl
Ticket 37. The 'ALTER TABLE tariffs' query added for the 'change_policy'
[stg.git] / doc / xslt / 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 7701 2008-02-22 06:07:31Z balls $
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'/>
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:apply-templates select='$authors[1]' mode='doc:docprop.author'/>
65             </xsl:when>
66             <xsl:otherwise>Unknown</xsl:otherwise>
67           </xsl:choose>
68         </o:Author>
69         <o:LastAuthor>
70           <xsl:choose>
71             <xsl:when test='$info/revhistory/revision[1]/*[self::author|self::authorinitials]'>
72               <xsl:apply-templates select='$info/revhistory/revision[1]/*[self::author|self::authorinitials]' mode='doc:docprop.author'/>
73             </xsl:when>
74             <xsl:when test='$authors'>
75               <xsl:apply-templates select='$authors[1]' mode='doc:docprop.author'/>
76             </xsl:when>
77             <xsl:otherwise>Unknown</xsl:otherwise>
78           </xsl:choose>
79         </o:LastAuthor>
80         <o:Revision>1</o:Revision>
81         <o:TotalTime></o:TotalTime>
82
83         <!-- dummy values -->
84         <o:Created>2004-01-01T07:07:00Z</o:Created>
85         <o:LastSaved>2004-01-01T08:08:00Z</o:LastSaved>
86
87         <o:Pages>1</o:Pages>
88         <o:Words>1</o:Words>
89         <o:Characters>1</o:Characters>
90
91         <!-- could derive this from author -->
92         <o:Company>DocBook</o:Company>
93
94         <o:Lines>1</o:Lines>
95         <o:Paragraphs>1</o:Paragraphs>
96         <o:CharactersWithSpaces>1</o:CharactersWithSpaces>
97         <o:Version>11.6113</o:Version>
98       </o:DocumentProperties>
99
100       <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'/>
101
102       <w:docPr>
103         <w:view w:val="print"/>
104         <w:zoom w:percent="100"/>
105         <w:doNotEmbedSystemFonts/>
106         <w:attachedTemplate w:val=""/>
107         <w:documentProtection w:formatting='on' w:enforcement='on'
108           w:unprotectPassword='CAA7FF77'/>
109         <w:defaultTabStop w:val="720"/>
110         <w:autoHyphenation/>
111         <w:hyphenationZone w:val="357"/>
112         <w:doNotHyphenateCaps/>
113         <w:evenAndOddHeaders/>
114         <w:characterSpacingControl w:val="DontCompress"/>
115         <w:optimizeForBrowser/>
116         <w:validateAgainstSchema/>
117         <w:saveInvalidXML w:val="off"/>
118         <w:ignoreMixedContent w:val="off"/>
119         <w:alwaysShowPlaceholderText w:val="off"/>
120         <w:footnotePr>
121           <w:footnote w:type="separator">
122             <w:p>
123               <w:r>
124                 <w:separator/>
125               </w:r>
126             </w:p>
127           </w:footnote>
128           <w:footnote w:type="continuation-separator">
129             <w:p>
130               <w:r>
131                 <w:continuationSeparator/>
132               </w:r>
133             </w:p>
134           </w:footnote>
135         </w:footnotePr>
136         <w:endnotePr>
137           <w:endnote w:type="separator">
138             <w:p>
139               <w:r>
140                 <w:separator/>
141               </w:r>
142             </w:p>
143           </w:endnote>
144           <w:endnote w:type="continuation-separator">
145             <w:p>
146               <w:r>
147                 <w:continuationSeparator/>
148               </w:r>
149             </w:p>
150           </w:endnote>
151         </w:endnotePr>
152         <w:compat>
153           <w:breakWrappedTables/>
154           <w:snapToGridInCell/>
155           <w:wrapTextWithPunct/>
156           <w:useAsianBreakRules/>
157           <w:useWord2002TableStyleRules/>
158         </w:compat>
159         <w:docVars>
160         </w:docVars>
161       </w:docPr>
162
163       <xsl:apply-templates select='$doc/*' mode='doc:toplevel'/>
164
165     </w:wordDocument>
166   </xsl:template>
167
168   <xsl:template name='doc:make-body'>
169     <xsl:param name='content'>
170       <xsl:apply-templates mode='doc:body'/>
171     </xsl:param>
172
173     <w:body>
174       <wx:sect>
175         <wx:sub-section>
176           <xsl:copy-of select='$content'/>
177         </wx:sub-section>
178       </wx:sect>
179     </w:body>
180   </xsl:template>
181
182   <xsl:template name='doc:make-subsection'>
183     <xsl:param name='content'>
184       <xsl:apply-templates mode='doc:body'/>
185     </xsl:param>
186
187     <wx:sub-section>
188       <xsl:copy-of select='$content'/>
189     </wx:sub-section>
190   </xsl:template>
191
192   <xsl:template name='doc:make-paragraph'>
193     <xsl:param name='style' select='"unknown"'/>
194     <xsl:param name='content'>
195       <xsl:apply-templates mode='doc:body'/>
196     </xsl:param>
197     <xsl:param name='outline.level' select='0'/>
198     <xsl:param name='attributes.node' select='.'/>
199
200     <w:p>
201       <xsl:if test='$style != "" or
202                     $outline.level != 0'>
203         <w:pPr>
204           <xsl:if test='$style != ""'>
205             <w:pStyle w:val='{$style}'/>
206           </xsl:if>
207
208           <xsl:if test='$outline.level != 0'>
209             <w:outlineLvl w:val='{$outline.level}'/>
210           </xsl:if>
211         </w:pPr>
212       </xsl:if>
213
214       <xsl:call-template name='attributes'>
215         <xsl:with-param name='node' select='$attributes.node'/>
216       </xsl:call-template>
217
218       <xsl:copy-of select='$content'/>
219     </w:p>
220   </xsl:template>
221
222   <xsl:template name='doc:make-phrase'>
223     <xsl:param name='style' select='""'/>
224     <xsl:param name='italic' select='0'/>
225     <xsl:param name='bold' select='0'/>
226     <xsl:param name='content'>
227       <xsl:apply-templates mode='doc:phrase'/>
228     </xsl:param>
229
230     <w:r>
231       <xsl:if test='$style != "" or
232                     $bold = 1 or
233                     $italic = 1'>
234         <w:rPr>
235           <xsl:if test='$style != ""'>
236             <w:rStyle w:val='{$style}'/>
237           </xsl:if>
238           <xsl:if test='$italic = 1'>
239             <w:i/>
240           </xsl:if>
241           <xsl:if test='$bold = 1'>
242             <w:b/>
243           </xsl:if>
244         </w:rPr>
245       </xsl:if>
246
247       <w:t>
248         <xsl:copy-of select='$content'/>
249       </w:t>
250     </w:r>
251   </xsl:template>
252
253   <xsl:template name='doc:make-hyperlink'>
254     <xsl:param name='target'/>
255     <xsl:param name='content'>
256       <xsl:apply-templates mode='doc:body'/>
257     </xsl:param>
258
259     <w:hlink w:dest='{$target}'>
260       <xsl:copy-of select='$content'/>
261     </w:hlink>
262   </xsl:template>
263
264   <xsl:template name='doc:make-table'>
265     <xsl:param name='columns'/>
266     <xsl:param name='content'>
267       <xsl:apply-templates select='*[not(self::caption|self::doc:caption|self::textobject|self::doc:textobject)]'
268         mode='doc:body'/>
269     </xsl:param>
270
271     <w:tbl>
272       <w:tblPr>
273         <w:tblW w:w="0" w:type="auto"/>
274         <w:tblInd w:w="108" w:type="dxa"/>
275         <w:tblLayout w:type="Fixed"/>
276       </w:tblPr>
277       <w:tblGrid>
278         <xsl:copy-of select='$columns'/>
279       </w:tblGrid>
280       <xsl:copy-of select='$content'/>
281     </w:tbl>
282   </xsl:template>
283
284   <xsl:template name='doc:make-column'>
285     <xsl:param name='width' select='0'/>
286
287     <w:gridcol w:w='{$width}'/>
288   </xsl:template>
289
290   <xsl:template name='doc:make-table-row'>
291     <xsl:param name='content'>
292       <xsl:apply-templates mode='doc:body'/>
293     </xsl:param>
294     <xsl:param name='is-header' select='false()'/>
295
296     <w:tr>
297       <w:trPr>
298         <xsl:if test='$is-header'>
299           <w:tblHeader/>
300         </xsl:if>
301       </w:trPr>
302       <xsl:copy-of select='$content'/>
303     </w:tr>
304   </xsl:template>
305
306   <xsl:template name='doc:make-table-cell'>
307     <xsl:param name='width' select='0'/>
308     <xsl:param name='hidden' select='false()'/>
309     <xsl:param name='rowspan' select='1'/>
310     <xsl:param name='colspan' select='1'/>
311     <xsl:param name='content'>
312       <xsl:apply-templates mode='doc:body'/>
313     </xsl:param>
314
315     <w:tc>
316       <xsl:if test='$colspan != 1 or
317                     $width != 0'>
318         <w:tcPr>
319           <xsl:if test='$colspan != 1 or
320                         $width != 0'>
321             <w:tcW w:w='{$width}' w:type='dxa'/>
322           </xsl:if>
323           <xsl:if test='$hidden'>
324             <w:vmerge w:val='{$hidden}'/>
325           </xsl:if>
326           <xsl:if test='$rowspan != 1'>          
327             <w:vmerge w:val='restart'/>
328           </xsl:if>
329           <xsl:if test='$colspan != 1'>
330             <w:gridspan w:val='{$colspan}'/>
331           </xsl:if>
332         </w:tcPr>
333       </xsl:if>
334
335       <xsl:copy-of select='$content'/>
336     </w:tc>
337   </xsl:template>
338
339   <xsl:template name='doc:make-soft-break'>
340     <w:br/>
341   </xsl:template>
342
343   <xsl:template name='attributes'>
344     <xsl:param name='node' select='.'/>
345
346     <xsl:if test='$node/@*'>
347       <aml:annotation aml:id='{count(preceding::*) + 1}' w:type='Word.Comment.Start'/>
348       <w:r>
349         <w:rPr>
350           <w:rStyle w:val='attributes'/>
351         </w:rPr>
352         <w:t>
353           <xsl:text> </xsl:text>
354         </w:t>
355       </w:r>
356       <aml:annotation aml:id='{count(preceding::*) + 1}' w:type='Word.Comment.End'/>
357       <w:r>
358         <w:rPr>
359           <w:rStyle w:val='CommentReference'/>
360         </w:rPr>
361         <aml:annotation aml:id='{count(preceding::*) + 1}' aml:author="DocBook" aml:createdate='2004-12-23T00:01:00' w:type='Word.Comment' w:initials='DBK'>
362           <aml:content>
363             <w:p>
364               <w:pPr>
365                 <w:pStyle w:val='CommentText'/>
366               </w:pPr>
367               <w:r>
368                 <w:rPr>
369                   <w:rStyle w:val='CommentReference'/>
370                 </w:rPr>
371                 <w:annotationRef/>
372               </w:r>
373               <xsl:for-each select='$node/@*'>
374                 <w:r>
375                   <w:rPr>
376                     <w:rStyle w:val='attribute-name'/>
377                   </w:rPr>
378                   <w:t>
379                     <xsl:value-of select='name()'/>
380                   </w:t>
381                 </w:r>
382                 <w:r>
383                   <w:t>=</w:t>
384                 </w:r>
385                 <w:r>
386                   <w:rPr>
387                     <w:rStyle w:val='attribute-value'/>
388                   </w:rPr>
389                   <w:t>
390                     <xsl:value-of select='.'/>
391                   </w:t>
392                 </w:r>
393               </xsl:for-each>
394             </w:p>
395           </aml:content>
396         </aml:annotation>
397       </w:r>
398     </xsl:if>
399   </xsl:template>
400
401 </xsl:stylesheet>