-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalto_to_tei_without_output.xsl
157 lines (150 loc) · 7.68 KB
/
alto_to_tei_without_output.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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs xi xsi pc" xmlns="http://www.tei-c.org/ns/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/standards/alto/ns-v4# http://www.loc.gov/standards/alto/v4/alto-4-2.xsd"
xmlns:pc="http://www.loc.gov/standards/alto/ns-v4#">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<!-- Creation of a variable for storing file's name -->
<xsl:variable name="file_name">
<xsl:value-of select="replace(/pc:alto/pc:Description/pc:sourceImageInformation/pc:fileName, '.jpg', '')"/>
</xsl:variable>
<!-- teiHeader elements -->
<TEI>
<teiHeader>
<fileDesc>
<titleStmt>
<title>
<xsl:value-of select="$file_name"/>
</title>
<respStmt>
<resp>Transcribed with</resp>
<name>eScriptorium</name>
</respStmt>
</titleStmt>
<publicationStmt>
<p/>
</publicationStmt>
<sourceDesc>
<p/>
</sourceDesc>
</fileDesc>
<revisionDesc>
<xsl:element name="change"><xsl:attribute name="when"><xsl:value-of select="pc:PcGts/pc:Metadata/pc:Created"
/></xsl:attribute>Creation</xsl:element>
<xsl:element name="change"><xsl:attribute name="when"><xsl:value-of select="pc:PcGts/pc:Metadata/pc:LastChange"
/></xsl:attribute>Last change</xsl:element>
</revisionDesc>
</teiHeader>
<sourceDoc>
<!-- A <graphic> TEI element is used for tagging attributes of the <Page> node in the XML ALTO -->
<graphic>
<xsl:attribute name="xml:id">
<xsl:value-of select="$file_name"/>
</xsl:attribute>
<xsl:attribute name="url">
<xsl:value-of select="$file_name"/>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="concat(//pc:Page/@WIDTH, 'px')"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="concat(//pc:Page/@HEIGHT, 'px')"/>
</xsl:attribute>
</graphic>
<surfaceGrp>
<xsl:attribute name="facs">
<xsl:value-of select="concat('#', $file_name)"/>
</xsl:attribute>
<xsl:apply-templates select="//pc:Page"/>
</surfaceGrp>
</sourceDoc>
</TEI>
</xsl:template>
<!-- A <TextBlock> node in the XML ALTO becomes a <surface> element in the TEI -->
<!-- <surface> in the TEI represents all baselines associated with a <TextBlock> in the XML ALTO -->
<xsl:template match="//pc:TextBlock">
<xsl:element name="surface">
<xsl:attribute name="xml:id">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="@TAGREFS">
<xsl:value-of select="@TAGREFS"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of>none</xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:choose>
<xsl:when test="pc:Shape/pc:Polygon/@POINTS">
<xsl:attribute name="points">
<xsl:variable name="value" select="./pc:Shape/pc:Polygon/@POINTS"/>
<xsl:analyze-string select="$value" regex="([0-9]+)\s([0-9]+)">
<xsl:matching-substring>
<xsl:for-each select="$value">
<xsl:value-of select="regex-group(1)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="regex-group(2)"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<!-- For each <TextLine> in the XML ALTO, a <zone> element is created in the TEI. -->
<xsl:for-each select="pc:TextLine">
<!-- <zone> in the TEI represents baseline's mask in the XML ALTO -->
<xsl:element name="zone">
<xsl:attribute name="xml:id">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of>mask</xsl:value-of>
</xsl:attribute>
<xsl:attribute name="points">
<xsl:variable name="value" select="./pc:Shape/pc:Polygon/@POINTS"/>
<xsl:analyze-string select="$value" regex="([0-9]+)\s([0-9]+)">
<xsl:matching-substring>
<xsl:for-each select="$value">
<xsl:value-of select="regex-group(1)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="regex-group(2)"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:attribute>
<!-- <path> in the TEI represents baseline's coordinates -->
<xsl:element name="path">
<xsl:attribute name="type">
<xsl:value-of>baseline</xsl:value-of>
</xsl:attribute>
<xsl:attribute name="points">
<xsl:variable name="value" select="./@BASELINE"/>
<xsl:analyze-string select="$value" regex="([0-9]+)\s([0-9]+)">
<xsl:matching-substring>
<xsl:for-each select="$value">
<xsl:value-of select="regex-group(1)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="regex-group(2)"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:attribute>
</xsl:element>
<!-- <line> element in the TEI represents the transcription in the XML ALTO -->
<xsl:element name="line">
<xsl:value-of select="pc:String/@CONTENT"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>