Statistics
| Revision:

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

History | View | Annotate | Download (11 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="http://www.tei-c.org/ns/1.0"
29
                version="2.0"
30
                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">
31
    
32
    
33
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
34
      <desc>
35
         <p> TEI stylesheet for converting Word docx files to TEI </p>
36
         <p>This software is dual-licensed:
37

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

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

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

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

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

    
56
This software is provided by the copyright holders and contributors
57
"as is" and any express or implied warranties, including, but not
58
limited to, the implied warranties of merchantability and fitness for
59
a particular purpose are disclaimed. In no event shall the copyright
60
holder or contributors be liable for any direct, indirect, incidental,
61
special, exemplary, or consequential damages (including, but not
62
limited to, procurement of substitute goods or services; loss of use,
63
data, or profits; or business interruption) however caused and on any
64
theory of liability, whether in contract, strict liability, or tort
65
(including negligence or otherwise) arising in any way out of the use
66
of this software, even if advised of the possibility of such damage.
67
</p>
68
         <p>Author: See AUTHORS</p>
69
         <p>Id: $Id: paragraphs.xsl 10152 2012-03-12 22:58:02Z rahtz $</p>
70
         <p>Copyright: 2008, TEI Consortium</p>
71
      </desc>
72
   </doc>
73
    
74
   <xsl:variable name="dblq">"</xsl:variable>
75
   <xsl:variable name="dblqplusr">" \r "</xsl:variable>
76
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
77
      <desc>
78
         <p>Calls the named template paragraph-wp that can be overriden.</p>
79
         <p>
80
            See comment at begin of document to understand why this template is calling
81
            a named template.
82
            
83
            This stylesheet is handling simple paragraphs that we know nothing else
84
            about.
85
        </p>
86
      </desc>
87
   </doc>
88
    <xsl:template match="w:p" mode="paragraph">
89
      <xsl:variable name="style" select="w:pPr/w:pStyle/@w:val"/>
90
      <xsl:choose>
91
	<xsl:when test="$style='tei_lg'"/>
92
	<xsl:when test="$style='GeneratedTitle'"/>
93
	<xsl:when test="$style='GeneratedSubTitle'"/>
94

    
95
	<xsl:when test="$style='tei_l'">
96
	  <l>
97
	    <xsl:apply-templates/>
98
	  </l>
99
	</xsl:when>
100
	<xsl:when test="$style='Tabletitle'">
101
	  <head>
102
	    <xsl:apply-templates/>
103
	  </head>
104
	</xsl:when>
105
	<xsl:when test="$style='dl'">
106
	  <GLOSSITEM>
107
	    <xsl:apply-templates/>
108
	  </GLOSSITEM>
109
	</xsl:when>
110
	<xsl:when test="$style='tei_signed'">
111
	  <signed>
112
	    <xsl:apply-templates/>
113
	  </signed>
114
	</xsl:when>
115
	<xsl:when test="$style='tei_speaker'">
116
	  <speaker>
117
	    <xsl:apply-templates/>
118
	  </speaker>
119
	</xsl:when>
120
	<xsl:when test="$style='tei_speech'">
121
	  <speech>
122
	    <xsl:apply-templates/>
123
	  </speech>
124
	</xsl:when>
125
	<xsl:otherwise>
126
	  <xsl:call-template name="paragraph-wp">
127
	    <xsl:with-param name="style" select="$style"/>
128
	  </xsl:call-template>
129
	</xsl:otherwise>
130
      </xsl:choose>
131
    </xsl:template>
132
    
133
    
134
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
135
      <desc>
136
        Named template for handling w:p; we 
137
       use the Word style (if provided) to make a TEI rend attribute,
138
       and check for change records.
139
    </desc>
140
   </doc>
141
   <xsl:template name="paragraph-wp">
142
     <xsl:param name="style"/>
143
     <xsl:element name="p">
144
       <xsl:if test="$style and not($style='Default')">
145
	 <xsl:attribute name="rend">
146
	   <xsl:value-of select="$style"/>
147
	 </xsl:attribute>
148
       </xsl:if>
149
       <xsl:if test="w:pPr/w:pStyle/w:rPr/w:rtl">
150
	 <xsl:attribute name="dir"
151
			xmlns="http://www.w3.org/2005/11/its">
152
	   <xsl:text>rtl</xsl:text>
153
	 </xsl:attribute>
154
       </xsl:if>
155
       <xsl:choose>
156
	 <xsl:when test="w:pPr/w:rPr/w:ins">
157
	   <add when="{w:pPr/w:rPr/w:ins/@w:date}" 
158
		type="para">
159
	     <xsl:call-template name="identifyChange">
160
	       <xsl:with-param name="who"
161
			       select="w:pPr/w:rPr/w:ins/@w:author"/>
162
	     </xsl:call-template>
163
	     <xsl:call-template name="process-checking-for-crossrefs"/>
164
	   </add>
165
	 </xsl:when>
166
	 <xsl:otherwise>
167
	   <xsl:call-template name="process-checking-for-crossrefs"/>
168
	 </xsl:otherwise>
169
       </xsl:choose>
170
     </xsl:element>
171
   </xsl:template>
172
   
173
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
174
      <desc>
175
	Named template for handling processing any cross-references found.
176
    </desc>
177
    </doc>
178
    <xsl:template name="process-checking-for-crossrefs">
179
      <xsl:choose>
180
	<xsl:when
181
	    test="w:r/w:fldChar[@w:fldCharType='begin']">
182
	  <xsl:for-each-group select="w:*|m:*"
183
			      group-starting-with="w:r[w:fldChar/@w:fldCharType[matches(.,'begin|end')]]">
184
	    <xsl:choose>
185
	      <xsl:when test="self::w:r/w:fldChar[@w:fldCharType='begin']">
186
		<xsl:variable name="rends">
187
		  <!-- collect all the rends for concatenation later -->
188
		  <xsl:choose>
189
		    <xsl:when
190
			test="contains(following-sibling::w:r[w:instrText][1],'NOTEREF')"><r>noteref</r></xsl:when>
191
		    <xsl:when
192
			test="contains(following-sibling::w:r[w:instrText][1],'SEQ')"><r>SEQ</r></xsl:when>
193
		    <xsl:when test="contains(following-sibling::w:r[w:instrText][1],'XE')"><r>index</r></xsl:when>
194
		    <xsl:when test="contains(following-sibling::w:r[w:instrText][1],'REF')"><r>ref</r></xsl:when>
195
		  </xsl:choose>
196
		  <xsl:if test="contains(following-sibling::w:r[w:instrText][1],'\r')"><r>instr_r</r></xsl:if>
197
		  <xsl:if test="contains(following-sibling::w:r[w:instrText][1],'\f')"><r>instr_f</r></xsl:if>
198
		  <xsl:if test="contains(following-sibling::w:r[w:instrText][1],'\n')"><r>instr_n</r></xsl:if>
199
		  <xsl:if test="contains(following-sibling::w:r[w:instrText][1],'MERGEFORMAT')"><r>mergeformat</r></xsl:if>
200
		</xsl:variable>
201
		<xsl:choose>
202
		  <xsl:when test="$rends/tei:r='index'">
203
		    <index>
204
		      <term>
205
		      <xsl:for-each
206
			  select="current-group()//w:instrText">
207
			<xsl:choose>
208
			  <xsl:when test=".='XE'"/>
209
			  <xsl:when test="normalize-space(.)=$dblq"/>
210
			  <xsl:when test="starts-with(normalize-space(.),$dblqplusr)"/>
211
			  <xsl:otherwise>
212
			    <xsl:apply-templates/>
213
			  </xsl:otherwise>
214
			</xsl:choose>
215
		      </xsl:for-each>
216
		      </term>
217
		    </index>
218
		  </xsl:when>
219
		  <xsl:when test="$rends/tei:r='SEQ'">
220
		    <xsl:variable name="What"
221
				  select="following-sibling::w:r/w:instrText[1]"/>
222
		    <xsl:number level="any" count="w:r[w:fldChar/@w:fldCharType='begin'][following-sibling::w:r/w:instrText=$What]"/>
223
		  </xsl:when>
224
		  <xsl:otherwise>
225
		    <ref>
226
		      <xsl:if test="$rends/tei:r">
227
			<xsl:attribute name="rend">
228
			  <xsl:value-of select="string-join(($rends/tei:r),' ')"/>
229
			</xsl:attribute>
230
		      </xsl:if>
231
		      <xsl:if test="following-sibling::w:r[w:rPr][1]/w:rStyle">
232
			<xsl:attribute name="iso:class">
233
			  <xsl:value-of select="following-sibling::w:r[w:rPr][1]/w:rStyle/w:rPr/w:rStyle/@w:val"/>
234
			</xsl:attribute>
235
		      </xsl:if> 
236
		      <xsl:for-each select="current-group()">
237
			<xsl:if test="self::w:r[w:instrText]">			    
238
			  <xsl:variable name="ref">
239
			    <xsl:choose>
240
			      <xsl:when test="contains(w:instrText,'REF _')"> <!-- this will also catch NOTEREF _ -->
241
				<xsl:text>#</xsl:text>
242
				<xsl:value-of select="substring-before(substring-after(w:instrText,'_'),'&#32;')"/>
243
			      </xsl:when>
244
			      <xsl:when test="contains(w:instrText,'HYPERLINK')">
245
				<xsl:value-of select="substring-before(substring-after(w:instrText,'&#x0022;'),'&#x0022;')"/>
246
			      </xsl:when>
247
			    </xsl:choose>
248
			  </xsl:variable>
249
			  <xsl:attribute name="target" select="$ref"/>
250
			</xsl:if>
251
		      </xsl:for-each>
252
		      <xsl:for-each select="current-group()">
253
			<xsl:choose>
254
			  <xsl:when  test="self::w:bookmarkStart">
255
			    <xsl:apply-templates select="."/>
256
			  </xsl:when>
257
			  <xsl:otherwise>
258
			    <xsl:apply-templates select="."/>
259
			  </xsl:otherwise>
260
			</xsl:choose>
261
		      </xsl:for-each>
262
		    </ref>
263
		  </xsl:otherwise>
264
		</xsl:choose>
265
	      </xsl:when>
266
	      <xsl:when
267
		  test="self::w:r[w:fldChar/@w:fldCharType[matches(.,'end')]]">
268
		<xsl:for-each select="current-group()">
269
		  <xsl:choose>
270
		    <xsl:when
271
			test="self::w:r[w:fldChar/@w:fldCharType[matches(.,'end')]]">
272
		    </xsl:when>
273
		    <xsl:otherwise>
274
		      <xsl:apply-templates select="."/>
275
		    </xsl:otherwise>
276
		  </xsl:choose>
277
		</xsl:for-each>
278
	      </xsl:when>
279
	      <xsl:otherwise>
280
		<xsl:apply-templates select="current-group()"/>
281
	      </xsl:otherwise>
282
	    </xsl:choose>
283
	  </xsl:for-each-group>
284
	</xsl:when>
285
	<xsl:otherwise>
286
	  <xsl:apply-templates/>
287
	</xsl:otherwise>
288
      </xsl:choose>
289
    </xsl:template>
290

    
291
</xsl:stylesheet>