htmltoword-1.8.7 0.1.8.rc1 → 0.1.8.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Htmltoword
2
- VERSION = '0.1.8.rc1'
2
+ VERSION = '0.1.8.rc2'
3
3
  end
@@ -15,333 +15,219 @@
15
15
  exclude-result-prefixes="java msxsl ext w o v WX aml w10">
16
16
 
17
17
 
18
- <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
19
-
20
- <xsl:template match="/">
21
- <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
22
- <xsl:apply-templates />
23
- </w:document>
24
- </xsl:template>
25
-
26
- <xsl:template match="head" />
27
-
28
- <xsl:template match="body">
29
- <xsl:comment>
30
- KNOWN BUGS:
31
- div
32
- h2
33
- div
34
- textnode (WONT BE WRAPPED IN A W:P)
35
- div
36
- table
37
- span
38
- text
39
- </xsl:comment>
40
- <w:body>
41
- <xsl:apply-templates/>
42
- <w:sectPr>
43
- <w:pgSz w:w="11906" w:h="16838"/>
44
- <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
45
- <w:cols w:space="708"/>
46
- <w:docGrid w:linePitch="360"/>
47
- </w:sectPr>
48
- </w:body>
49
- </xsl:template>
50
-
51
- <xsl:template match="body/*[not(*)]">
52
- <w:p>
53
- <xsl:call-template name="text-alignment" />
54
- <w:r>
55
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
56
- </w:r>
57
- </w:p>
58
- </xsl:template>
59
-
60
- <xsl:template match="div[not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li)]">
61
- <xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
62
- <w:p>
63
- <xsl:call-template name="text-alignment" />
64
- <xsl:apply-templates />
65
- </w:p>
66
- </xsl:template>
67
-
68
- <xsl:template match="div">
69
- <xsl:apply-templates />
70
- </xsl:template>
71
-
72
- <!-- TODO: make this prettier. Headings shouldn't enter in template from L51 -->
73
- <xsl:template match="body/h1|body/h2|body/h3|body/h4|body/h5|body/h6|h1|h2|h3|h4|h5|h6">
74
- <w:p>
75
- <w:r>
76
- <w:rPr>
77
- <w:rStyle w:val="{name(.)}"/>
78
- </w:rPr>
79
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
80
- </w:r>
81
- </w:p>
82
- </xsl:template>
83
-
84
- <xsl:template match="p">
85
- <w:p>
86
- <xsl:call-template name="text-alignment" />
87
- <xsl:apply-templates />
88
- </w:p>
89
- </xsl:template>
90
-
91
- <xsl:template match="li">
92
- <w:p>
93
- <w:r>
94
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
95
- </w:r>
96
- </w:p>
97
- </xsl:template>
98
-
99
- <xsl:template match="span[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
100
- |a[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
101
- |small[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
102
- |strong[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
103
- |em[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
104
- |i[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
105
- |b[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
106
- <xsl:comment>
107
- In the following situation:
108
-
109
- div
110
- h2
111
- span
112
- textnode
113
- span
114
- textnode
115
- p
116
-
117
- The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the inline elements span|a|small in a p here.
118
- </xsl:comment>
119
- <w:p>
120
- <xsl:apply-templates />
121
- </w:p>
122
- </xsl:template>
123
-
124
- <xsl:template match="text()[not(parent::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
125
- <xsl:comment>
126
- In the following situation:
127
-
128
- div
129
- h2
130
- textnode
131
- p
132
-
133
- The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the textnode in a p here.
134
- </xsl:comment>
135
- <w:p>
136
- <w:r>
137
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
138
- </w:r>
139
- </w:p>
140
- </xsl:template>
141
-
142
- <xsl:template match="span[contains(concat(' ', @class, ' '), ' h ')]">
143
- <xsl:comment>
144
- This template adds MS Word highlighting ability.
145
- </xsl:comment>
146
- <xsl:variable name="color">
147
- <xsl:choose>
148
- <xsl:when test="./@data-style='pink'">magenta</xsl:when>
149
- <xsl:when test="./@data-style='blue'">cyan</xsl:when>
150
- <xsl:when test="./@data-style='orange'">darkYellow</xsl:when>
151
- <xsl:otherwise><xsl:value-of select="./@data-style"/></xsl:otherwise>
152
- </xsl:choose>
153
- </xsl:variable>
154
- <xsl:choose>
155
- <xsl:when test="preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div">
18
+ <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes"/>
19
+
20
+ <xsl:template match="/">
21
+ <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
22
+ xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
23
+ xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office"
24
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
25
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml"
26
+ xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
27
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word"
28
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
29
+ xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
30
+ xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
31
+ xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
32
+ <xsl:apply-templates/>
33
+ </w:document>
34
+ </xsl:template>
35
+
36
+ <xsl:template match="head"/>
37
+
38
+ <xsl:template match="body">
39
+ <w:body>
40
+ <xsl:apply-templates/>
41
+ <w:sectPr>
42
+ <w:pgSz w:w="11906" w:h="16838"/>
43
+ <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
44
+ <w:cols w:space="708"/>
45
+ <w:docGrid w:linePitch="360"/>
46
+ </w:sectPr>
47
+ </w:body>
48
+ </xsl:template>
49
+
50
+ <xsl:template match="body/*[not(*)]">
156
51
  <w:p>
157
- <w:r>
158
- <w:rPr>
159
- <w:highlight w:val="{$color}"/>
160
- </w:rPr>
161
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
162
- </w:r>
52
+ <w:r>
53
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
54
+ </w:r>
163
55
  </w:p>
164
- </xsl:when>
165
- <xsl:otherwise>
166
- <w:r>
167
- <w:rPr>
168
- <w:highlight w:val="{$color}"/>
169
- </w:rPr>
170
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
171
- </w:r>
172
- </xsl:otherwise>
173
- </xsl:choose>
174
- </xsl:template>
175
-
176
- <xsl:template match="div[contains(concat(' ', @class, ' '), ' -page-break ')]">
177
- <w:p>
178
- <w:r>
179
- <w:br w:type="page" />
180
- </w:r>
181
- </w:p>
182
- <xsl:apply-templates />
183
- </xsl:template>
56
+ </xsl:template>
184
57
 
185
- <xsl:template match="details" />
186
-
187
- <xsl:template name="tableborders">
188
- <xsl:variable name="border">
189
- <xsl:choose>
190
- <xsl:when test="contains(concat(' ', @class, ' '), ' table-bordered ')">6</xsl:when>
191
- <xsl:when test="not(@border)">0</xsl:when>
192
- <xsl:otherwise><xsl:value-of select="./@border * 6"/></xsl:otherwise>
193
- </xsl:choose>
194
- </xsl:variable>
195
- <xsl:variable name="bordertype">
196
- <xsl:choose>
197
- <xsl:when test="$border=0">none</xsl:when>
198
- <xsl:otherwise>single</xsl:otherwise>
199
- </xsl:choose>
200
- </xsl:variable>
201
- <w:tblBorders>
202
- <w:top w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
203
- <w:left w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
204
- <w:bottom w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
205
- <w:right w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
206
- <w:insideH w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
207
- <w:insideV w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
208
- </w:tblBorders>
209
- </xsl:template>
210
-
211
- <xsl:template match="table">
212
- <w:tbl>
213
- <w:tblPr>
214
- <w:tblStyle w:val="TableGrid"/>
215
- <w:tblW w:w="0" w:type="auto"/>
216
- <xsl:call-template name="tableborders"/>
217
- <w:tblLook w:val="0600" w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="1" w:noVBand="1"/>
218
- </w:tblPr>
219
- <w:tblGrid>
220
- <w:gridCol w:w="2310"/>
221
- <w:gridCol w:w="2310"/>
222
- </w:tblGrid>
223
- <xsl:apply-templates />
224
- </w:tbl>
225
- </xsl:template>
226
-
227
- <xsl:template match="tbody">
228
- <xsl:apply-templates />
229
- </xsl:template>
230
-
231
- <xsl:template match="thead">
232
- <xsl:choose>
233
- <xsl:when test="count(./tr) = 0">
234
- <w:tr><xsl:apply-templates /></w:tr>
235
- </xsl:when>
236
- <xsl:otherwise>
58
+ <xsl:template match="div">
237
59
  <xsl:apply-templates />
238
- </xsl:otherwise>
239
- </xsl:choose>
240
- </xsl:template>
60
+ </xsl:template>
241
61
 
242
- <xsl:template match="tr">
243
- <xsl:if test="string-length(.) > 0">
244
- <w:tr>
245
- <xsl:apply-templates />
246
- </w:tr>
247
- </xsl:if>
248
- </xsl:template>
62
+ <xsl:template match="h3|h4|h5|h6">
63
+ <w:p>
64
+ <w:r>
65
+ <w:rPr>
66
+ <w:rStyle w:val="{name(.)}"/>
67
+ </w:rPr>
68
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
69
+ </w:r>
70
+ </w:p>
71
+
72
+ <w:pPr>
73
+ <w:jc w:val="left" />
74
+ <w:spacing w:before="10" w:after="0"/>
75
+ <w:ind w:left="0" w:right="0"/>
76
+ <w:tab w:val="start" pos="0"/>
77
+ </w:pPr>
249
78
 
250
- <xsl:template match="th">
251
- <w:tc>
252
- <w:p>
253
- <w:r>
254
- <w:rPr>
255
- <w:b />
256
- </w:rPr>
257
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
258
- </w:r>
259
- </w:p>
260
- </w:tc>
261
- </xsl:template>
79
+ </xsl:template>
80
+ <xsl:template match="h1|h2">
81
+ <w:p>
82
+ <w:r>
83
+ <w:rPr>
84
+ <w:rStyle w:val="{name(.)}"/>
85
+ </w:rPr>
86
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
87
+ </w:r>
88
+ </w:p>
262
89
 
263
- <xsl:template match="td">
264
- <w:tc>
265
- <xsl:call-template name="block">
266
- <xsl:with-param name="current" select="." />
267
- <xsl:with-param name="class" select="@class" />
268
- <xsl:with-param name="style" select="@style" />
269
- </xsl:call-template>
270
- </w:tc>
271
- </xsl:template>
90
+ <w:pPr>
91
+ <w:jc w:val="center" />
92
+ <w:spacing w:before="10" w:after="0"/>
93
+ <w:ind w:left="0" w:right="0"/>
94
+ <w:tab w:val="start" pos="0"/>
95
+ </w:pPr>
96
+
97
+ </xsl:template>
98
+
99
+ <xsl:template match="p">
100
+ <w:pPr>
101
+ <w:pStyle w:val="NormalWeb"/>
102
+ <w:jc w:val="left" />
103
+ <w:spacing w:before="0" w:after="0"/>
104
+ <w:ind w:left="0" w:right="0"/>
105
+ <w:tab w:val="start" pos="0"/>
106
+ </w:pPr>
107
+ <w:p>
108
+ <xsl:apply-templates/>
109
+ </w:p>
110
+ </xsl:template>
272
111
 
273
- <xsl:template name="block">
274
- <xsl:param name="current" />
275
- <xsl:param name="class" />
276
- <xsl:param name="style" />
277
- <xsl:if test="count($current/*|$current/text()) = 0">
278
- <w:p/>
279
- </xsl:if>
280
- <xsl:for-each select="$current/*|$current/text()">
281
- <xsl:choose>
282
- <xsl:when test="name(.) = 'table'">
283
- <xsl:apply-templates select="." />
284
- <w:p/>
285
- </xsl:when>
286
- <xsl:when test="contains('|p|h1|h2|h3|h4|h5|h6|ul|ol|', concat('|', name(.), '|'))">
287
- <xsl:apply-templates select="." />
288
- </xsl:when>
289
- <xsl:when test="descendant::table|descendant::p|descendant::h1|descendant::h2|descendant::h3|descendant::h4|descendant::h5|descendant::h6|descendant::li">
290
- <xsl:call-template name="block">
291
- <xsl:with-param name="current" select="."/>
292
- </xsl:call-template>
293
- </xsl:when>
294
- <xsl:otherwise>
295
- <w:p>
296
- <xsl:call-template name="text-alignment">
297
- <xsl:with-param name="class" select="$class" />
298
- <xsl:with-param name="style" select="$style" />
112
+ <xsl:template match="li">
113
+ <w:p>
114
+ <w:r>
115
+ <w:spacing w:before="0" w:after="0"/>
116
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
117
+ </w:r>
118
+ </w:p>
119
+ </xsl:template>
120
+
121
+ <xsl:template name="tableborders">
122
+ <xsl:variable name="border">
123
+ <xsl:choose>
124
+ <xsl:when test="contains(concat(' ', @class, ' '), ' table-bordered ')">6</xsl:when>
125
+ <xsl:when test="not(@border)">0</xsl:when>
126
+ <xsl:otherwise>
127
+ <xsl:value-of select="./@border * 6"/>
128
+ </xsl:otherwise>
129
+ </xsl:choose>
130
+ </xsl:variable>
131
+ <xsl:variable name="bordertype">
132
+ <xsl:choose>
133
+ <xsl:when test="$border=0">none</xsl:when>
134
+ <xsl:otherwise>single</xsl:otherwise>
135
+ </xsl:choose>
136
+ </xsl:variable>
137
+ <w:tblBorders>
138
+ <w:top w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
139
+ <w:left w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
140
+ <w:bottom w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
141
+ <w:right w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
142
+ <w:insideH w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
143
+ <w:insideV w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
144
+ </w:tblBorders>
145
+ </xsl:template>
146
+
147
+ <xsl:template match="table">
148
+ <w:tbl>
149
+ <w:tblPr>
150
+ <w:tblStyle w:val="TableGrid"/>
151
+ <w:tblW w:type="dxa" w:w="100%"/>
152
+ <xsl:call-template name="tableborders"/>
153
+ <w:tblLook w:val="0600" w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="1" w:noVBand="1"/>
154
+ </w:tblPr>
155
+ <w:tblGrid>
156
+ <w:gridCol w:w="2310"/>
157
+ <w:gridCol w:w="2310"/>
158
+ </w:tblGrid>
159
+ <xsl:apply-templates/>
160
+ </w:tbl>
161
+ </xsl:template>
162
+
163
+ <xsl:template match="tr">
164
+ <xsl:if test="string-length(.) > 0">
165
+ <w:tr>
166
+ <xsl:apply-templates/>
167
+ </w:tr>
168
+ </xsl:if>
169
+ </xsl:template>
170
+
171
+ <xsl:template match="td">
172
+ <w:tc>
173
+ <xsl:call-template name="block">
174
+ <xsl:with-param name="current" select="."/>
175
+ <xsl:with-param name="class" select="@class"/>
176
+ <xsl:with-param name="style" select="@style"/>
299
177
  </xsl:call-template>
300
- <xsl:apply-templates select="." />
301
- </w:p>
302
- </xsl:otherwise>
303
- </xsl:choose>
304
- </xsl:for-each>
305
- </xsl:template>
306
-
307
- <xsl:template match="text()">
308
- <xsl:if test="string-length(.) > 0">
309
- <w:r>
310
- <xsl:if test="ancestor::i or ancestor::em">
311
- <w:rPr>
312
- <w:i />
313
- </w:rPr>
178
+ </w:tc>
179
+ </xsl:template>
180
+
181
+ <xsl:template name="block">
182
+ <xsl:param name="current"/>
183
+ <xsl:param name="class"/>
184
+ <xsl:param name="style"/>
185
+ <xsl:if test="count($current/*|$current/text()) = 0">
186
+ <w:p/>
314
187
  </xsl:if>
315
- <xsl:if test="ancestor::b or ancestor::strong">
316
- <w:rPr>
317
- <w:b />
318
- </w:rPr>
188
+ <xsl:for-each select="$current/*|$current/text()">
189
+ <xsl:choose>
190
+ <xsl:when test="name(.) = 'table'">
191
+ <xsl:apply-templates select="."/>
192
+ <w:p/>
193
+ </xsl:when>
194
+ <xsl:when test="contains('|p|h1|h2|h3|h4|h5|h6|ul|ol|', concat('|', name(.), '|'))">
195
+ <xsl:apply-templates select="."/>
196
+ </xsl:when>
197
+ <xsl:when test="descendant::table|descendant::p|descendant::h1|descendant::h2|descendant::h3|descendant::h4|descendant::h5|descendant::h6|descendant::li">
198
+ <xsl:call-template name="block">
199
+ <xsl:with-param name="current" select="."/>
200
+ </xsl:call-template>
201
+ </xsl:when>
202
+ <xsl:otherwise>
203
+ <w:p>
204
+ <xsl:apply-templates select="."/>
205
+ </w:p>
206
+ </xsl:otherwise>
207
+ </xsl:choose>
208
+ </xsl:for-each>
209
+ </xsl:template>
210
+
211
+ <xsl:template match="text()">
212
+ <xsl:if test="string-length(.) > 0">
213
+ <w:r>
214
+ <xsl:if test="ancestor::i or ancestor::em">
215
+ <w:rPr>
216
+ <w:i/>
217
+ </w:rPr>
218
+ </xsl:if>
219
+ <xsl:if test="ancestor::b or ancestor::strong">
220
+ <w:rPr>
221
+ <w:b/>
222
+ </w:rPr>
223
+ </xsl:if>
224
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
225
+ </w:r>
319
226
  </xsl:if>
320
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
321
- </w:r>
322
- </xsl:if>
323
- </xsl:template>
227
+ </xsl:template>
324
228
 
325
- <xsl:template match="*">
326
- <xsl:apply-templates/>
327
- </xsl:template>
229
+ <xsl:template match="*">
230
+ <xsl:apply-templates/>
231
+ </xsl:template>
328
232
 
329
- <xsl:template name="text-alignment">
330
- <xsl:param name="class" select="@class" />
331
- <xsl:param name="style" select="@style" />
332
- <xsl:variable name="alignment">
333
- <xsl:choose>
334
- <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
335
- <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
336
- <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
337
- <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
338
- <xsl:otherwise></xsl:otherwise>
339
- </xsl:choose>
340
- </xsl:variable>
341
- <xsl:if test="string-length(normalize-space($alignment)) > 0">
342
- <w:pPr>
343
- <w:jc w:val="{$alignment}"/>
344
- </w:pPr>
345
- </xsl:if>
346
- </xsl:template>
347
233
  </xsl:stylesheet>
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmltoword-1.8.7
3
3
  version: !ruby/object:Gem::Version
4
- hash: -2720420102
4
+ hash: -1780902772
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 8
10
10
  - rc
11
- - 1
12
- version: 0.1.8.rc1
11
+ - 2
12
+ version: 0.1.8.rc2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Nicholas Frandsen, Cristina Matonte