-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork2tei.xsl
189 lines (187 loc) · 6.68 KB
/
work2tei.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:alto="http://bibnum.bnf.fr/ns/alto_prod"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="alto tei"
>
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:variable name="gallica" select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:sourceDesc/*/tei:idno"/>
<xsl:variable name="lf" select="' '"/>
<xsl:variable name="num">0123456789</xsl:variable>
<!-- Majuscules, pour conversions. -->
<xsl:variable name="caps">ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒÇÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ</xsl:variable>
<!-- Minuscules, pour conversions -->
<xsl:variable name="mins">abcdefghijklmnopqrstuvwxyzæœçàáâãäåèéêëìíîïòóôõöùúûüý</xsl:variable>
<xsl:template match="/">
<!-- Inutile de valider encore
<xsl:processing-instruction name="xml-model">href="http://svn.code.sf.net/p/algone/code/teibook/teibook.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction>
-->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:body">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*"/>
<xsl:call-template name="divClose">
<xsl:with-param name="n" select=".//tei:head[position() = last()]/@n"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:book">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="tei:page">
<pb>
<xsl:copy-of select="@xml:id|@xml:type"/>
<xsl:attribute name="n">
<xsl:value-of select="tei:fw"/>
</xsl:attribute>
<xsl:variable name="f" select="number( substring-after(@xml:id, 'PAG_') )"/>
<xsl:if test="$gallica and $f > 0">
<xsl:attribute name="corresp">
<xsl:value-of select="$gallica"/>
<xsl:text>/f</xsl:text>
<xsl:value-of select="$f"/>
<xsl:text>.image</xsl:text>
</xsl:attribute>
</xsl:if>
</pb>
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="divClose">
<xsl:param name="n"/>
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:processing-instruction name="div">/</xsl:processing-instruction>
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="$n - 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="divOpen">
<xsl:param name="n"/>
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:processing-instruction name="div"/>
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="$n - 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- TODO, get prev <pb> -->
<xsl:template match="tei:head">
<xsl:variable name="level" select="@n"/>
<xsl:variable name="prev" select="preceding::tei:head[1]/@n"/>
<xsl:choose>
<xsl:when test="$prev">
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="1+ $prev - $level"/>
</xsl:call-template>
</xsl:when>
<!-- no prev, no close
<xsl:otherwise>
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="1"/>
</xsl:call-template>
</xsl:otherwise>
-->
</xsl:choose>
<!-- Always one -->
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="1"/>
</xsl:call-template>
<!-- Sometimes more -->
<xsl:variable name="open">
<xsl:choose>
<xsl:when test="$prev">
<xsl:value-of select="$level - $prev - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$level - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="$open"/>
</xsl:call-template>
<xsl:copy>
<!--
<xsl:copy-of select="@n"/>
-->
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:b | tei:i | tei:sub | tei:u ">
<hi rend="{local-name()}">
<xsl:apply-templates/>
</hi>
</xsl:template>
<xsl:template match="tei:sup">
<xsl:variable name="text" select="."/>
<xsl:choose>
<xsl:when test="translate(., $num, '') != ''">
<hi rend="sup">
<xsl:apply-templates/>
</hi>
</xsl:when>
<!-- Tentative de raccrochage de note, ratée
<xsl:when test="ancestor::tei:page/*[starts-with(normalize-space(.), $text)][*[1][local-name()='small']]">
<note>
<xsl:attribute name="xml:id">
<xsl:value-of select="ancestor::tei:page/@xml:id"/>
<xsl:text>-note</xsl:text>
<xsl:value-of select="$text"/>
</xsl:attribute>
<xsl:value-of select="$lf"/>
<xsl:apply-templates select="ancestor::tei:page/*[starts-with(normalize-space(.), $text)][*[1][local-name()='small']]/*/node()"/>
<xsl:value-of select="$lf"/>
</note>
</xsl:when>
-->
<xsl:otherwise>
<hi rend="sup">
<xsl:apply-templates/>
</hi>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Attention aux blocs qui raccrochent par erreur une ligne <small>
*[tei:small and not(*[local-name()!='small'])]
-->
<xsl:template match="*[tei:small and not(*[local-name()!='small'])]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="rend">
<xsl:value-of select="normalize-space(concat(@rend, ' ', 'small'))"/>
</xsl:attribute>
<xsl:apply-templates select="text()|*/node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:fw"/>
<xsl:template match="tei:head[@n='1']/text()">
<xsl:value-of select="substring(., 1 , 1)"/>
<xsl:value-of select="translate(substring(., 2), $caps, $mins)"/>
</xsl:template>
<!-- Pour débogage afficher un path -->
<xsl:template name="idpath">
<xsl:for-each select="ancestor-or-self::*">
<xsl:text>/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:if test="count(../*[name()=name(current())]) > 1">
<xsl:text>[</xsl:text>
<xsl:number/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:transform>