Statistics
| Revision:

root / tmp / org.txm.oriflamms.rcp / groovy / org / txm / macro / oriflamms / prepare / 1-oriflamms-split-surfaces.xsl @ 1094

History | View | Annotate | Download (8.1 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet
3
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
		xmlns:xd="http://www.pnp-software.com/XSLTdoc"
5
		xmlns:tei="http://www.tei-c.org/ns/1.0"
6
		version="2.0" xpath-default-namespace="http://www.tei-c.org/ns/1.0">
7

    
8
  <xd:doc type="stylesheet">
9
    <xd:short>
10
      Cette feuille permet de découper un fichier XML TEI Oriflamms en pages
11
      avant de procéder à la tokénisation au niveau de caractère.
12
    </xd:short>
13
    <xd:detail>
14
      This software is dual-licensed:
15
      
16
      1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
17
      Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
18
      
19
      2. http://www.opensource.org/licenses/BSD-2-Clause
20
      
21
      All rights reserved.
22
      
23
      Redistribution and use in source and binary forms, with or without
24
      modification, are permitted provided that the following conditions are
25
      met:
26
      
27
      * Redistributions of source code must retain the above copyright
28
      notice, this list of conditions and the following disclaimer.
29
      
30
      * Redistributions in binary form must reproduce the above copyright
31
      notice, this list of conditions and the following disclaimer in the
32
      documentation and/or other materials provided with the distribution.
33
      
34
      This software is provided by the copyright holders and contributors
35
      "as is" and any express or implied warranties, including, but not
36
      limited to, the implied warranties of merchantability and fitness for
37
      a particular purpose are disclaimed. In no event shall the copyright
38
      holder or contributors be liable for any direct, indirect, incidental,
39
      special, exemplary, or consequential damages (including, but not
40
      limited to, procurement of substitute goods or services; loss of use,
41
      data, or profits; or business interruption) however caused and on any
42
      theory of liability, whether in contract, strict liability, or tort
43
      (including negligence or otherwise) arising in any way out of the use
44
      of this software, even if advised of the possibility of such damage.
45
      
46
      $Id$
47
      
48
      This stylesheet is based on TEI processpb.xsl by Sebastian Rahtz 
49
      available at 
50
      https://github.com/TEIC/Stylesheets/blob/master/tools/processpb.xsl 
51
      and is adapted by Alexei Lavrentiev to split an XML TEI Oriflamms file
52
      into pages for further tokenizatrion at character level.
53
      
54
    </xd:detail>
55
    <xd:author>Alexei Lavrentiev alexei.lavrentev@ens-lyon.fr</xd:author>
56
    <xd:copyright>2015, CNRS / ICAR (Équipe CACTUS)</xd:copyright>
57
  </xd:doc>
58
  
59
  
60
  
61
  <xsl:output indent="no" method="xml"/>
62

    
63

    
64
  <xsl:variable name="filename">
65
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
66
      <xsl:matching-substring>
67
        <xsl:value-of select="regex-group(2)"/>
68
      </xsl:matching-substring>
69
    </xsl:analyze-string>
70
  </xsl:variable>
71
  
72
  <xsl:variable name="filedir">
73
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
74
      <xsl:matching-substring>
75
        <xsl:value-of select="regex-group(1)"/>
76
      </xsl:matching-substring>
77
    </xsl:analyze-string>
78
  </xsl:variable>
79
  
80
  <!--<xsl:variable name="filenameresult">
81
    <xsl:value-of select="replace($filename,'(-ori)?-w$','')"/>
82
  </xsl:variable>-->
83

    
84
  <xsl:param name="output-directory"><xsl:value-of select="concat($filedir,'/out')"/></xsl:param>
85

    
86
 
87
  <xsl:template match="teiHeader">
88
    <!--<xsl:copy-of select="."/>-->
89
  </xsl:template>
90
  
91
  <xsl:template match="TEI|teiCorpus|group|text">
92
    <xsl:copy>
93
      <xsl:apply-templates select="@*"/>
94
      <xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
95
    </xsl:copy>
96
  </xsl:template>
97

    
98

    
99
  <xsl:template match="text/body|text/back|text/front">
100
      <xsl:variable name="pages">
101
	<xsl:copy>
102
	  <xsl:apply-templates select="@*"/>
103
	  <xsl:apply-templates
104
	      select="*|processing-instruction()|comment()|text()"/>
105
	</xsl:copy>
106
      </xsl:variable>
107
      <xsl:for-each select="$pages">
108
	<xsl:apply-templates  mode="pass2"/>
109
      </xsl:for-each>
110
  </xsl:template>
111

    
112

    
113
 <!-- first (recursive) pass. look for <pb> elements and group on them -->
114
  <xsl:template match="comment()|@*|processing-instruction()|text()">
115
    <xsl:copy-of select="."/>
116
  </xsl:template>
117

    
118
  <xsl:template match="*">
119
    <xsl:call-template name="checkpb">
120
      <xsl:with-param name="eName" select="local-name()"/>
121
    </xsl:call-template>
122
  </xsl:template>
123

    
124
  <xsl:template match="milestone[@unit='surface']">
125
    <xsl:copy-of select="."/>
126
  </xsl:template>
127

    
128
  <xsl:template name="checkpb">
129
    <xsl:param name="eName"/>
130
    <xsl:choose>
131
      <xsl:when test="not(.//milestone[@unit='surface'])">
132
        <xsl:copy-of select="."/>
133
      </xsl:when>
134
      <xsl:otherwise>
135
        <xsl:variable name="pass">
136
	  <xsl:call-template name="groupbypb">
137
	    <xsl:with-param name="Name" select="$eName"/>
138
	  </xsl:call-template>
139
        </xsl:variable>
140
	<xsl:for-each select="$pass">
141
	  <xsl:apply-templates/>
142
	</xsl:for-each>
143
      </xsl:otherwise>
144
    </xsl:choose>
145
  </xsl:template>
146

    
147
  <xsl:template name="groupbypb">
148
    <xsl:param name="Name"/>
149
    <xsl:for-each-group select="node()" group-starting-with="milestone[@unit='surface']">
150
      <xsl:choose>
151
        <xsl:when test="self::milestone[@unit='surface']">
152
          <xsl:copy-of select="."/>
153
          <xsl:element name="{$Name}" namespace="http://www.w3.org/1999/xhtml">
154
	    <xsl:attribute name="rend">CONTINUED</xsl:attribute>
155
            <xsl:apply-templates select="current-group() except ."/>
156
          </xsl:element>
157
        </xsl:when>
158
        <xsl:otherwise>
159
          <xsl:element name="{$Name}" namespace="http://www.w3.org/1999/xhtml">
160
            <xsl:for-each select="..">
161
              <xsl:copy-of select="@*"/>
162
              <xsl:apply-templates select="current-group()"/>
163
            </xsl:for-each>
164
          </xsl:element>
165
        </xsl:otherwise>
166
      </xsl:choose>
167
    </xsl:for-each-group>
168
  </xsl:template>
169

    
170
  <!-- second pass. group by <pb> (now all at top level) and wrap groups
171
       in <page> -->
172
  <xsl:template match="*" mode="pass2">
173
    <xsl:copy>
174
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="pass2"/>
175
    </xsl:copy>
176
  </xsl:template>
177

    
178
  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="pass2">
179
    <xsl:copy-of select="."/>
180
  </xsl:template>
181

    
182

    
183
  <xsl:template match="*[milestone[@unit='surface']]" mode="pass2" >
184
    <xsl:copy>
185
      <xsl:apply-templates select="@*"/>
186
      <xsl:for-each-group select="*" group-starting-with="milestone[@unit='surface']">
187
        <xsl:choose>
188
          <xsl:when test="self::milestone[@unit='surface']">
189
          	<xsl:comment> Page <xsl:value-of select="@xml:id"/> enregistrée dans <xsl:value-of select="concat($output-directory,'/',$filename,'_',@xml:id,'.xml')"/></xsl:comment>
190
            <xsl:text>&#xA;</xsl:text>
191
          	<xsl:result-document href="{$output-directory}/{$filename}_{@xml:id}.xml" indent="yes">
192
          	<TEI>
193
          	  <teiHeader>
194
          	    <fileDesc>
195
          	      <titleStmt>
196
          	        <title>Page <xsl:value-of select="@xml:id"/> of <xsl:value-of select="$filename"/> tokenized at character level.</title>
197
          	      </titleStmt>
198
          	      <publicationStmt>
199
          	        <p>Oriflamms project (http://oriflamms.hypotheses.org)</p>
200
          	      </publicationStmt>
201
          	      <sourceDesc>
202
          	        <p>Converted from <xsl:value-of select="$filename"/>.</p>
203
          	      </sourceDesc>
204
          	    </fileDesc>
205
          	    <revisionDesc>
206
          	      <change when="{current-dateTime()}">File created.</change>
207
          	    </revisionDesc>
208
          	  </teiHeader>
209
          	  <text>
210
          	    <body>
211
          	      <xsl:copy-of select="."/>
212
        	        <xsl:copy-of select="current-group() except ."/>
213
          	    </body>
214
          	  </text>
215
          	</TEI>
216
          	</xsl:result-document>
217
          </xsl:when>
218
          <xsl:otherwise>
219
            <xsl:copy-of select="current-group()"/>
220
          </xsl:otherwise>
221
        </xsl:choose>
222
      </xsl:for-each-group>
223
    </xsl:copy>
224
  </xsl:template>
225

    
226
</xsl:stylesheet>