-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-titleErrors.xsl
54 lines (41 loc) · 2.17 KB
/
find-titleErrors.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
<?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"
exclude-result-prefixes="xs tei jc"
xmlns:jc="http://james.blushingbunny.net/ns.html"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
version="2.0">
<!--
File to output information about titles in SRO Entries, for each SRO Entry it creates output only if
the number of titles and the number in the metadata do *not* match
This is best run on the commandline with something like:
saxon -o:OutputFileName.csv -s:Arber1.xml -xsl:find-titleErrors.xsl
Then import the CSV into something like libreoffice or excel
-->
<!-- We set the output method for text because we are producing CSV -->
<xsl:output method="text"/>
<!-- We are matching the top-level document node since we're ignoring most of it. -->
<xsl:template match="/">
<!-- We output the column headings with a linebreak by having xsl:text end on next line -->
<xsl:text>"SRO ID", "Number of Titles", "Number of Works"
</xsl:text>
<!-- For each title inside an entry... -->
<xsl:for-each select="//div[@type='entry'][count(.//title) ne number(.//ab[@type='metadata']/num[@type='works']/@value)]">
<!-- We make a variable named 'output' which has all the columns we want. It is fine to
have them on separate lines and such because we will normalize-space it afterwards. -->
<xsl:variable name="output">
"<xsl:value-of select="ancestor-or-self::div[@type='entry']/@xml:id"/>",
"<xsl:value-of select="count(.//title)"/>",
"<xsl:value-of select=".//ab[@type='metadata']/num[@type='works']/@value"/>"
</xsl:variable>
<xsl:value-of select="normalize-space($output)"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
<!-- CSV doesn't like spare double quotes lying around. So you escape them by putting two double quotes instead -->
<xsl:function name="jc:csvEscapeDoubleQuotes" as="xs:string">
<xsl:param name="string" as="xs:string"/>
<xsl:value-of select="replace($string, '"', '""')"/>
</xsl:function>
</xsl:stylesheet>