Statistics
| Revision:

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

History | View | Annotate | Download (8.8 kB)

1 476 mdecorde
<?xml version="1.0" encoding="utf-8"?>
2 476 mdecorde
<xsl:stylesheet exclude-result-prefixes="#all"
3 476 mdecorde
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 476 mdecorde
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
5 476 mdecorde
  version="2.0">
6 476 mdecorde
  <!--
7 476 mdecorde
This software is dual-licensed:
8 476 mdecorde
9 476 mdecorde
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
10 476 mdecorde
Unported License http://creativecommons.org/licenses/by-sa/3.0/
11 476 mdecorde
12 476 mdecorde
2. http://www.opensource.org/licenses/BSD-2-Clause
13 476 mdecorde
14 476 mdecorde
All rights reserved.
15 476 mdecorde
16 476 mdecorde
Redistribution and use in source and binary forms, with or without
17 476 mdecorde
modification, are permitted provided that the following conditions are
18 476 mdecorde
met:
19 476 mdecorde
20 476 mdecorde
* Redistributions of source code must retain the above copyright
21 476 mdecorde
notice, this list of conditions and the following disclaimer.
22 476 mdecorde
23 476 mdecorde
* Redistributions in binary form must reproduce the above copyright
24 476 mdecorde
notice, this list of conditions and the following disclaimer in the
25 476 mdecorde
documentation and/or other materials provided with the distribution.
26 476 mdecorde
27 476 mdecorde
This software is provided by the copyright holders and contributors
28 476 mdecorde
"as is" and any express or implied warranties, including, but not
29 476 mdecorde
limited to, the implied warranties of merchantability and fitness for
30 476 mdecorde
a particular purpose are disclaimed. In no event shall the copyright
31 476 mdecorde
holder or contributors be liable for any direct, indirect, incidental,
32 476 mdecorde
special, exemplary, or consequential damages (including, but not
33 476 mdecorde
limited to, procurement of substitute goods or services; loss of use,
34 476 mdecorde
data, or profits; or business interruption) however caused and on any
35 476 mdecorde
theory of liability, whether in contract, strict liability, or tort
36 476 mdecorde
(including negligence or otherwise) arising in any way out of the use
37 476 mdecorde
of this software, even if advised of the possibility of such damage.
38 476 mdecorde
39 476 mdecorde
     $Id$
40 476 mdecorde
41 476 mdecorde
This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz
42 476 mdecorde
available at
43 476 mdecorde
https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl
44 476 mdecorde
and is adapted by Alexei Lavrentiev to split an HTML edition for
45 476 mdecorde
TXM platform.
46 476 mdecorde
47 476 mdecorde
  -->
48 476 mdecorde
  <xsl:output indent="no" method="html"/>
49 476 mdecorde
50 476 mdecorde
  <xsl:param name="css-name-txm">txm</xsl:param>
51 476 mdecorde
  <xsl:param name="css-name">tei</xsl:param>
52 476 mdecorde
  <xsl:param name="edition-name">default</xsl:param>
53 476 mdecorde
  <xsl:param name="number-words-per-page">999999</xsl:param>
54 476 mdecorde
  <xsl:param name="pagination-element">a[@class='txm-page']</xsl:param>
55 476 mdecorde
  <xsl:param name="output-directory"><xsl:value-of select="concat($current-file-directory,'/',$edition-name)"/></xsl:param>
56 476 mdecorde
57 476 mdecorde
  <xsl:variable name="current-file-name">
58 476 mdecorde
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
59 476 mdecorde
      <xsl:matching-substring>
60 476 mdecorde
        <xsl:value-of select="regex-group(2)"/>
61 476 mdecorde
      </xsl:matching-substring>
62 476 mdecorde
    </xsl:analyze-string>
63 476 mdecorde
  </xsl:variable>
64 476 mdecorde
65 476 mdecorde
  <xsl:variable name="current-file-directory">
66 476 mdecorde
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
67 476 mdecorde
      <xsl:matching-substring>
68 476 mdecorde
        <xsl:value-of select="regex-group(1)"/>
69 476 mdecorde
      </xsl:matching-substring>
70 476 mdecorde
    </xsl:analyze-string>
71 476 mdecorde
  </xsl:variable>
72 476 mdecorde
73 476 mdecorde
74 476 mdecorde
75 476 mdecorde
76 476 mdecorde
  <xsl:template match="html/body">
77 476 mdecorde
    <xsl:variable name="pages">
78 476 mdecorde
      <xsl:copy>
79 476 mdecorde
        <xsl:apply-templates select="@*"/>
80 476 mdecorde
        <xsl:apply-templates
81 476 mdecorde
          select="*|processing-instruction()|comment()|text()"/>
82 476 mdecorde
      </xsl:copy>
83 476 mdecorde
    </xsl:variable>
84 476 mdecorde
    <xsl:for-each select="$pages">
85 476 mdecorde
      <xsl:apply-templates  mode="pass2"/>
86 476 mdecorde
    </xsl:for-each>
87 476 mdecorde
    <!-- creating title page with metadata -->
88 476 mdecorde
  </xsl:template>
89 476 mdecorde
90 476 mdecorde
91 476 mdecorde
  <!-- first (recursive) pass. look for <pb> elements and group on them -->
92 476 mdecorde
  <xsl:template match="comment()|@*|processing-instruction()|text()">
93 476 mdecorde
    <xsl:copy-of select="."/>
94 476 mdecorde
  </xsl:template>
95 476 mdecorde
96 476 mdecorde
  <xsl:template match="*">
97 476 mdecorde
    <xsl:call-template name="checkpb">
98 476 mdecorde
      <xsl:with-param name="eName" select="local-name()"/>
99 476 mdecorde
    </xsl:call-template>
100 476 mdecorde
  </xsl:template>
101 476 mdecorde
102 476 mdecorde
  <xsl:template match="a[@class='txm-page']">
103 476 mdecorde
104 476 mdecorde
<!--    <xsl:variable name="next-word-position" as="xs:integer">
105 476 mdecorde
      <xsl:choose>
106 476 mdecorde
        <xsl:when test="following::span[@class='w']">
107 476 mdecorde
          <xsl:value-of select="count(following::span[@class='w'][1]/preceding::span[@class='w'])"/>
108 476 mdecorde
        </xsl:when>
109 476 mdecorde
        <xsl:otherwise>20</xsl:otherwise>
110 476 mdecorde
      </xsl:choose>
111 476 mdecorde
    </xsl:variable>
112 476 mdecorde
    <xsl:variable name="next-pb-position" as="xs:integer">
113 476 mdecorde
      <xsl:choose>
114 476 mdecorde
        <xsl:when test="following::a[@class='txm-page']">
115 476 mdecorde
          <xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::span[@class='w'])"/>
116 476 mdecorde
        </xsl:when>
117 476 mdecorde
        <xsl:otherwise>999999999</xsl:otherwise>
118 476 mdecorde
      </xsl:choose>
119 476 mdecorde
    </xsl:variable>
120 476 mdecorde
    <!-\-<xsl:value-of select="count(following::a[@class='txm-page'][1]/preceding::a[@class='w'])"/>-\->
121 476 mdecorde
    <xsl:variable name="next-word-id">
122 476 mdecorde
      <xsl:choose>
123 476 mdecorde
        <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 476 mdecorde
        <xsl:when test="$next-pb-position &gt; $next-word-position"><xsl:value-of select="following::*:span[@class='w'][1]/@id"/></xsl:when>
125 476 mdecorde
        <xsl:otherwise><!-\- w_0 -\-><xsl:value-of select="concat($next-pb-position,' - ',$next-word-position)"/></xsl:otherwise>
126 476 mdecorde
      </xsl:choose>
127 476 mdecorde
    </xsl:variable>-->
128 476 mdecorde
129 476 mdecorde
130 476 mdecorde
    <!--  <a xmlns="http://www.w3.org/1999/xhtml">  -->
131 476 mdecorde
132 476 mdecorde
    <a>
133 476 mdecorde
      <xsl:copy-of select="@*"/>
134 476 mdecorde
      <!--<xsl:attribute name="next-word-id"><xsl:value-of select="$next-word-id"/></xsl:attribute>-->
135 476 mdecorde
    </a>
136 476 mdecorde
  </xsl:template>
137 476 mdecorde
138 476 mdecorde
  <xsl:template name="checkpb">
139 476 mdecorde
    <xsl:param name="eName"/>
140 476 mdecorde
    <xsl:choose>
141 476 mdecorde
      <xsl:when test="not(.//a[@class='txm-page'])">
142 476 mdecorde
        <xsl:copy-of select="."/>
143 476 mdecorde
      </xsl:when>
144 476 mdecorde
      <xsl:otherwise>
145 476 mdecorde
        <xsl:variable name="pass">
146 476 mdecorde
          <xsl:call-template name="groupbypb">
147 476 mdecorde
            <xsl:with-param name="Name" select="$eName"/>
148 476 mdecorde
          </xsl:call-template>
149 476 mdecorde
        </xsl:variable>
150 476 mdecorde
        <xsl:for-each select="$pass">
151 476 mdecorde
          <xsl:apply-templates/>
152 476 mdecorde
        </xsl:for-each>
153 476 mdecorde
      </xsl:otherwise>
154 476 mdecorde
    </xsl:choose>
155 476 mdecorde
  </xsl:template>
156 476 mdecorde
157 476 mdecorde
  <xsl:template name="groupbypb">
158 476 mdecorde
    <xsl:param name="Name"/>
159 476 mdecorde
    <xsl:for-each-group select="node()" group-starting-with="a[@class='txm-page']">
160 476 mdecorde
      <xsl:choose>
161 476 mdecorde
        <xsl:when test="self::a[@class='txm-page']">
162 476 mdecorde
          <xsl:copy-of select="."/>
163 476 mdecorde
          <xsl:element name="{$Name}">
164 476 mdecorde
            <xsl:attribute name="rend">CONTINUED</xsl:attribute>
165 476 mdecorde
            <xsl:apply-templates select="current-group() except ."/>
166 476 mdecorde
          </xsl:element>
167 476 mdecorde
        </xsl:when>
168 476 mdecorde
        <xsl:otherwise>
169 476 mdecorde
          <xsl:element name="{$Name}">
170 476 mdecorde
            <xsl:for-each select="..">
171 476 mdecorde
              <xsl:copy-of select="@*"/>
172 476 mdecorde
              <xsl:apply-templates select="current-group()"/>
173 476 mdecorde
            </xsl:for-each>
174 476 mdecorde
          </xsl:element>
175 476 mdecorde
        </xsl:otherwise>
176 476 mdecorde
      </xsl:choose>
177 476 mdecorde
    </xsl:for-each-group>
178 476 mdecorde
  </xsl:template>
179 476 mdecorde
180 476 mdecorde
  <!-- second pass. group by <pb> (now all at top level) and wrap groups
181 476 mdecorde
       in <page> -->
182 476 mdecorde
  <xsl:template match="*" mode="pass2">
183 476 mdecorde
    <xsl:copy>
184 476 mdecorde
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="pass2"/>
185 476 mdecorde
    </xsl:copy>
186 476 mdecorde
  </xsl:template>
187 476 mdecorde
188 476 mdecorde
  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="pass2">
189 476 mdecorde
    <xsl:copy-of select="."/>
190 476 mdecorde
  </xsl:template>
191 476 mdecorde
192 476 mdecorde
193 476 mdecorde
194 476 mdecorde
  <!--	<xsl:variable name="style">
195 476 mdecorde
	  <xsl:copy-of select="/html/head[1]/style[1]"></xsl:copy-of>
196 476 mdecorde
	</xsl:variable>-->
197 476 mdecorde
198 476 mdecorde
  <xsl:template match="*[a[@class='txm-page']]" mode="pass2" >
199 476 mdecorde
200 476 mdecorde
    <xsl:copy>
201 476 mdecorde
      <xsl:apply-templates select="@*"/>
202 476 mdecorde
      <xsl:for-each-group select="*" group-starting-with="a[@class='txm-page']">
203 476 mdecorde
        <xsl:choose>
204 476 mdecorde
          <xsl:when test="self::a[@class='txm-page']">
205 476 mdecorde
            <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 476 mdecorde
            <xsl:result-document href="{$output-directory}/{$current-file-name}_{@title}.html/">
207 476 mdecorde
              <html>
208 476 mdecorde
                <head>
209 476 mdecorde
                  <meta name="txm:first-word-id" content="{@next-word-id}"/>
210 476 mdecorde
                  <title><xsl:value-of select="concat($current-file-name,', Page ',@title)"/></title>
211 476 mdecorde
                  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
212 476 mdecorde
                  <link rel="stylesheet" media="all" type="text/css" href="css/{$css-name-txm}.css"/>
213 476 mdecorde
                  <xsl:if test="matches($css-name,'\S')"><link rel="stylesheet" media="all" type="text/css" href="css/{$css-name}.css"/></xsl:if>
214 476 mdecorde
                  <!--<xsl:copy-of select="$style"/>-->
215 476 mdecorde
                </head>
216 476 mdecorde
                <body>
217 476 mdecorde
                  <div class="txmeditionpage">
218 476 mdecorde
                    <xsl:copy-of select="current-group() except ."/>
219 476 mdecorde
                  </div>
220 476 mdecorde
                </body>
221 476 mdecorde
              </html>
222 476 mdecorde
            </xsl:result-document>
223 476 mdecorde
224 476 mdecorde
          </xsl:when>
225 476 mdecorde
          <xsl:otherwise>
226 476 mdecorde
            <xsl:copy-of select="current-group()"/>
227 476 mdecorde
          </xsl:otherwise>
228 476 mdecorde
        </xsl:choose>
229 476 mdecorde
      </xsl:for-each-group>
230 476 mdecorde
    </xsl:copy>
231 476 mdecorde
  </xsl:template>
232 476 mdecorde
233 476 mdecorde
</xsl:stylesheet>