-
Notifications
You must be signed in to change notification settings - Fork 2
/
xmlpage_to_tei_without_output.xsl
130 lines (123 loc) · 6.23 KB
/
xmlpage_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
<?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://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15 http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15/pagecontent.xsd"
xmlns:pc="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15">
<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:PcGts/pc:Page/@imageFilename, '.jpg', '')"/>
</xsl:variable>
<!-- teiHeader elements -->
<TEI>
<teiHeader>
<fileDesc>
<titleStmt>
<title>
<xsl:value-of
select="$file_name"
/>
</title>
<respStmt>
<resp>Transcribed with</resp>
<name>
<xsl:value-of select="pc:PcGts/pc:Metadata/pc:Creator"/>
</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 PAGE XML -->
<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/@imageWidth, 'px')"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="concat(//@imageHeight, '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 <TextRegion> node in the PAGE XML becomes a <surface> element in the TEI -->
<!-- <surface> in the TEI represents all baselines associated with a <TextRegion> in the PAGE XML -->
<xsl:template match="//pc:TextRegion">
<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="@custom">
<xsl:value-of select="replace(replace(@custom, 'structure \{type:', ''), ';\}', '')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of>none</xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:choose>
<xsl:when test="pc:Coords/@points">
<xsl:attribute name="points">
<xsl:value-of select="pc:Coords/@points"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<!-- For each <TextLine> in the PAGE XML, a <zone> element is created in the TEI. -->
<xsl:for-each select="pc:TextLine">
<!-- <zone> in the TEI represents baseline's mask in the PAGE XML -->
<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:value-of select="pc:Coords/@points"/>
</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:value-of select="pc:Baseline/@points"/>
</xsl:attribute>
</xsl:element>
<!-- <line> element in the TEI represents the transcription in the PAGE XML -->
<xsl:element name="line">
<xsl:value-of select="pc:TextEquiv/pc:Unicode"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>