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

2-default-pager.xsl (revision 2398)
1 1
<?xml version="1.0" encoding="utf-8"?>
2 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"
5
  version="2.0">
6
  <!--
7
This software is dual-licensed:
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" />
8 28

  
9
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
10
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
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>
11 48

  
12
2. http://www.opensource.org/licenses/BSD-2-Clause
13
		
14
All rights reserved.
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>
15 57

  
16
Redistribution and use in source and binary forms, with or without
17
modification, are permitted provided that the following conditions are
18
met:
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>
19 66

  
20
* Redistributions of source code must retain the above copyright
21
notice, this list of conditions and the following disclaimer.
22 67

  
23
* Redistributions in binary form must reproduce the above copyright
24
notice, this list of conditions and the following disclaimer in the
25
documentation and/or other materials provided with the distribution.
26 68

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

  
39
     $Id$
40
     
41
This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz 
42
available at 
43
https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl 
44
and is adapted by Alexei Lavrentiev to split an HTML edition for 
45
TXM platform.
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>
46 83

  
47
  -->
48
  <xsl:output indent="no" method="html"/>
49
  
50
  <xsl:param name="css-name-txm">txm</xsl:param>
51
  <xsl:param name="css-name">tei</xsl:param>
52
  <xsl:param name="edition-name">default</xsl:param>
53
  <xsl:param name="number-words-per-page">999999</xsl:param>
54
  <xsl:param name="pagination-element">a[@class='txm-page']</xsl:param>
55
  <xsl:param name="output-directory"><xsl:value-of select="concat($current-file-directory,'/',$edition-name)"/></xsl:param>
56
  
57
  <xsl:variable name="current-file-name">
58
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
59
      <xsl:matching-substring>
60
        <xsl:value-of select="regex-group(2)"/>
61
      </xsl:matching-substring>
62
    </xsl:analyze-string>
63
  </xsl:variable>
64
  
65
  <xsl:variable name="current-file-directory">
66
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
67
      <xsl:matching-substring>
68
        <xsl:value-of select="regex-group(1)"/>
69
      </xsl:matching-substring>
70
    </xsl:analyze-string>
71
  </xsl:variable>
72
  
73
  
74
  
75
  
76
  <xsl:template match="html/body">
77
    <xsl:variable name="pages">
78
      <xsl:copy>
79
        <xsl:apply-templates select="@*"/>
80
        <xsl:apply-templates
81
          select="*|processing-instruction()|comment()|text()"/>
82
      </xsl:copy>
83
    </xsl:variable>
84
    <xsl:for-each select="$pages">
85
      <xsl:apply-templates  mode="pass2"/>
86
    </xsl:for-each>
87
    <!-- creating title page with metadata -->
88
  </xsl:template>
89
  
90
  
91
  <!-- first (recursive) pass. look for <pb> elements and group on them -->
92
  <xsl:template match="comment()|@*|processing-instruction()|text()">
93
    <xsl:copy-of select="."/>
94
  </xsl:template>
95
  
96
  <xsl:template match="*">
97
    <xsl:call-template name="checkpb">
98
      <xsl:with-param name="eName" select="local-name()"/>
99
    </xsl:call-template>
100
  </xsl:template>
101
  
102
  <xsl:template match="a[@class='txm-page']">
103
    
104
<!--    <xsl:variable name="next-word-position" as="xs:integer">
105
      <xsl:choose>
106
        <xsl:when test="following::span[@class='w']">
107
          <xsl:value-of select="count(following::span[@class='w'][1]/preceding::span[@class='w'])"/>
108
        </xsl:when>
109
        <xsl:otherwise>20</xsl:otherwise>
110
      </xsl:choose>
111
    </xsl:variable>
112
    <xsl:variable name="next-pb-position" as="xs:integer">
113
      <xsl:choose>
114
        <xsl:when test="following::a[@class='txm-page']">
115
          <xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::span[@class='w'])"/>
116
        </xsl:when>
117
        <xsl:otherwise>999999999</xsl:otherwise>
118
      </xsl:choose>
119
    </xsl:variable>
120
    <!-\-<xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::a[@class='w'])"/>-\->
121
    <xsl:variable name="next-word-id">
122
      <xsl:choose>
123
        <xsl:when test="$next-pb-position - $next-word-position = 999999999"><!-\-w_0-\-><xsl:value-of select="concat($next-pb-position,' - ',$next-word-position)"/></xsl:when>
124
        <xsl:when test="$next-pb-position &gt; $next-word-position"><xsl:value-of select="following::*:span[@class='w'][1]/@id"/></xsl:when>
125
        <xsl:otherwise><!-\- w_0 -\-><xsl:value-of select="concat($next-pb-position,' - ',$next-word-position)"/></xsl:otherwise>
126
      </xsl:choose>
127
    </xsl:variable>-->
128
    
129
    
130
    <!--  <a xmlns="http://www.w3.org/1999/xhtml">  -->
131
    
132
    <a>
133
      <xsl:copy-of select="@*"/>
134
      <!--<xsl:attribute name="next-word-id"><xsl:value-of select="$next-word-id"/></xsl:attribute>-->
135
    </a>
136
  </xsl:template>
137
  
138
  <xsl:template name="checkpb">
139
    <xsl:param name="eName"/>
140
    <xsl:choose>
141
      <xsl:when test="not(.//a[@class='txm-page'])">
142
        <xsl:copy-of select="."/>
143
      </xsl:when>
144
      <xsl:otherwise>
145
        <xsl:variable name="pass">
146
          <xsl:call-template name="groupbypb">
147
            <xsl:with-param name="Name" select="$eName"/>
148
          </xsl:call-template>
149
        </xsl:variable>
150
        <xsl:for-each select="$pass">
151
          <xsl:apply-templates/>
152
        </xsl:for-each>
153
      </xsl:otherwise>
154
    </xsl:choose>
155
  </xsl:template>
156
  
157
  <xsl:template name="groupbypb">
158
    <xsl:param name="Name"/>
159
    <xsl:for-each-group select="node()" group-starting-with="a[@class='txm-page']">
160
      <xsl:choose>
161
        <xsl:when test="self::a[@class='txm-page']">
162
          <xsl:copy-of select="."/>
163
          <xsl:element name="{$Name}">
164
            <xsl:attribute name="rend">CONTINUED</xsl:attribute>
165
            <xsl:apply-templates select="current-group() except ."/>
166
          </xsl:element>
167
        </xsl:when>
168
        <xsl:otherwise>
169
          <xsl:element name="{$Name}">
170
            <xsl:for-each select="..">
171
              <xsl:copy-of select="@*"/>
172
              <xsl:apply-templates select="current-group()"/>
173
            </xsl:for-each>
174
          </xsl:element>
175
        </xsl:otherwise>
176
      </xsl:choose>
177
    </xsl:for-each-group>
178
  </xsl:template>
179
  
180
  <!-- second pass. group by <pb> (now all at top level) and wrap groups
181
       in <page> -->
182
  <xsl:template match="*" mode="pass2">
183
    <xsl:copy>
184
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="pass2"/>
185
    </xsl:copy>
186
  </xsl:template>
187
  
188
  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="pass2">
189
    <xsl:copy-of select="."/>
190
  </xsl:template>
191
  
192
  
193
  
194
  <!--	<xsl:variable name="style">
195
	  <xsl:copy-of select="/html/head[1]/style[1]"></xsl:copy-of>
196
	</xsl:variable>-->
197
  
198
  <xsl:template match="*[a[@class='txm-page']]" mode="pass2" >    
199
    
200
    <xsl:copy>
201
      <xsl:apply-templates select="@*"/>
202
      <xsl:for-each-group select="*" group-starting-with="a[@class='txm-page']">
203
        <xsl:choose>
204
          <xsl:when test="self::a[@class='txm-page']">
205
            <xsl:comment> Page <xsl:value-of select="@title"/> déplacée vers <xsl:value-of select="concat($output-directory,'/',$current-file-name,'_',@title,'.html')"/></xsl:comment>
206
            <xsl:result-document href="{$output-directory}/{$current-file-name}_{@title}.html/">
207
              <html>
208
                <head>
209
                  <meta name="txm:first-word-id" content="{@next-word-id}"/>
210
                  <title><xsl:value-of select="concat($current-file-name,', Page ',@title)"/></title>
211
                  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
212
                  <link rel="stylesheet" media="all" type="text/css" href="css/{$css-name-txm}.css"/>
213
                  <xsl:if test="matches($css-name,'\S')"><link rel="stylesheet" media="all" type="text/css" href="css/{$css-name}.css"/></xsl:if>
214
                  <!--<xsl:copy-of select="$style"/>-->
215
                </head>
216
                <body>
217
                  <div class="txmeditionpage">
218
                    <xsl:copy-of select="current-group() except ."/>
219
                  </div>
220
                </body>
221
              </html>
222
            </xsl:result-document>
223
            
224
          </xsl:when>
225
          <xsl:otherwise>
226
            <xsl:copy-of select="current-group()"/>
227
          </xsl:otherwise>
228
        </xsl:choose>
229
      </xsl:for-each-group>
230
    </xsl:copy>
231
  </xsl:template>
232
  
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

  
233 236
</xsl:stylesheet>

Also available in: Unified diff