Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / oriflamms / prepare / 2-default-pager.xsl @ 479

History | View | Annotate | Download (8.8 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">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
  
233
</xsl:stylesheet>