Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / tools / processpb.xsl @ 187

History | View | Annotate | Download (5.6 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns="http://www.tei-c.org/ns/1.0"
3
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
		xpath-default-namespace="http://www.tei-c.org/ns/1.0"
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: processpb.xsl 9646 2011-11-05 23:39:08Z rahtz $
40

    
41
    Take an arbitrary TEI file and move page breaks (<pb>) up in the
42
    hierarchy, splitting containers as needed, until <pb>s are at the
43
    same level as <div>. Wrap the resulting pages on <page> element.
44
-->
45
  <xsl:output indent="yes"/>
46

    
47
  <xsl:template match="teiHeader">
48
    <xsl:copy-of select="."/>
49
  </xsl:template>
50

    
51
  <xsl:template match="TEI|teiCorpus|group">
52
    <xsl:copy>
53
      <xsl:apply-templates select="@*"/>
54
      <xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
55
    </xsl:copy>
56
  </xsl:template>
57

    
58
  <xsl:template match="text|body|back|front">
59
    <xsl:copy>
60
      <xsl:apply-templates select="@*"/>
61
      <xsl:variable name="pages">
62
        <xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
63
      </xsl:variable>
64
      <xsl:for-each select="$pages">
65
        <xsl:apply-templates select="*|processing-instruction()|comment()|text()" mode="pass2"/>
66
      </xsl:for-each>
67
    </xsl:copy>
68
  </xsl:template>
69

    
70

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

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

    
82
  <xsl:template match="pb">
83
    <pb>
84
      <xsl:copy-of select="@*"/>
85
    </pb>
86
  </xsl:template>
87

    
88
  <xsl:template name="checkpb">
89
    <xsl:param name="eName"/>
90
    <xsl:choose>
91
      <xsl:when test="not(.//pb)">
92
        <xsl:copy>
93
          <xsl:apply-templates select="@*"/>
94
          <xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
95
        </xsl:copy>
96
      </xsl:when>
97
      <xsl:otherwise>
98
        <xsl:variable name="pass">
99
          <xsl:call-template name="groupbypb">
100
            <xsl:with-param name="Name" select="$eName"/>
101
          </xsl:call-template>
102
        </xsl:variable>
103
        <xsl:for-each select="$pass">
104
          <xsl:apply-templates/>
105
        </xsl:for-each>
106
      </xsl:otherwise>
107
    </xsl:choose>
108
  </xsl:template>
109

    
110
  <xsl:template name="groupbypb">
111
    <xsl:param name="Name"/>
112
    <xsl:for-each-group select="node()" group-starting-with="pb">
113
      <xsl:choose>
114
        <xsl:when test="self::pb">
115
          <xsl:copy-of select="."/>
116
          <xsl:element name="{$Name}">
117
	    <xsl:attribute name="rend">CONTINUED</xsl:attribute>
118
            <xsl:apply-templates select="current-group() except ."/>
119
          </xsl:element>
120
        </xsl:when>
121
        <xsl:otherwise>
122
          <xsl:element name="{$Name}">
123
            <xsl:for-each select="..">
124
              <xsl:copy-of select="@*"/>
125
              <xsl:apply-templates select="current-group()"/>
126
            </xsl:for-each>
127
          </xsl:element>
128
        </xsl:otherwise>
129
      </xsl:choose>
130
    </xsl:for-each-group>
131
  </xsl:template>
132

    
133
  <!-- second pass. group by <pb> (now all at top level) and wrap groups
134
       in <page> -->
135
  <xsl:template match="*" mode="pass2">
136
    <xsl:copy>
137
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="pass2"/>
138
    </xsl:copy>
139
  </xsl:template>
140

    
141
  <xsl:template match="*[pb]" mode="pass2">
142
    <xsl:copy>
143
      <xsl:apply-templates select="@*"/>
144
      <xsl:for-each-group select="*" group-starting-with="pb">
145
        <xsl:choose>
146
          <xsl:when test="self::pb">
147
            <page xmlns="http://www.tei-c.org/ns/notTEI"> 
148
              <xsl:copy-of select="@*"/>
149
              <xsl:copy-of select="current-group() except ."/>
150
            </page>
151
          </xsl:when>
152
          <xsl:otherwise>
153
            <xsl:copy-of select="current-group()"/>
154
          </xsl:otherwise>
155
        </xsl:choose>
156
      </xsl:for-each-group>
157
    </xsl:copy>
158
  </xsl:template>
159

    
160
  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="pass2">
161
    <xsl:copy-of select="."/>
162
  </xsl:template>
163

    
164
</xsl:stylesheet>