Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / 2-default-pager.xsl @ 187

History | View | Annotate | Download (9.1 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"
5
  version="2.0">
6
  <!--
7
This software is dual-licensed:
8

    
9
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
10
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
11

    
12
2. http://www.opensource.org/licenses/BSD-2-Clause
13
		
14
All rights reserved.
15

    
16
Redistribution and use in source and binary forms, with or without
17
modification, are permitted provided that the following conditions are
18
met:
19

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

    
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

    
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

    
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.
46

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