Statistics
| Revision:

root / tmp / org.txm.oriflamms.rcp / res / 2-default-pager.xsl @ 2398

History | View | Annotate | Download (8.4 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet exclude-result-prefixes="#all"
3
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
	xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
5
	<!-- This software is dual-licensed: 1. Distributed under a Creative Commons 
6
		Attribution-ShareAlike 3.0 Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
7
		2. http://www.opensource.org/licenses/BSD-2-Clause All rights reserved. Redistribution 
8
		and use in source and binary forms, with or without modification, are permitted 
9
		provided that the following conditions are met: * Redistributions of source 
10
		code must retain the above copyright notice, this list of conditions and 
11
		the following disclaimer. * Redistributions in binary form must reproduce 
12
		the above copyright notice, this list of conditions and the following disclaimer 
13
		in the documentation and/or other materials provided with the distribution. 
14
		This software is provided by the copyright holders and contributors "as is" 
15
		and any express or implied warranties, including, but not limited to, the 
16
		implied warranties of merchantability and fitness for a particular purpose 
17
		are disclaimed. In no event shall the copyright holder or contributors be 
18
		liable for any direct, indirect, incidental, special, exemplary, or consequential 
19
		damages (including, but not limited to, procurement of substitute goods or 
20
		services; loss of use, data, or profits; or business interruption) however 
21
		caused and on any theory of liability, whether in contract, strict liability, 
22
		or tort (including negligence or otherwise) arising in any way out of the 
23
		use of this software, even if advised of the possibility of such damage. 
24
		$Id$ This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz available 
25
		at https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl and 
26
		is adapted by Alexei Lavrentiev to split an HTML edition for TXM platform. -->
27
	<xsl:output indent="no" method="html" />
28

    
29
	<xsl:param name="css-name-txm">
30
		txm
31
	</xsl:param>
32
	<xsl:param name="css-name">
33
		tei
34
	</xsl:param>
35
	<xsl:param name="edition-name">
36
		default
37
	</xsl:param>
38
	<xsl:param name="number-words-per-page">
39
		999999
40
	</xsl:param>
41
	<xsl:param name="pagination-element">
42
		a[@class='txm-page']
43
	</xsl:param>
44
	<xsl:param name="output-directory">
45
		<xsl:value-of
46
			select="concat($current-file-directory,'/',$edition-name)" />
47
	</xsl:param>
48

    
49
	<xsl:variable name="current-file-name">
50
		<xsl:analyze-string select="document-uri(.)"
51
			regex="^(.*)/([^/]+)\.[^/]+$">
52
			<xsl:matching-substring>
53
				<xsl:value-of select="regex-group(2)" />
54
			</xsl:matching-substring>
55
		</xsl:analyze-string>
56
	</xsl:variable>
57

    
58
	<xsl:variable name="current-file-directory">
59
		<xsl:analyze-string select="document-uri(.)"
60
			regex="^(.*)/([^/]+)\.[^/]+$">
61
			<xsl:matching-substring>
62
				<xsl:value-of select="regex-group(1)" />
63
			</xsl:matching-substring>
64
		</xsl:analyze-string>
65
	</xsl:variable>
66

    
67

    
68

    
69

    
70
	<xsl:template match="html/body">
71
		<xsl:variable name="pages">
72
			<xsl:copy>
73
				<xsl:apply-templates select="@*" />
74
				<xsl:apply-templates
75
					select="*|processing-instruction()|comment()|text()" />
76
			</xsl:copy>
77
		</xsl:variable>
78
		<xsl:for-each select="$pages">
79
			<xsl:apply-templates mode="pass2" />
80
		</xsl:for-each>
81
		<!-- creating title page with metadata -->
82
	</xsl:template>
83

    
84

    
85
	<!-- first (recursive) pass. look for <pb> elements and group on them -->
86
	<xsl:template
87
		match="comment()|@*|processing-instruction()|text()">
88
		<xsl:copy-of select="." />
89
	</xsl:template>
90

    
91
	<xsl:template match="*">
92
		<xsl:call-template name="checkpb">
93
			<xsl:with-param name="eName" select="local-name()" />
94
		</xsl:call-template>
95
	</xsl:template>
96

    
97
	<xsl:template match="a[@class='txm-page']">
98

    
99
		<!-- <xsl:variable name="next-word-position" as="xs:integer"> <xsl:choose> 
100
			<xsl:when test="following::span[@class='w']"> <xsl:value-of select="count(following::span[@class='w'][1]/preceding::span[@class='w'])"/> 
101
			</xsl:when> <xsl:otherwise>20</xsl:otherwise> </xsl:choose> </xsl:variable> 
102
			<xsl:variable name="next-pb-position" as="xs:integer"> <xsl:choose> <xsl:when 
103
			test="following::a[@class='txm-page']"> <xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::span[@class='w'])"/> 
104
			</xsl:when> <xsl:otherwise>999999999</xsl:otherwise> </xsl:choose> </xsl:variable> 
105
			<!-\-<xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::a[@class='w'])"/>-\-> 
106
			<xsl:variable name="next-word-id"> <xsl:choose> <xsl:when test="$next-pb-position 
107
			- $next-word-position = 999999999"><!-\-w_0-\-><xsl:value-of select="concat($next-pb-position,' 
108
			- ',$next-word-position)"/></xsl:when> <xsl:when test="$next-pb-position 
109
			&gt; $next-word-position"><xsl:value-of select="following::*:span[@class='w'][1]/@id"/></xsl:when> 
110
			<xsl:otherwise><!-\- w_0 -\-><xsl:value-of select="concat($next-pb-position,' 
111
			- ',$next-word-position)"/></xsl:otherwise> </xsl:choose> </xsl:variable> -->
112

    
113

    
114
		<!-- <a xmlns="http://www.w3.org/1999/xhtml"> -->
115

    
116
		<a>
117
			<xsl:copy-of select="@*" />
118
			<!--<xsl:attribute name="next-word-id"><xsl:value-of select="$next-word-id"/></xsl:attribute> -->
119
		</a>
120
	</xsl:template>
121

    
122
	<xsl:template name="checkpb">
123
		<xsl:param name="eName" />
124
		<xsl:choose>
125
			<xsl:when test="not(.//a[@class='txm-page'])">
126
				<xsl:copy-of select="." />
127
			</xsl:when>
128
			<xsl:otherwise>
129
				<xsl:variable name="pass">
130
					<xsl:call-template name="groupbypb">
131
						<xsl:with-param name="Name" select="$eName" />
132
					</xsl:call-template>
133
				</xsl:variable>
134
				<xsl:for-each select="$pass">
135
					<xsl:apply-templates />
136
				</xsl:for-each>
137
			</xsl:otherwise>
138
		</xsl:choose>
139
	</xsl:template>
140

    
141
	<xsl:template name="groupbypb">
142
		<xsl:param name="Name" />
143
		<xsl:for-each-group select="node()"
144
			group-starting-with="a[@class='txm-page']">
145
			<xsl:choose>
146
				<xsl:when test="self::a[@class='txm-page']">
147
					<xsl:copy-of select="." />
148
					<xsl:element name="{$Name}">
149
						<xsl:attribute name="rend">CONTINUED</xsl:attribute>
150
						<xsl:apply-templates
151
							select="current-group() except ." />
152
					</xsl:element>
153
				</xsl:when>
154
				<xsl:otherwise>
155
					<xsl:element name="{$Name}">
156
						<xsl:for-each select="..">
157
							<xsl:copy-of select="@*" />
158
							<xsl:apply-templates select="current-group()" />
159
						</xsl:for-each>
160
					</xsl:element>
161
				</xsl:otherwise>
162
			</xsl:choose>
163
		</xsl:for-each-group>
164
	</xsl:template>
165

    
166
	<!-- second pass. group by <pb> (now all at top level) and wrap groups in 
167
		<page> -->
168
	<xsl:template match="*" mode="pass2">
169
		<xsl:copy>
170
			<xsl:apply-templates
171
				select="@*|*|processing-instruction()|comment()|text()" mode="pass2" />
172
		</xsl:copy>
173
	</xsl:template>
174

    
175
	<xsl:template
176
		match="comment()|@*|processing-instruction()|text()" mode="pass2">
177
		<xsl:copy-of select="." />
178
	</xsl:template>
179

    
180

    
181

    
182
	<!-- <xsl:variable name="style"> <xsl:copy-of select="/html/head[1]/style[1]"></xsl:copy-of> 
183
		</xsl:variable> -->
184

    
185
	<xsl:template match="*[a[@class='txm-page']]" mode="pass2">
186

    
187
		<xsl:copy>
188
			<xsl:apply-templates select="@*" />
189
			<xsl:for-each-group select="*"
190
				group-starting-with="a[@class='txm-page']">
191
				<xsl:choose>
192
					<xsl:when test="self::a[@class='txm-page']">
193
						<xsl:comment>
194
							Page
195
							<xsl:value-of select="@title" />
196
							déplacée vers
197
							<xsl:value-of
198
								select="concat($output-directory,'/',$current-file-name,'_',@title,'.html')" />
199
						</xsl:comment>
200
						<xsl:result-document
201
							href="{$output-directory}/{$current-file-name}_{@title}.html/">
202
							<html>
203
								<head>
204
									<meta name="txm:first-word-id" content="{@next-word-id}" />
205
									<title>
206
										<xsl:value-of
207
											select="concat($current-file-name,', Page ',@title)" />
208
									</title>
209
									<meta http-equiv="Content-Type"
210
										content="text/html;charset=UTF-8" />
211
									<link rel="stylesheet" media="all" type="text/css"
212
										href="css/{$css-name-txm}.css" />
213
									<xsl:if test="matches($css-name,'\S')">
214
										<link rel="stylesheet" media="all" type="text/css"
215
											href="css/{$css-name}.css" />
216
									</xsl:if>
217
									<!--<xsl:copy-of select="$style"/> -->
218
								</head>
219
								<body>
220
									<div class="txmeditionpage">
221
										<xsl:copy-of select="current-group() except ." />
222
									</div>
223
								</body>
224
							</html>
225
						</xsl:result-document>
226

    
227
					</xsl:when>
228
					<xsl:otherwise>
229
						<xsl:copy-of select="current-group()" />
230
					</xsl:otherwise>
231
				</xsl:choose>
232
			</xsl:for-each-group>
233
		</xsl:copy>
234
	</xsl:template>
235

    
236
</xsl:stylesheet>