-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbalanceTest.xsl
More file actions
257 lines (231 loc) · 10 KB
/
balanceTest.xsl
File metadata and controls
257 lines (231 loc) · 10 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="http://www.tei-c.org/ns/1.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="xs" version="2.0">
<xsl:output omit-xml-declaration="yes" method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//body"/>
</xsl:template>
<!-- run against catalogue.xml to check balance for lacy, vpp, and tei -->
<xsl:template match="body">
<xsl:variable name="lacyTot" select="count(//div[@type = 'work'])"/>
<xsl:variable name="vppTot"
select="count(//div[@type = 'work' and bibl[@type = 'originalSource']/idno[@type = 'vpp']])"/>
<xsl:variable name="teiTot" select="count(//div[@type = 'work' and @subtype eq 'TEI'])"/>
<xsl:message>Totals : of <xsl:value-of select="$lacyTot"/> Lacy titles, <xsl:value-of select="$vppTot"/> are in VPP; and <xsl:value-of select="$teiTot"/> in TEI</xsl:message>
<xsl:message>TEI per Volume counts: </xsl:message>
<xsl:variable name="zeroVols" select="//*:div[@type='volume'][count(*:div[@type='work' and @subtype='TEI']) eq 0]/substring-before(@n,'/')"/>
<xsl:message><xsl:value-of select="concat( count($zeroVols), ' (',string-join($zeroVols,' '),') have 0 TEI titles')"/></xsl:message>
<xsl:variable name="oneVols" select="//*:div[@type='volume'][count(*:div[@type='work' and @subtype='TEI']) eq 1]/substring-before(@n,'/')"/>
<xsl:message><xsl:value-of select="concat( count($oneVols), ' (',string-join($oneVols,' '),') have 1 TEI title')"/></xsl:message>
<xsl:variable name="twoVols" select="//*:div[@type='volume'][count(*:div[@type='work' and @subtype='TEI']) eq 2]/substring-before(@n,'/')"/>
<xsl:message><xsl:value-of select="concat( count($twoVols), ' (',string-join($twoVols,' '),') have 2 TEI title')"/></xsl:message>
<xsl:variable name="threeVols" select="//*:div[@type='volume'][count(*:div[@type='work' and @subtype='TEI']) eq 3]/substring-before(@n,'/')"/>
<xsl:message><xsl:value-of select="concat( count($threeVols), ' (',string-join($threeVols,' '),') have 3 TEI titles')"/></xsl:message>
<xsl:variable name="fourVols" select="//*:div[@type='volume'][count(*:div[@type='work' and @subtype='TEI']) ge 4]/substring-before(@n,'/')"/>
<xsl:message><xsl:value-of select="concat( count($fourVols), ' (',string-join($fourVols,' '),') have 4+ TEI titles')"/></xsl:message>
<xsl:message>Checking balance for ...</xsl:message>
<!-- define the types to count -->
<xsl:variable name="types"
select="distinct-values(//event[@type = 'firstPerf' and starts-with(@when, '18')]/substring(@when, 1, 3))"/>
<xsl:message> ... date criterion</xsl:message>
<xsl:variable name="root" select="."/>
<xsl:text>
total,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:value-of select="concat(., ',')"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$lacyTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="."/>
<xsl:if test="string-length($t) gt 1">
<xsl:variable name="f"
select="count($root/div/div[@type = 'work' and substring(listEvent/event[@type = 'firstPerf']/@when, 1, 3) eq $t])"/>
<xsl:variable name="teiF"
select="count($root/div/div[@type = 'work' and substring(listEvent/event[@type = 'firstPerf']/@when, 1, 3) eq $t and @subtype eq 'TEI'])"/>
<xsl:variable name="lacyPerc" as="xs:decimal">
<xsl:choose>
<xsl:when test="$f eq 0">
<xsl:message>No Lacy titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:when test="$teiF eq 0">
<xsl:message>No TEI titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round(($f div $lacyTot) * 100)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="diff" select="$lacyPerc - $teiF"/>
<xsl:value-of select="$f"/>
<xsl:if test="abs($diff) gt 2">
<xsl:message>For <xsl:value-of select="$t"/> %lacyTot = <xsl:value-of select="$lacyPerc"/> should be <xsl:value-of select="$teiF"/></xsl:message>
<xsl:value-of select="concat(' (', $diff, ')')"/>
</xsl:if>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$vppTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="."/>
<xsl:if test="string-length($t) gt 1">
<xsl:variable name="f"
select="count($root/div/div[@type = 'work' and substring(listEvent/event[@type = 'firstPerf']/@when, 1, 3) eq $t and bibl[@type = 'origin']/idno[@type = 'vpp']])"/>
<xsl:variable name="teiF"
select="count($root/div/div[@type = 'work' and substring(listEvent/event[@type = 'firstPerf']/@when, 1, 3) eq $t and @subtype eq 'TEI'])"/>
<xsl:variable name="vppPerc" as="xs:decimal">
<xsl:choose>
<xsl:when test="$f eq 0">
<xsl:message>No VPP titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:when test="$teiF eq 0">
<xsl:message>No TEI titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round(($f div $vppTot) * 100)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="diff" select="$vppPerc - $teiF"/>
<xsl:value-of select="$f"/>
<xsl:if test="abs($diff) gt 2">
<xsl:message>For <xsl:value-of select="$t"/> f%vppTot = <xsl:value-of select="$vppPerc"/> should be <xsl:value-of select="$teiF"/>
</xsl:message>
<xsl:value-of select="concat(' (', $diff, ')')"/>
</xsl:if>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$teiTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="."/>
<xsl:if test="string-length($t) gt 1">
<xsl:value-of
select="count($root/div/div[@type = 'work' and substring(listEvent/event[@type = 'firstPerf']/@when, 1, 3) eq $t and @subtype eq 'TEI'])"/>
</xsl:if>
<xsl:if test="not(position() = last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<!-- just do it again, this time for types -->
<xsl:variable name="types"
select="distinct-values(//div[@type = 'work']/tokenize(@ana, '_')[last()])"/>
<xsl:message> ... genre criterion</xsl:message>
<xsl:variable name="root" select="."/>
<xsl:text>
total,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:value-of select="concat(., ',')"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$lacyTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="concat('_', .)"/>
<xsl:if test="string-length($t) gt 1">
<xsl:variable name="f" select="count($root/div/div[@type = 'work' and ends-with(@ana, $t)])"/>
<xsl:variable name="teiF"
select="count($root/div/div[@type = 'work' and ends-with(@ana, $t) and @subtype eq 'TEI'])"/>
<xsl:variable name="lacyPerc" as="xs:decimal">
<xsl:choose>
<xsl:when test="$f eq 0">
<xsl:message>No Lacy titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:when test="$teiF eq 0">
<xsl:message>No TEI titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round(($f div $lacyTot) * 100)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="diff" select="$lacyPerc - $teiF"/>
<xsl:value-of select="$f"/>
<xsl:if test="abs($diff) gt 2">
<xsl:message>For <xsl:value-of select="$t"/> %lacyTot = <xsl:value-of select="$lacyPerc"/> should be <xsl:value-of select="$teiF"/>
</xsl:message>
<xsl:value-of select="concat(' (', $diff, ')')"/>
</xsl:if>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$vppTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="concat('_', .)"/>
<xsl:if test="string-length($t) gt 1">
<xsl:variable name="f"
select="count($root/div/div[@type = 'work' and bibl[@type = 'origin']/idno[@type = 'vpp'] and ends-with(@ana, $t)])"/>
<xsl:variable name="teiF"
select="count($root/div/div[@type = 'work' and ends-with(@ana, $t) and @subtype eq 'TEI'])"/>
<xsl:variable name="vppPerc" as="xs:decimal">
<xsl:choose>
<xsl:when test="$f eq 0">
<xsl:message>No VPP titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:when test="$teiF eq 0">
<xsl:message>No TEI titles for <xsl:value-of select="$t"/></xsl:message>
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round(($f div $vppTot) * 100)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="diff" select="$vppPerc - $teiF"/>
<xsl:value-of select="$f"/>
<xsl:if test="abs($diff) gt 2">
<xsl:message>For <xsl:value-of select="$t"/> f%vppTot = <xsl:value-of select="$vppPerc"/> should be <xsl:value-of select="$teiF"/>
</xsl:message>
<xsl:value-of select="concat(' (', $diff, ')')"/>
</xsl:if>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="$teiTot"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="$types">
<xsl:sort/>
<xsl:variable name="t" select="."/>
<xsl:if test="string-length($t) gt 1">
<xsl:value-of
select="count($root/div/div[@type = 'work' and ends-with(@ana, $t) and @subtype eq 'TEI'])"/>
</xsl:if>
<xsl:if test="not(position() = last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>