Statistics
| Revision:

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

History | View | Annotate | Download (15.8 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:cals="http://www.oasis-open.org/specs/tm9901"
3
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
                xmlns:prop="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
6
                xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
7
                xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
8
                xmlns:dc="http://purl.org/dc/elements/1.1/"
9
                xmlns:dcterms="http://purl.org/dc/terms/"
10
                xmlns:dcmitype="http://purl.org/dc/dcmitype/"
11
		xmlns:html="http://www.w3.org/1999/xhtml"
12
                xmlns:iso="http://www.iso.org/ns/1.0"
13
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
14
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
15
                xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
16
                xmlns:mv="urn:schemas-microsoft-com:mac:vml"
17
                xmlns:o="urn:schemas-microsoft-com:office:office"
18
                xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
19
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
20
                xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships"
21
                xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html"
22
                xmlns:tei="http://www.tei-c.org/ns/1.0"
23
                xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
24
                xmlns:v="urn:schemas-microsoft-com:vml"
25
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
26
                xmlns:w10="urn:schemas-microsoft-com:office:word"
27
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
28
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
29
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
30
                
31
                xmlns="http://www.tei-c.org/ns/1.0"
32
                version="2.0"
33
                exclude-result-prefixes="a cp dc dcterms dcmitype prop  html   iso m mml mo mv o pic r rel cals     tbx tei teidocx v xs ve w10 w wne wp">
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: pass2.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
72
         <p>Copyright: 2008, TEI Consortium</p>
73
      </desc>
74
   </doc>
75
    
76
    
77
    <xsl:template match="@*|comment()|processing-instruction()" mode="pass2">
78
        <xsl:copy-of select="."/>
79
    </xsl:template>
80
    
81
    <xsl:template match="*" mode="pass2">
82
        <xsl:copy>
83
            <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
84
        </xsl:copy>
85
    </xsl:template>
86
    
87
    
88
    <xsl:template match="text()" mode="pass2">
89
	  <xsl:value-of select="."/>
90
    </xsl:template>
91
    
92
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
93
      <desc>
94
         <p>     Zap empty p and item </p>
95
      </desc>
96
    </doc>
97
 
98
   <xsl:template match="tei:p[not(*) and string-length(.)=0]"
99
		 mode="pass2" priority="99"/>
100
    
101
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
102
      <desc>
103
         <p>     Inner lists in lists must be moved to inside items
104
	 </p>
105
      </desc>
106
    </doc>
107
    <xsl:template match="tei:list/tei:list" mode="pass2"/>
108
    <xsl:template match="tei:item" mode="pass2">
109
      <xsl:choose>
110
	<xsl:when test="not(*) and string-length(.)=0"/>
111
	<xsl:otherwise>
112
	  <item>
113
	    <xsl:copy-of select="@*"/>
114
	    <xsl:variable name="me" select="generate-id()"/>
115
	    <xsl:apply-templates mode="pass2"/>
116
	    <!-- find following sibling lists and notes -->
117
	    <xsl:for-each select="following-sibling::tei:list[preceding-sibling::tei:item[1][generate-id()=$me]]">
118
	      <list>
119
		<xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
120
	      </list>
121
	    </xsl:for-each>
122
	  </item>
123
	</xsl:otherwise>
124
      </xsl:choose>
125
    </xsl:template>
126
    
127
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
128
      <desc>
129
         <p>     Zap emdashes at start of head </p>
130
      </desc>
131
    </doc>
132
    <xsl:template match="tei:head/text()" mode="pass2">
133
        <xsl:choose>
134
            <xsl:when test="starts-with(.,'โ€” ')">
135
                <xsl:value-of select="substring(.,3)"/>
136
            </xsl:when>
137
            <xsl:when test="starts-with(.,'&#160;โ€” ')">
138
                <xsl:value-of select="substring(.,4)"/>
139
            </xsl:when>
140
            <xsl:when test="starts-with(.,' โ€” ')">
141
                <xsl:value-of select="substring(.,4)"/>
142
            </xsl:when>
143
            <xsl:otherwise>
144
                <xsl:value-of select="."/>
145
            </xsl:otherwise>
146
        </xsl:choose>
147
    </xsl:template>
148
    
149
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
150
      <desc>
151
         <p>     A &lt;seg&gt; which does nothing is not worth having </p>
152
      </desc>
153
    </doc>
154
    <xsl:template match="tei:seg[not(@*)]" mode="pass2">
155
        <xsl:choose>
156
            <xsl:when test="parent::tei:formula and normalize-space(.)=''"/>
157
	    <xsl:when test=".=' ' and following-sibling::node()[1][self::tei:hi]/@rend=
158
			    preceding-sibling::node()[1][self::tei:hi]/@rend"/>
159

    
160
            <xsl:when test="parent::*/text()">
161
                <xsl:value-of select="."/>
162
            </xsl:when>
163
	    <xsl:when test="parent::tei:hi[count(*)=1]">
164
	      <xsl:value-of select="."/>
165

    
166
	    </xsl:when>
167
            <xsl:otherwise>
168
                <xsl:copy-of select="."/>
169
            </xsl:otherwise>
170
        </xsl:choose>
171
    </xsl:template>
172
    
173
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
174
      <desc>
175
         <p>Look at the sections we have generated, and put
176
        them in &lt;front&gt; or &lt;body&gt; as appropriate</p>
177
      </desc>
178
    </doc>
179

    
180
    <xsl:template match="tei:text" mode="pass2">
181
        <text>
182
            <xsl:for-each select="tei:fw">
183
                <xsl:copy-of select="."/>
184
            </xsl:for-each>
185
            <body>
186
                <xsl:for-each select="tei:body/tei:*">
187
                    <xsl:apply-templates select="." mode="pass2"/>
188
                </xsl:for-each>
189
            </body>
190
        </text>
191
    </xsl:template>
192
    
193
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
194
      <desc>
195
         <p>     A &lt;p&gt; inside a listBibl is moved out</p>
196
      </desc>
197
    </doc>
198
    <xsl:template match="tei:listBibl/tei:p" mode="pass2"/>
199
    
200
    <xsl:template match="tei:listBibl" mode="pass2">
201
        <xsl:for-each select="tei:p">
202
            <p>
203
                <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
204
            </p>
205
        </xsl:for-each>
206
        <listBibl>
207
            <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
208
        </listBibl>
209
    </xsl:template>
210
    
211
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
212
      <desc>
213
         <p>  Gloss list from tei to docx</p>
214
      </desc>
215
    </doc>
216
    <!-- <GLOSSITEM>
217
	 <hi rend="bold">100</hi>
218
	 <lb/>first item </GLOSSITEM>
219
    -->
220
    <xsl:template match="tei:GLOSSITEM" mode="pass2">
221
      <label>
222
	<xsl:for-each select="tei:hi">
223
	  <xsl:apply-templates/>
224
	</xsl:for-each>
225
      </label>
226
      <item>
227
	<xsl:apply-templates mode="inglossitem"/>
228
      </item>
229
    </xsl:template>
230

    
231
    <xsl:template match="*" mode="inglossitem">
232
      <xsl:apply-templates select="." mode="pass2"/>
233
    </xsl:template>
234

    
235
    <xsl:template match="tei:lb" mode="inglossitem"/>
236
    <xsl:template match="tei:hi[@rend='bold']" mode="inglossitem"/>
237

    
238
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
239
      <desc>
240
         <p>     Top of a weird gloss list </p>
241
      </desc>
242
    </doc>
243
    <xsl:template match="tei:list[@type='gloss']/tei:label[.='where']" mode="pass2">
244
        <head>
245
            <xsl:apply-templates/>
246
        </head>
247
    </xsl:template>
248
    
249
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
250
      <desc>
251
         <p>     A tab in a &lt;bibl&gt;? no. </p>
252
      </desc>
253
    </doc>
254
    <xsl:template match="tei:bibl/tei:g[@ref='x:tab']" mode="pass2"/>
255
    
256
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
257
      <desc>
258
         <p>     A tab in a &lt;gloss&gt;? no. </p>
259
      </desc>
260
    </doc>
261
    <xsl:template match="tei:gloss//tei:g[@ref='x:tab']" mode="pass2"/>
262
    
263
    
264
    <!-- removed 2010-03-15, seems to screw up formulae
265
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
266
      <desc>
267
         <p>     A tab in a &lt;formula&gt;? no. </p>
268
      </desc>
269
    </doc>
270

    
271
    <xsl:template match="tei:formula//tei:g[@ref='x:tab']" mode="pass2"/>
272
    -->
273
    
274
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
275
      <desc>
276
         <p>     A tab in a &lt;head&gt;? no. </p>
277
      </desc>
278
    </doc>
279
    <xsl:template match="tei:head/tei:g[@ref='x:tab']" mode="pass2"/>
280
    
281

    
282
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
283
      <desc>
284
         <p>     An empty item</p>
285
      </desc>
286
    </doc>
287
    <xsl:template match="tei:item[not(*) and not(text())]" mode="pass2"/>
288
    
289

    
290
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl"  >
291
    <desc>Zap empty &lt;bibl&gt; </desc></doc>
292
    
293
    <xsl:template match="tei:bibl[not(*) and not(text())]" mode="pass2"/>
294

    
295
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl"  >
296
    <desc>Zap empty &lt;availability&gt; </desc></doc>
297
   
298
    <xsl:template match="tei:availability[not(*) and not(text())]"
299
		  mode="pass2"/>
300

    
301
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl"  >
302
    <desc>Zap empty &lt;note&gt; </desc></doc>
303
   
304
    <xsl:template match="tei:note[not(*) and not(text())]"
305
		  mode="pass2">
306
    </xsl:template>
307

    
308
    <xsl:template match="tei:list[@type='gloss']/tei:item/tei:g[@ref='x:tab']" mode="pass2"/>
309
    
310

    
311
    <xsl:template match="tei:hi[@rend='footnote_reference' and
312
			 count(*)=1 and tei:note]" mode="pass2" priority="99">
313
          <xsl:apply-templates mode="pass2"/>
314
    </xsl:template>
315

    
316
  <xsl:template match="tei:hi[not(@rend) and not(*) and string-length(.)=0]" mode="pass2">
317
  </xsl:template>
318

    
319
  <xsl:template match="tei:hi[@rend='Endnote_anchor']" mode="pass2" priority="99">
320
    <xsl:apply-templates mode="pass2"/>
321
  </xsl:template>
322

    
323
  <xsl:template match="tei:hi[@rend='EndnoteReference']" mode="pass2"  priority="99">
324
    <xsl:apply-templates mode="pass2"/>
325
  </xsl:template>
326

    
327
  <xsl:template match="tei:hi[@rend='EndnoteCharacters']" mode="pass2"
328
		 priority="99">
329
    <xsl:apply-templates mode="pass2"/>
330
  </xsl:template>
331
 
332
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
333
    <desc>Clean up <gi>hi</gi> by merging adjacent &lt;hi&gt;s </desc>
334
  </doc>
335

    
336
  <xsl:template match="tei:hi[@rend]" mode="pass2">
337
    <xsl:variable name="r" select="@rend"/>
338
    <xsl:choose>
339
      <xsl:when test="count(parent::tei:speaker/*)=1 and not
340
		      (parent::tei:speaker/text())">
341
	<xsl:apply-templates/>
342
      </xsl:when>
343
      <xsl:when test="parent::tei:head and .='&#160;'"/>
344
      <xsl:when test ="not(*) and string-length(.)=0"/>
345
      <xsl:when test="parent::tei:item/parent::tei:list[@type='gloss']
346
		      and tei:g[@ref='x:tab']"/>
347
      <xsl:when
348
	  test="preceding-sibling::node()[1][self::tei:hi[@rend=$r]]">
349
      </xsl:when>
350
      <xsl:when
351
	  test="preceding-sibling::node()[1][self::tei:seg and .=' ']
352
		and
353
		preceding-sibling::node()[2][self::tei:hi[@rend=$r]]">
354
      </xsl:when>
355
      <xsl:when test="@rend='bold' and .=' '">
356
	<xsl:text> </xsl:text>
357
      </xsl:when>
358
      <xsl:when test="@rend='italic' and .=' '">
359
	<xsl:text> </xsl:text>
360
      </xsl:when>
361
      <xsl:otherwise>
362
	<xsl:variable name="ename">
363
	  <xsl:choose>
364
	    <xsl:when test="@rend='italic' and
365
			    ancestor::tei:bibl">title</xsl:when>
366
	    <xsl:otherwise>hi</xsl:otherwise>
367
	  </xsl:choose>
368
	</xsl:variable>
369
	<xsl:element name="{$ename}">
370
	  <xsl:copy-of select="@*"/>
371
	  <xsl:apply-templates mode="pass2"/>
372
	  <xsl:call-template name="nextHi">
373
	    <xsl:with-param name="r" select="$r"/>
374
	  </xsl:call-template>
375
	</xsl:element>
376
      </xsl:otherwise>
377
    </xsl:choose>
378
   </xsl:template>
379

    
380
   <xsl:template name="nextHi">
381
      <xsl:param name="r"/>
382
      <xsl:for-each select="following-sibling::node()[1]">
383
         <xsl:choose>
384
	   <xsl:when test="self::tei:hi[@rend=$r]">
385
            <xsl:apply-templates mode="pass2"/>
386
            <xsl:call-template name="nextHi">
387
	              <xsl:with-param name="r" select="$r"/>
388
            </xsl:call-template>
389
	   </xsl:when>
390
	   <xsl:when test="self::tei:seg and .=' ' and
391
			   following-sibling::node()[1][self::tei:hi[@rend=$r]]">
392
            <xsl:apply-templates mode="pass2"/>
393
            <xsl:call-template name="nextHi">
394
	              <xsl:with-param name="r" select="$r"/>
395
	    </xsl:call-template>
396
	   </xsl:when>
397
	 </xsl:choose>
398
      </xsl:for-each>
399
   </xsl:template>
400

    
401
   <xsl:template match="tei:div[tei:head/tei:ANCHOR]" mode="pass2">
402
     <xsl:copy>
403
       <xsl:attribute name="xml:id"
404
		      select="tei:head/tei:ANCHOR[1]/@xml:id"/>
405
       <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
406
     </xsl:copy>
407
   </xsl:template>
408

    
409
   <xsl:template match="tei:ANCHOR" mode="pass2"/>
410

    
411
   <xsl:template match="w:bookmarkStart" mode="pass2">
412
       <anchor>
413
        <xsl:attribute name="xml:id">
414
            <xsl:value-of select="substring(@w:name,2)"/>
415
        </xsl:attribute>
416
	</anchor>
417
   </xsl:template>
418

    
419
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl"  >
420
    <desc>Paragraphs in cells not allowed</desc></doc>
421
   
422
    <xsl:template match="tei:cell/tei:p" mode="pass2">
423
      <xsl:if test="preceding-sibling::tei:p">
424
	<lb/>
425
      </xsl:if>
426
      <xsl:apply-templates mode="pass2"/>
427
    </xsl:template>
428

    
429
    <xsl:template match="tei:speech" mode="pass2"/>
430
    <xsl:template match="tei:speech" mode="keep">
431
      <p>
432
	<xsl:apply-templates mode="pass2"/>
433
      </p>
434
    </xsl:template>
435

    
436
    <xsl:template match="tei:speaker" mode="pass2">
437
      <sp>
438
	<speaker>
439
	  <xsl:choose>	
440
	    <xsl:when test="count(*)=1 and not(text()) and tei:hi[@rend]">
441
	      <xsl:attribute name="rend" select="tei:hi/@rend"/>
442
	      <xsl:for-each select="tei:hi">
443
	      <xsl:apply-templates mode="pass2"/>
444
	      </xsl:for-each>
445
	    </xsl:when>
446
	    <xsl:otherwise>
447
	      <xsl:apply-templates mode="pass2"/>
448
	    </xsl:otherwise>
449
	  </xsl:choose>
450
	</speaker>
451
	<xsl:apply-templates
452
	    select="following-sibling::tei:speech[1]" mode="keep"/>
453
      </sp>
454
    </xsl:template>
455

    
456

    
457

    
458
</xsl:stylesheet>