Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / txm-edition-page-split.xsl @ 187

History | View | Annotate | Download (6.9 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet
3
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
		version="2.0" xpath-default-namespace="http://www.w3.org/1999/xhtml">
5
<!--
6
This software is dual-licensed:
7

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

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

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

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

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

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

    
38
     $Id$
39

    
40
This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz 
41
available at 
42
https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl 
43
and is adapted by Alexei Lavrentiev to split an HTML edition for 
44
TXM platform.
45

    
46
  -->
47
  <xsl:output indent="no" method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
48

    
49
  <xsl:param name="cssname-txm">txm</xsl:param>
50
	<xsl:param name="cssname">tei</xsl:param>
51
	<xsl:param name="editionname">default</xsl:param>
52

    
53
  <xsl:template match="html/body">
54
      <xsl:variable name="pages">
55
	<xsl:copy>
56
	  <xsl:apply-templates select="@*"/>
57
	  <xsl:apply-templates
58
	      select="*|processing-instruction()|comment()|text()"/>
59
	</xsl:copy>
60
      </xsl:variable>
61
      <xsl:for-each select="$pages">
62
	<xsl:apply-templates  mode="pass2"/>
63
      </xsl:for-each>
64
    <!-- creating title page with metadata -->
65
  </xsl:template>
66

    
67

    
68
 <!-- first (recursive) pass. look for <pb> elements and group on them -->
69
  <xsl:template match="comment()|@*|processing-instruction()|text()">
70
    <xsl:copy-of select="."/>
71
  </xsl:template>
72

    
73
  <xsl:template match="*">
74
    <xsl:call-template name="checkpb">
75
      <xsl:with-param name="eName" select="local-name()"/>
76
    </xsl:call-template>
77
  </xsl:template>
78

    
79
  <xsl:template match="a[@class='txm-page']">
80
    <a xmlns="http://www.w3.org/1999/xhtml">
81
      <xsl:copy-of select="@*"/>
82
    </a>
83
  </xsl:template>
84

    
85
  <xsl:template name="checkpb">
86
    <xsl:param name="eName"/>
87
    <xsl:choose>
88
      <xsl:when test="not(.//a[@class='txm-page'])">
89
        <xsl:copy-of select="."/>
90
      </xsl:when>
91
      <xsl:otherwise>
92
        <xsl:variable name="pass">
93
	  <xsl:call-template name="groupbypb">
94
	    <xsl:with-param name="Name" select="$eName"/>
95
	  </xsl:call-template>
96
        </xsl:variable>
97
	<xsl:for-each select="$pass">
98
	  <xsl:apply-templates/>
99
	</xsl:for-each>
100
      </xsl:otherwise>
101
    </xsl:choose>
102
  </xsl:template>
103

    
104
  <xsl:template name="groupbypb">
105
    <xsl:param name="Name"/>
106
    <xsl:for-each-group select="node()" group-starting-with="a[@class='txm-page']">
107
      <xsl:choose>
108
        <xsl:when test="self::a[@class='txm-page']">
109
          <xsl:copy-of select="."/>
110
          <xsl:element name="{$Name}" namespace="http://www.w3.org/1999/xhtml">
111
	    <xsl:attribute name="rend">CONTINUED</xsl:attribute>
112
            <xsl:apply-templates select="current-group() except ."/>
113
          </xsl:element>
114
        </xsl:when>
115
        <xsl:otherwise>
116
          <xsl:element name="{$Name}" namespace="http://www.w3.org/1999/xhtml">
117
            <xsl:for-each select="..">
118
              <xsl:copy-of select="@*"/>
119
              <xsl:apply-templates select="current-group()"/>
120
            </xsl:for-each>
121
          </xsl:element>
122
        </xsl:otherwise>
123
      </xsl:choose>
124
    </xsl:for-each-group>
125
  </xsl:template>
126

    
127
  <!-- second pass. group by <pb> (now all at top level) and wrap groups
128
       in <page> -->
129
  <xsl:template match="*" mode="pass2">
130
    <xsl:copy>
131
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="pass2"/>
132
    </xsl:copy>
133
  </xsl:template>
134

    
135
  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="pass2">
136
    <xsl:copy-of select="."/>
137
  </xsl:template>
138

    
139
	<xsl:variable name="filename">
140
		<xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
141
			<xsl:matching-substring>
142
				<xsl:value-of select="regex-group(2)"/>
143
			</xsl:matching-substring>
144
		</xsl:analyze-string>
145
	</xsl:variable>
146
	
147
	<xsl:variable name="filedir">
148
		<xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
149
			<xsl:matching-substring>
150
				<xsl:value-of select="regex-group(1)"/>
151
			</xsl:matching-substring>
152
		</xsl:analyze-string>
153
	</xsl:variable>
154
	
155
	
156
<!--	<xsl:variable name="style">
157
	  <xsl:copy-of select="/html/head[1]/style[1]"></xsl:copy-of>
158
	</xsl:variable>-->
159

    
160
  <xsl:template match="*[a[@class='txm-page']]" mode="pass2" >
161
    <xsl:copy>
162
      <xsl:apply-templates select="@*"/>
163
      <xsl:for-each-group select="*" group-starting-with="a[@class='txm-page']">
164
        <xsl:choose>
165
          <xsl:when test="self::a[@class='txm-page']">
166
          	<xsl:comment> Page <xsl:value-of select="@title"/> déplacée vers <xsl:value-of select="concat($filedir,'/',$editionname,'/',$filename,'_',@title,'.html')"/></xsl:comment>
167
          	<xsl:result-document href="{$filedir}/{$editionname}/{$filename}_{@title}.html">
168
          	<html>
169
          		<head>
170
          			<title><xsl:value-of select="concat($filename,', Page ',@title)"/></title>
171
          			<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
172
          			<link rel="stylesheet" media="all" type="text/css" href="css/{$cssname-txm}.css"/>
173
          			<xsl:if test="matches($cssname,'\S')"><link rel="stylesheet" media="all" type="text/css" href="css/{$cssname}.css"/></xsl:if>
174
          		  <!--<xsl:copy-of select="$style"/>-->
175
          		</head>
176
          		<body>
177
          		  <div class="txmeditionpage">
178
          			  <xsl:copy-of select="current-group() except ."/>
179
          			</div>
180
          		</body>
181
          	</html>
182
          	</xsl:result-document>
183

    
184
          </xsl:when>
185
          <xsl:otherwise>
186
            <xsl:copy-of select="current-group()"/>
187
          </xsl:otherwise>
188
        </xsl:choose>
189
      </xsl:for-each-group>
190
    </xsl:copy>
191
  </xsl:template>
192

    
193
</xsl:stylesheet>