Statistics
| Revision:

root / tmp / org.txm.oriflamms.rcp / groovy / org / txm / macro / oriflamms / prepare / 1-oriflamms-split-surfaces.xsl @ 2398

History | View | Annotate | Download (7.8 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet
3
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
	xmlns:xd="http://www.pnp-software.com/XSLTdoc"
5
	xmlns:tei="http://www.tei-c.org/ns/1.0" version="2.0"
6
	xpath-default-namespace="http://www.tei-c.org/ns/1.0">
7

    
8
	<xd:doc type="stylesheet">
9
		<xd:short>
10
			Cette feuille permet de découper un fichier XML TEI Oriflamms en pages
11
			avant de procéder à la tokénisation au niveau de caractère.
12
		</xd:short>
13
		<xd:detail>
14
			This software is dual-licensed:
15

    
16
			1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
17
			Unported License http://creativecommons.org/licenses/by-sa/3.0/
18

    
19
			2. http://www.opensource.org/licenses/BSD-2-Clause
20

    
21
			All rights reserved.
22

    
23
			Redistribution and use in source and binary forms, with or without
24
			modification, are permitted provided that the following conditions are
25
			met:
26

    
27
			* Redistributions of source code must retain the above copyright
28
			notice, this list of conditions and the following disclaimer.
29

    
30
			* Redistributions in binary form must reproduce the above copyright
31
			notice, this list of conditions and the following disclaimer in the
32
			documentation and/or other materials provided with the distribution.
33

    
34
			This software is provided by the copyright holders and contributors
35
			"as is" and any express or implied warranties, including, but not
36
			limited to, the implied warranties of merchantability and fitness for
37
			a particular purpose are disclaimed. In no event shall the copyright
38
			holder or contributors be liable for any direct, indirect,
39
			incidental,
40
			special, exemplary, or consequential damages (including, but not
41
			limited to, procurement of substitute goods or services; loss of use,
42
			data, or profits; or business interruption) however caused and on any
43
			theory of liability, whether in contract, strict liability, or tort
44
			(including negligence or otherwise) arising in any way out of the use
45
			of this software, even if advised of the possibility of such damage.
46

    
47
			$Id$
48

    
49
			This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz
50
			available at
51
			https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl
52
			and is adapted by Alexei Lavrentiev to split an XML TEI Oriflamms
53
			file
54
			into pages for further tokenizatrion at character level.
55

    
56
		</xd:detail>
57
		<xd:author>Alexei Lavrentiev alexei.lavrentev@ens-lyon.fr</xd:author>
58
		<xd:copyright>2015, CNRS / ICAR (Équipe CACTUS)</xd:copyright>
59
	</xd:doc>
60

    
61

    
62

    
63
	<xsl:output indent="no" method="xml" />
64

    
65

    
66
	<xsl:variable name="filename">
67
		<xsl:analyze-string select="document-uri(.)"
68
			regex="^(.*)/([^/]+)\.[^/]+$">
69
			<xsl:matching-substring>
70
				<xsl:value-of select="regex-group(2)" />
71
			</xsl:matching-substring>
72
		</xsl:analyze-string>
73
	</xsl:variable>
74

    
75
	<xsl:variable name="filedir">
76
		<xsl:analyze-string select="document-uri(.)"
77
			regex="^(.*)/([^/]+)\.[^/]+$">
78
			<xsl:matching-substring>
79
				<xsl:value-of select="regex-group(1)" />
80
			</xsl:matching-substring>
81
		</xsl:analyze-string>
82
	</xsl:variable>
83

    
84
	<!--<xsl:variable name="filenameresult"> <xsl:value-of select="replace($filename,'(-ori)?-w$','')"/> 
85
		</xsl:variable> -->
86

    
87
	<xsl:param name="output-directory">
88
		<xsl:value-of select="concat($filedir,'/out')" />
89
	</xsl:param>
90

    
91

    
92
	<xsl:template match="teiHeader">
93
		<!--<xsl:copy-of select="."/> -->
94
	</xsl:template>
95

    
96
	<xsl:template match="TEI|teiCorpus|group|text">
97
		<xsl:copy>
98
			<xsl:apply-templates select="@*" />
99
			<xsl:apply-templates
100
				select="*|processing-instruction()|comment()|text()" />
101
		</xsl:copy>
102
	</xsl:template>
103

    
104

    
105
	<xsl:template match="text/body|text/back|text/front">
106
		<xsl:variable name="pages">
107
			<xsl:copy>
108
				<xsl:apply-templates select="@*" />
109
				<xsl:apply-templates
110
					select="*|processing-instruction()|comment()|text()" />
111
			</xsl:copy>
112
		</xsl:variable>
113
		<xsl:for-each select="$pages">
114
			<xsl:apply-templates mode="pass2" />
115
		</xsl:for-each>
116
	</xsl:template>
117

    
118

    
119
	<!-- first (recursive) pass. look for <pb> elements and group on them -->
120
	<xsl:template
121
		match="comment()|@*|processing-instruction()|text()">
122
		<xsl:copy-of select="." />
123
	</xsl:template>
124

    
125
	<xsl:template match="*">
126
		<xsl:call-template name="checkpb">
127
			<xsl:with-param name="eName" select="local-name()" />
128
		</xsl:call-template>
129
	</xsl:template>
130

    
131
	<xsl:template match="milestone[@unit='surface']">
132
		<xsl:copy-of select="." />
133
	</xsl:template>
134

    
135
	<xsl:template name="checkpb">
136
		<xsl:param name="eName" />
137
		<xsl:choose>
138
			<xsl:when test="not(.//milestone[@unit='surface'])">
139
				<xsl:copy-of select="." />
140
			</xsl:when>
141
			<xsl:otherwise>
142
				<xsl:variable name="pass">
143
					<xsl:call-template name="groupbypb">
144
						<xsl:with-param name="Name" select="$eName" />
145
					</xsl:call-template>
146
				</xsl:variable>
147
				<xsl:for-each select="$pass">
148
					<xsl:apply-templates />
149
				</xsl:for-each>
150
			</xsl:otherwise>
151
		</xsl:choose>
152
	</xsl:template>
153

    
154
	<xsl:template name="groupbypb">
155
		<xsl:param name="Name" />
156
		<xsl:for-each-group select="node()"
157
			group-starting-with="milestone[@unit='surface']">
158
			<xsl:choose>
159
				<xsl:when test="self::milestone[@unit='surface']">
160
					<xsl:copy-of select="." />
161
					<xsl:element name="{$Name}"
162
						namespace="http://www.w3.org/1999/xhtml">
163
						<xsl:attribute name="rend">CONTINUED</xsl:attribute>
164
						<xsl:apply-templates
165
							select="current-group() except ." />
166
					</xsl:element>
167
				</xsl:when>
168
				<xsl:otherwise>
169
					<xsl:element name="{$Name}"
170
						namespace="http://www.w3.org/1999/xhtml">
171
						<xsl:for-each select="..">
172
							<xsl:copy-of select="@*" />
173
							<xsl:apply-templates select="current-group()" />
174
						</xsl:for-each>
175
					</xsl:element>
176
				</xsl:otherwise>
177
			</xsl:choose>
178
		</xsl:for-each-group>
179
	</xsl:template>
180

    
181
	<!-- second pass. group by <pb> (now all at top level) and wrap groups in 
182
		<page> -->
183
	<xsl:template match="*" mode="pass2">
184
		<xsl:copy>
185
			<xsl:apply-templates
186
				select="@*|*|processing-instruction()|comment()|text()" mode="pass2" />
187
		</xsl:copy>
188
	</xsl:template>
189

    
190
	<xsl:template
191
		match="comment()|@*|processing-instruction()|text()" mode="pass2">
192
		<xsl:copy-of select="." />
193
	</xsl:template>
194

    
195

    
196
	<xsl:template match="*[milestone[@unit='surface']]"
197
		mode="pass2">
198
		<xsl:copy>
199
			<xsl:apply-templates select="@*" />
200
			<xsl:for-each-group select="*"
201
				group-starting-with="milestone[@unit='surface']">
202
				<xsl:choose>
203
					<xsl:when test="self::milestone[@unit='surface']">
204
						<xsl:comment>
205
							Page
206
							<xsl:value-of select="@xml:id" />
207
							enregistrée dans
208
							<xsl:value-of
209
								select="concat($output-directory,'/',$filename,'_',@xml:id,'.xml')" />
210
						</xsl:comment>
211
						<xsl:text>&#xA;</xsl:text>
212
						<xsl:result-document
213
							href="{$output-directory}/{$filename}_{@xml:id}.xml" indent="yes">
214
							<TEI>
215
								<teiHeader>
216
									<fileDesc>
217
										<titleStmt>
218
											<title>
219
												Page
220
												<xsl:value-of select="@xml:id" />
221
												of
222
												<xsl:value-of select="$filename" />
223
												tokenized at character level.
224
											</title>
225
										</titleStmt>
226
										<publicationStmt>
227
											<p>Oriflamms project (http://oriflamms.hypotheses.org)</p>
228
										</publicationStmt>
229
										<sourceDesc>
230
											<p>
231
												Converted from
232
												<xsl:value-of select="$filename" />
233
												.
234
											</p>
235
										</sourceDesc>
236
									</fileDesc>
237
									<revisionDesc>
238
										<change when="{current-dateTime()}">File created.</change>
239
									</revisionDesc>
240
								</teiHeader>
241
								<text>
242
									<body>
243
										<xsl:copy-of select="." />
244
										<xsl:copy-of select="current-group() except ." />
245
									</body>
246
								</text>
247
							</TEI>
248
						</xsl:result-document>
249
					</xsl:when>
250
					<xsl:otherwise>
251
						<xsl:copy-of select="current-group()" />
252
					</xsl:otherwise>
253
				</xsl:choose>
254
			</xsl:for-each-group>
255
		</xsl:copy>
256
	</xsl:template>
257

    
258
</xsl:stylesheet>