Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / docx / from / tables / tables.xsl @ 187

History | View | Annotate | Download (26.9 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
3
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
                xmlns:prop="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
5
                xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
6
                xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
7
                xmlns:dc="http://purl.org/dc/elements/1.1/"
8
                xmlns:dcterms="http://purl.org/dc/terms/"
9
                xmlns:dcmitype="http://purl.org/dc/dcmitype/"
10
                xmlns:iso="http://www.iso.org/ns/1.0"
11
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
12
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
13
                xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
14
                xmlns:mv="urn:schemas-microsoft-com:mac:vml"
15
                xmlns:o="urn:schemas-microsoft-com:office:office"
16
                xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
17
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
18
                xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships"
19
                xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html"
20
                xmlns:tei="http://www.tei-c.org/ns/1.0"
21
                xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
22
                xmlns:v="urn:schemas-microsoft-com:vml"
23
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
24
                xmlns:w10="urn:schemas-microsoft-com:office:word"
25
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
26
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
27
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
28
                xmlns:html="http://www.w3.org/1999/xhtml"                
29
                
30
                xmlns="http://www.tei-c.org/ns/1.0"
31
                version="2.0"
32
                exclude-result-prefixes="a cp dc dcterms dcmitype prop     iso m mml mo mv o pic r rel     tbx tei teidocx v xs ve w10 w wne wp">
33
    
34
    
35
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
36
      <desc>
37
         <p> TEI stylesheet for converting Word docx files to TEI </p>
38
         <p>This software is dual-licensed:
39

    
40
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
41
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
42

    
43
2. http://www.opensource.org/licenses/BSD-2-Clause
44
		
45
All rights reserved.
46

    
47
Redistribution and use in source and binary forms, with or without
48
modification, are permitted provided that the following conditions are
49
met:
50

    
51
* Redistributions of source code must retain the above copyright
52
notice, this list of conditions and the following disclaimer.
53

    
54
* Redistributions in binary form must reproduce the above copyright
55
notice, this list of conditions and the following disclaimer in the
56
documentation and/or other materials provided with the distribution.
57

    
58
This software is provided by the copyright holders and contributors
59
"as is" and any express or implied warranties, including, but not
60
limited to, the implied warranties of merchantability and fitness for
61
a particular purpose are disclaimed. In no event shall the copyright
62
holder or contributors be liable for any direct, indirect, incidental,
63
special, exemplary, or consequential damages (including, but not
64
limited to, procurement of substitute goods or services; loss of use,
65
data, or profits; or business interruption) however caused and on any
66
theory of liability, whether in contract, strict liability, or tort
67
(including negligence or otherwise) arising in any way out of the use
68
of this software, even if advised of the possibility of such damage.
69
</p>
70
         <p>Author: See AUTHORS</p>
71
         <p>Id: $Id: tables.xsl 9719 2011-11-09 18:18:03Z rahtz $</p>
72
         <p>Copyright: 2008, TEI Consortium</p>
73
      </desc>
74
   </doc>
75

    
76
   <xsl:template name="getTableBorderStyles">
77
     <xsl:param name="tblBorders"/>
78
     <xsl:if test="$tblBorders//w:left[@w:sz!='']">
79
       <xsl:text>border-left: </xsl:text><xsl:value-of select="$tblBorders//w:left[1]/@w:sz"/><xsl:text>; </xsl:text>
80
     </xsl:if>
81
     <xsl:if test="$tblBorders//w:left[@w:val='nil']">
82
       <xsl:text>border-left: 0; </xsl:text>
83
     </xsl:if>
84
     <xsl:if test="$tblBorders//w:bottom[@w:sz!='']">
85
       <xsl:text>border-bottom: </xsl:text><xsl:value-of select="$tblBorders//w:bottom[1]/@w:sz"/><xsl:text>; </xsl:text>
86
     </xsl:if>
87
     <xsl:if test="$tblBorders//w:bottom[@w:val='nil']">
88
       <xsl:text>border-bottom: 0; </xsl:text>
89
     </xsl:if>
90
     <xsl:if test="$tblBorders//w:right[@w:sz!='']">
91
       <xsl:text>border-right: </xsl:text><xsl:value-of select="$tblBorders//w:right[1]/@w:sz"/><xsl:text>; </xsl:text>
92
     </xsl:if>
93
     <xsl:if test="$tblBorders//w:right[@w:val='nil']">
94
       <xsl:text>border-right: 0; </xsl:text>
95
     </xsl:if>
96
     <xsl:if test="$tblBorders//w:top[@w:sz!='']">
97
       <xsl:text>border-top: </xsl:text><xsl:value-of select="$tblBorders//w:top[1]/@w:sz"/><xsl:text>; </xsl:text>
98
     </xsl:if>
99
     <xsl:if test="$tblBorders//w:top[@w:val='nil']">
100
       <xsl:text>border-top: 0; </xsl:text>
101
     </xsl:if>
102
   </xsl:template>
103
    
104
    	<xsl:template match="w:tbl" mode="paragraph">
105
	     <xsl:choose>
106
	        <xsl:when test="$tableMethod='word'">
107
	           <xsl:copy>
108
		             <xsl:copy-of select="@*"/>
109
		             <xsl:apply-templates/>
110
	           </xsl:copy>
111
	        </xsl:when>
112
	        <xsl:when test="$tableMethod='cals'">
113
	      <!-- preprocess the table to expand colspans, add row numbers, and
114
		   simplify vertical merge info -->
115

    
116
	      <xsl:variable name="TABLE">
117

    
118
	      <xsl:variable name="tableBorders">
119
		<xsl:choose>
120
		  <xsl:when test="w:tblPr/w:tblBorders/w:top[@w:val='single']">
121
		    <xsl:copy-of select="w:tblPr/w:tblBorders/w:top"/>
122
		  </xsl:when>
123
		  <xsl:when test=".//w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:top[@w:val='single']">
124
		    <xsl:copy-of select=".//w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:top"/>
125
		  </xsl:when>
126
		</xsl:choose>
127
		<xsl:choose>
128
		  <xsl:when test="w:tblPr/w:tblBorders/w:left[@w:val='single']">
129
		    <xsl:copy-of select="w:tblPr/w:tblBorders/w:left"/>
130
		  </xsl:when>
131
		  <xsl:when test=".//w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:left[@w:val='single']">
132
		    <xsl:copy-of select=".//w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:left"/>
133
		  </xsl:when>
134
		</xsl:choose>
135
		<xsl:choose>
136
		  <xsl:when test="w:tblPr/w:tblBorders/w:bottom[@w:val='single']">
137
		    <xsl:copy-of select="w:tblPr/w:tblBorders/w:bottom"/>
138
		  </xsl:when>
139
		  <xsl:when test=".//w:tr[last()]/w:tc[last()]/w:tcPr/w:tcBorders/w:bottom[@w:val='single']">
140
		    <xsl:copy-of select=".//w:tr[last()]/w:tc[last()]/w:tcPr/w:tcBorders/w:bottom"/>
141
		  </xsl:when>
142
		</xsl:choose>
143
		<xsl:choose>
144
		  <xsl:when test="w:tblPr/w:tblBorders/w:right[@w:val='single']">
145
		    <xsl:copy-of select="w:tblPr/w:tblBorders/w:right"/>
146
		  </xsl:when>
147
		  <xsl:when test=".//w:tr[last()]/w:tc[last()]/w:tcPr/w:tcBorders/w:right[@w:val='single']">
148
		    <xsl:copy-of select=".//w:tr[last()]/w:tc[last()]/w:tcPr/w:tcBorders/w:right"/>
149
		  </xsl:when>
150
		</xsl:choose>		
151
	      </xsl:variable>
152
	      <xsl:variable name="tableBorderStyles">
153
		<xsl:call-template name="getTableBorderStyles">
154
		  <xsl:with-param name="tblBorders" select="$tableBorders"/>
155
		</xsl:call-template>
156
	      </xsl:variable>
157
		             <table xmlns="http://www.oasis-open.org/specs/tm9901">
158
			       <xsl:if test="normalize-space($tableBorderStyles)!=''">
159
				 <xsl:attribute name="iso:style">
160
				   <xsl:value-of select="normalize-space($tableBorderStyles)"/>
161
				 </xsl:attribute>
162
			       </xsl:if>
163
			       <xsl:attribute name="frame">
164
		                   <xsl:choose>
165
		      <!-- lets face it, most tables do have
166
			   borders, especially in ISO; but not in footers! -->
167
		      <xsl:when test="not(w:tblPr/w:tblBorders) and
168
				      parent::w:ftr">
169
			                        <xsl:text>none</xsl:text>
170
		                      </xsl:when>
171
		                      <xsl:when test="not($tableBorders)">
172
					<!-- if really no info on borders, default 
173
					     to all (? is this really what we want?) -->
174
					<xsl:text>all</xsl:text>
175
		                      </xsl:when>
176
		                      <xsl:otherwise>
177
					<xsl:for-each select="$tableBorders">
178
					  <xsl:choose>
179
					    <xsl:when test="    w:top/@w:val='single'
180
							    and w:bottom/@w:val='single'
181
							    and w:right/@w:val='single'        
182
							    and w:left/@w:val='single'">all</xsl:when>
183
					    <xsl:when test="    w:top/@w:val='single' 
184
							    and w:bottom/@w:val='single'
185
							    and not(w:right/@w:val='single') 
186
							    and not(w:left/@w:val='single')">topbot</xsl:when>
187
					    <xsl:when test="    w:top/@w:val='single' 
188
							    and not(w:bottom/@w:val='single') 
189
							    and not(w:right/@w:val='single') 
190
							    and not(w:left/@w:val='single')">top</xsl:when>
191
					    <xsl:when test="    not(w:top/@w:val='single') 
192
							    and w:bottom/@w:val='single' 
193
							    and not(w:right/@w:val='single') 
194
							    and not(w:left/@w:val='single')">bottom</xsl:when>
195
					    <xsl:when test="    not(w:top/@w:val='single') 
196
							    and not(w:bottom/@w:val='single') 
197
							    and w:right/@w:val='single' 
198
							    and w:left/@w:val='single'">sides</xsl:when>
199
					    <xsl:otherwise>
200
					      <!-- start guessing -->
201
					      <xsl:variable name="sideBorders">
202
						<xsl:choose>
203
						  <xsl:when test="w:left/@w:val='single' 
204
								  or w:right/@w:val='single'
205
								  or ../../w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:left[@w:val='single']
206
								  or ../../w:tr[last()]/w:tc[last()]/w:tcPr/w:tcBorders/w:right[@w:val='single']">true</xsl:when> 
207
						  <xsl:otherwise>false</xsl:otherwise>
208
						</xsl:choose>
209
					      </xsl:variable>
210
					      <xsl:choose>
211
						<xsl:when test="$sideBorders='true'
212
								and(w:bottom/@w:val='single' or w:top/@w:val='single')">all</xsl:when>
213
						<xsl:otherwise>
214
						  <xsl:text>none</xsl:text>
215
						</xsl:otherwise>
216
					      </xsl:choose>
217
					    </xsl:otherwise>
218
					  </xsl:choose>
219
					</xsl:for-each>
220
		                      </xsl:otherwise>
221
		                   </xsl:choose>
222
		                </xsl:attribute>
223
		                <xsl:attribute name="colsep">
224
		                   <xsl:choose>
225
		                      <xsl:when test="w:tblPr/w:tblBorders/w:insideV/@w:val='single'">1</xsl:when>
226
		                      <xsl:otherwise>0</xsl:otherwise>
227
		                   </xsl:choose>
228
		                </xsl:attribute>
229
		                <xsl:attribute name="rowsep">
230
		                   <xsl:choose>
231
		                      <xsl:when test="w:tblPr/w:tblBorders/w:insideH/@w:val='single'">1</xsl:when>
232
		                      <xsl:otherwise>0</xsl:otherwise>
233
		                   </xsl:choose>
234
		                </xsl:attribute>
235
		                <xsl:call-template name="cals-table-header"/>
236
		                <tgroup>
237
		                   <xsl:for-each select="w:tblGrid/w:gridCol">
238
		                      <colspec colnum="{position()}" colname="c{position()}">
239
			                        <xsl:attribute name="colwidth" select="concat(number(@w:w) div 20,'pt')"/>
240
		                      </colspec>
241
		                   </xsl:for-each>
242
		                   <tbody>
243
		                      <xsl:for-each select="w:tr">
244
			                        <xsl:copy>
245
			                           <xsl:variable name="ROWPOS">
246
			                              <xsl:number/>
247
			                           </xsl:variable>
248
			                           <xsl:for-each select="w:tc">
249
						     <xsl:variable name="cellBorderStyles">
250
						       <xsl:choose>
251
							 <xsl:when test="w:tcBorders">
252
							   <xsl:call-template name="getTableBorderStyles">
253
							     <xsl:with-param name="tblBorders" select="w:tcBorders"/>
254
							   </xsl:call-template>
255
							 </xsl:when>
256
							 <xsl:when test="w:tcPr/w:tcBorders">
257
							   <xsl:call-template name="getTableBorderStyles">
258
							     <xsl:with-param name="tblBorders" select="w:tcPr/w:tcBorders"/>
259
							   </xsl:call-template>
260
							 </xsl:when>
261
						       </xsl:choose>
262
						     </xsl:variable>
263
			                              <xsl:variable name="VMERGE">
264
			                                 <xsl:choose>
265
				                                   <xsl:when test="w:tcPr/w:vMerge/@w:val='restart'">
266
				                                      <xsl:text>start</xsl:text>
267
				                                   </xsl:when>
268
				                                   <xsl:when test="w:tcPr[not(w:vMerge)]">
269
				                                      <xsl:text>start</xsl:text>
270
				                                   </xsl:when>
271
				                                   <xsl:otherwise>
272
				                                      <xsl:text>continue</xsl:text>
273
				                                   </xsl:otherwise>
274
			                                 </xsl:choose>
275
			                              </xsl:variable>
276
			                              <xsl:variable name="innards">
277
			                                 <xsl:copy-of select="w:tcPr"/>
278
			                              </xsl:variable>
279
			                              <xsl:copy>
280
			                                 <xsl:variable
281
							     name="N"
282
							     select="position()"/>
283
							 <xsl:if test="normalize-space($cellBorderStyles)!=''">
284
							   <xsl:attribute name="iso:style">
285
							     <xsl:value-of select="normalize-space($cellBorderStyles)"/>
286
							   </xsl:attribute>
287
							 </xsl:if>
288
			                                 <xsl:attribute name="rowsep">
289
				                                   <xsl:choose>
290
				                                      <xsl:when test="w:tcPr/w:tcBorders/w:bottom[@w:sz=0 or @w:val='nil']">
291
				                                         <xsl:text>0</xsl:text>
292
				                                      </xsl:when>
293
				                                      <xsl:when test="w:tcPr/w:tcBorders/w:bottom[@w:sz&gt;0]">
294
				                                         <xsl:text>1</xsl:text>
295
				                                      </xsl:when>
296
				                                      <xsl:when test="parent::w:tr/following-sibling::w:tr[1]/w:tc[$N]/w:tcPr/w:tcBorders/w:top[@w:sz&gt;0]">
297
				                                         <xsl:text>1</xsl:text>
298
				                                      </xsl:when>
299
				                                      <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideH[@w:sz=0          or @w:val='nil']">
300
				                                         <xsl:text>0</xsl:text>
301
				                                      </xsl:when>
302
				                                      <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideH">
303
				                                         <xsl:text>1</xsl:text>
304
				                                      </xsl:when>
305
				                                      <xsl:when test="not(parent::w:tr/following-sibling::w:tr)          and not(ancestor::w:ftr)">
306
				                                         <xsl:text>1</xsl:text>
307
				                                      </xsl:when>
308
				                                      <xsl:otherwise>
309
				                                         <xsl:text>0</xsl:text>
310
				                                      </xsl:otherwise>
311
				                                   </xsl:choose>
312
			                                 </xsl:attribute>
313
			                                 <xsl:attribute name="colsep">
314
				                                   <xsl:choose>
315
				                                      <xsl:when test="following-sibling::w:tc[1]/w:tcPr/w:tcBorders/w:left[@w:sz&gt;0]">
316
				                                         <xsl:text>1</xsl:text>
317
				                                      </xsl:when>
318
				                                      <xsl:when test="w:tcPr/w:tcBorders/w:right[@w:sz=0 or @w:val='nil']">
319
				                                         <xsl:text>0</xsl:text>
320
				                                      </xsl:when>
321
				                                      <xsl:when test="w:tcPr/w:tcBorders/w:right[@w:sz&gt;0]">
322
				                                         <xsl:text>1</xsl:text>
323
				                                      </xsl:when>
324
				                                      <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideV[@w:sz=0          or @w:val='nil']">
325
				                                         <xsl:text>0</xsl:text>
326
				                                      </xsl:when>
327
				                                      <xsl:when test="not(ancestor::w:tbl/w:tblPr/w:tblBorders)          and ancestor::w:ftr">
328
				                                         <xsl:text>0</xsl:text>
329
				                                      </xsl:when>
330
				                                      <xsl:otherwise>
331
				                                         <xsl:text>1</xsl:text>
332
				                                      </xsl:otherwise>
333
				                                   </xsl:choose>
334
			                                 </xsl:attribute>
335
			                                 <xsl:attribute name="ROWPOS" select="$ROWPOS"/>
336
			                                 <xsl:attribute name="VMERGE" select="$VMERGE"/>
337
			                                 <xsl:copy-of select="@*"/>
338
			                                 <xsl:copy-of select="*"/>
339
			                              </xsl:copy>
340
			                              <xsl:if test="w:tcPr/w:gridSpan/@w:val">
341
			                                 <xsl:variable name="N" select="number(w:tcPr/w:gridSpan/@w:val)           cast as xs:integer"/>
342
			                                 <xsl:for-each select="2 to $N">
343
				                                   <w:tc DUMMY="yes">
344
								     <xsl:copy-of select="$innards"/>
345
				                                   </w:tc>
346
			                                 </xsl:for-each>
347
			                              </xsl:if>
348
			                           </xsl:for-each>
349
			                        </xsl:copy>
350
		                      </xsl:for-each>
351
		                   </tbody>
352
		                </tgroup>
353
		             </table>
354
		             <!--
355
		    <xsl:comment>START</xsl:comment>
356
		    <TABLE>
357
		    <xsl:copy-of select="$TABLE"/>
358
		    </TABLE>
359
		    <xsl:comment>END</xsl:comment>
360
		-->
361
	      </xsl:variable>
362
	      <xsl:variable name="n">
363
		<xsl:number level="any"/>
364
	      </xsl:variable>
365
	      <xsl:for-each select="$TABLE">
366
		<xsl:apply-templates mode="insideCalsTable">
367
		  <xsl:with-param name="n" select="$n" tunnel="yes"/>
368
		</xsl:apply-templates>
369
	      </xsl:for-each>
370
	    </xsl:when>
371
	    <xsl:otherwise>
372
	      <table rend="rules">
373
		<xsl:call-template name="table-header"/>
374
		<xsl:for-each select="w:tr">
375
		  <row>
376
		    <xsl:for-each select="w:tc">
377
		      <cell>
378
			<xsl:if test="preserveEffects='true'">
379
			  <xsl:attribute name="tei:align">
380
			    <xsl:choose>
381
			      <xsl:when test="w:p/w:pPr/w:jc">
382
				<xsl:value-of
383
				  select="w:p[1]/w:pPr/w:jc/@w:val"/>
384
			      </xsl:when>
385
			      <xsl:otherwise>
386
				<xsl:text>left</xsl:text>
387
			      </xsl:otherwise>
388
			    </xsl:choose>
389
			  </xsl:attribute>
390
			</xsl:if>
391
			<xsl:if test="w:tcPr/w:gridSpan">
392
			  <xsl:attribute name="cols" select="w:tcPr/w:gridSpan/@w:val"/>
393
			</xsl:if>
394
			<xsl:variable name="val" select="w:p[1]/w:pPr/w:pStyle/@w:val"/>
395
			<xsl:choose>
396
			  <xsl:when test="$val='[No Paragraph Style]'"/>
397
			  <xsl:when test="$val='Table text (9)'"/>
398
			  <xsl:when test="$val='Table Contents'"/>
399
			  <xsl:when test="string-length($val)=0"/>
400
			  <xsl:otherwise>
401
			    <xsl:attribute name="rend">
402
			      <xsl:value-of select="replace($val,' ','_')"/>
403
			      <xsl:if test="w:tcPr/w:shd/@w:fill and not(w:tcPr/w:shd/@w:fill='auto')">
404
				<xsl:text> background-color(</xsl:text>
405
				<xsl:value-of select="w:tcPr/w:shd/@w:fill"/>
406
				<xsl:text>)</xsl:text>
407
			      </xsl:if>
408
			    </xsl:attribute>
409
			  </xsl:otherwise>
410
			  </xsl:choose>
411
			  <xsl:if test="w:tcPr/w:gridSpan">
412
			    <xsl:attribute name="cols">
413
			      <xsl:value-of select="w:tcPr/w:gridSpan/@w:val"/>
414
			    </xsl:attribute>
415
			  </xsl:if>
416
			  <xsl:call-template name="mainProcess"/>
417
		      </cell>
418
		    </xsl:for-each>
419
		  </row>
420
		</xsl:for-each>
421
	      </table>
422
	    </xsl:otherwise>
423
	  </xsl:choose>
424
	</xsl:template>
425
	
426
	  <xsl:template match="*" mode="insideCalsTable">
427
	     <xsl:copy>
428
	        <xsl:copy-of select="@*"/>
429
	        <xsl:apply-templates mode="insideCalsTable"/>	    
430
	     </xsl:copy>
431
	  </xsl:template>
432

    
433
	  <xsl:template match="w:tr" mode="insideCalsTable">
434
	     <row xmlns="http://www.oasis-open.org/specs/tm9901">
435
	        <xsl:for-each select="w:tc[not(@DUMMY='yes')]">
436
		  <xsl:variable name="cellBorderStyles">
437
		    <xsl:call-template name="getTableBorderStyles">
438
		      <xsl:with-param name="tblBorders" select="w:tcPr/w:tcBorders"/>
439
		    </xsl:call-template>
440
		  </xsl:variable>
441
	           <xsl:choose>
442
		             <xsl:when test="w:tcPr/w:vMerge[not(@w:val='restart')]"/>
443
		             <xsl:otherwise>
444
		                <entry>
445
		                   <xsl:variable name="ROWPOS" select="@ROWPOS"/>
446
		                   <xsl:variable name="COLPOS">
447
		                      <xsl:number/>
448
		                   </xsl:variable>
449
		                   <xsl:copy-of select="@rowsep"/>
450
		                   <xsl:copy-of select="@colsep"/>
451
		                   <xsl:attribute name="colname">
452
		                      <xsl:text>c</xsl:text>
453
		                      <xsl:value-of select="$COLPOS"/>
454
		                   </xsl:attribute>
455
				   <xsl:if test="normalize-space($cellBorderStyles)!=''">
456
				     <xsl:attribute
457
					 name="iso:style">
458
				       <xsl:value-of select="normalize-space($cellBorderStyles)"/>
459
				     </xsl:attribute>
460
				   </xsl:if>
461
		                   <xsl:if test="w:p/w:pPr/w:jc">
462
		                      <xsl:attribute name="align">
463
			                        <xsl:value-of select="w:p[w:pPr/w:jc/@w:val][1]/w:pPr/w:jc/@w:val"/>
464
		                      </xsl:attribute>
465
		                   </xsl:if>
466
		                   <xsl:if test="w:tcPr/w:gridSpan">
467
		                      <xsl:attribute name="namest">
468
			                        <xsl:text>c</xsl:text>
469
			                        <xsl:value-of select="$COLPOS"/>
470
		                      </xsl:attribute>
471
		                      <xsl:attribute name="nameend">
472
			                        <xsl:text>c</xsl:text>
473
			                        <xsl:value-of select="$COLPOS+number(w:tcPr/w:gridSpan/@w:val)-1"/>
474
		                      </xsl:attribute>
475
		                   </xsl:if>
476
		                   <xsl:if test="w:tcPr/w:vAlign">
477
		                      <xsl:attribute name="valign">
478
			                        <xsl:choose>
479
			                           <xsl:when test="w:tcPr/w:vAlign/@w:val='center'">middle</xsl:when>
480
			                           <xsl:otherwise>
481
			                              <xsl:value-of select="w:tcPr/w:vAlign/@w:val"/>
482
			                           </xsl:otherwise>
483
			                        </xsl:choose>
484
		                      </xsl:attribute>
485
		                   </xsl:if>
486
		                   <xsl:if test="w:tcPr/w:textDirection[@w:val='btLr']">
487
		                      <xsl:attribute name="rotate">
488
			                        <xsl:text>1</xsl:text>
489
		                      </xsl:attribute>
490
		                   </xsl:if>
491
		                   <xsl:if test="w:tcPr/w:vMerge/@w:val='restart'">
492
		                      <xsl:variable name="MOREROWS">
493
			                        <xsl:choose>
494
			                           <xsl:when test="parent::w:tr/following-sibling::w:tr/w:tc[position()=$COLPOS][@VMERGE='start']">
495
			                              <xsl:for-each select="(parent::w:tr/following-sibling::w:tr/w:tc[position()=$COLPOS][@VMERGE='start'])[1]">
496
			                                 <xsl:value-of select="@ROWPOS"/>
497
			                              </xsl:for-each>
498
			                           </xsl:when>
499
			                           <xsl:otherwise>
500
			                              <xsl:value-of select="parent::w:tr/following-sibling::w:tr[last()]/w:tc/@ROWPOS"/>
501
			                           </xsl:otherwise>
502
			                        </xsl:choose>
503
		                      </xsl:variable>
504
		                      <!--
505
			  <xsl:message>start a merged cell at <xsl:value-of
506
			  select="$ROWPOS"/>/<xsl:value-of select="$COLPOS"/>
507
			  <xsl:text>: </xsl:text>
508
			  <xsl:value-of select="$MOREROWS"/>-<xsl:value-of
509
			  select="$ROWPOS"/> =<xsl:value-of select="."/>
510
			  </xsl:message>
511
		      -->
512
		      <xsl:attribute name="morerows">
513
			<xsl:value-of select="number($MOREROWS) -            number($ROWPOS) -1"/>
514
		      </xsl:attribute>
515
				   </xsl:if>
516
				   <xsl:choose>
517
				     <xsl:when test="count(w:p)&gt;1
518
						     or w:p/w:pPr/w:pStyle">
519
					<xsl:call-template name="cellContents"/>
520
		                      </xsl:when>
521
		                      <xsl:otherwise>
522
			                        <xsl:apply-templates/>
523
		                      </xsl:otherwise>
524
		                   </xsl:choose>
525
		                </entry>
526
		             </xsl:otherwise>
527
	           </xsl:choose>
528
	        </xsl:for-each>
529
	     </row>
530

    
531
	  </xsl:template>
532

    
533
	  <xsl:template name="cellContents">
534
	     <xsl:apply-templates select="w:p" mode="inTable"/> 
535
	  </xsl:template>
536

    
537
	  <xsl:template match="w:p" mode="inTable">
538
	     <p rend="{w:pPr/w:pStyle/@w:val}">
539
	        <xsl:apply-templates/>
540
	     </p>
541
	  </xsl:template>
542

    
543
	  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
544
      <desc>
545
	    getting the basic table structure
546
    </desc>
547
   </doc>
548
	  <xsl:template match="w:gridCol|w:tblBorders|w:tblCellMar|w:tblGrid|w:tblLayout|w:tblLook|w:tblPr|w:tblW|w:tc|w:tcBorders|w:tcPr|w:tcW|w:tr|w:trPr|w:vAlign|w:top|w:left|w:bottom|w:right|w:insideH|w:insideV">
549

    
550
		    <xsl:choose>
551
			      <xsl:when test="$tableMethod='word'">
552
				        <xsl:copy>
553
					          <xsl:copy-of select="@*"/>
554
					          <xsl:apply-templates/>
555
				        </xsl:copy>
556
			      </xsl:when>
557
			      <xsl:otherwise>
558
				        <xsl:apply-templates/>
559
			      </xsl:otherwise>
560
		    </xsl:choose>
561
	  </xsl:template>
562

    
563

    
564

    
565
    <xsl:template name="table-header">
566
        <xsl:variable name="precedingTableTitle"
567
                    select="preceding-sibling::w:p[w:pPr/w:pStyle/@w:val='TableTitle'             or w:pPr/w:pStyle/@w:val=$Tabletitle][1]"/>
568
        <xsl:if test="$precedingTableTitle and $precedingTableTitle/following-sibling::w:tbl[1] and generate-id()=generate-id($precedingTableTitle/following-sibling::w:tbl[1])">
569
            <head>
570
                <xsl:apply-templates select="$precedingTableTitle"/>
571
            </head>
572
        </xsl:if>
573
    </xsl:template>
574
    
575
    <xsl:template name="cals-table-header">
576
        <xsl:variable name="precedingTableTitle"
577
                    select="preceding-sibling::w:p[w:pPr/w:pStyle/@w:val='TableTitle'             or w:pPr/w:pStyle/@w:val=$Tabletitle][1]"/>
578
        <xsl:if test="$precedingTableTitle and $precedingTableTitle/following-sibling::w:tbl[1] and generate-id()=generate-id($precedingTableTitle/following-sibling::w:tbl[1])">
579
            <title xmlns="http://www.oasis-open.org/specs/tm9901">
580
                <xsl:apply-templates select="$precedingTableTitle"/>
581
            </title>
582
        </xsl:if>
583
    </xsl:template>
584
    
585
</xsl:stylesheet>