-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpt3.xsl
139 lines (130 loc) · 4.48 KB
/
pt3.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output indent="1" />
<xd:doc>
<xd:desc>
<xd:p>Try to guess whether there’s forme work on this page; normal book or article pages ususally have no more
than one line of footer and header each. Official writs, letters etc. may have more (e. g. complete addresses
etc. but we ignore those use cases for now – this can be dealt with in post processing.</xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="*:page">
<xsl:choose>
<xsl:when test="tei:cb and count(tei:cb[1]/preceding-sibling::*) lt 2 and not(tei:cb[1]/preceding-sibling::tei:head)">
<pb n="{@number}">
<xsl:sequence select="@height | @width | @l | @r" />
<xsl:apply-templates select="tei:cb[1]/preceding-sibling::*" />
</pb>
<xsl:apply-templates select="tei:cb[1]/following-sibling::*" />
</xsl:when>
<xsl:otherwise>
<pb n="{@number}">
<xsl:sequence select="@height | @width | @l | @r" />
</pb>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xd:doc>
<xd:desc>
<xd:p>Convert links to <xd:pre>tei:ref</xd:pre></xd:p>
</xd:desc>
</xd:doc>
<!-- TODO This will need more detailed work -->
<xsl:template match="*:a">
<xsl:choose>
<xsl:when test="string-length() < 5">
<ref ref="{@href}">
<xsl:sequence select="node()" />
</ref>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="node()" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- for now, we hope that all styles like bold and italics are encoded with the respective elements; if that is not
the case, we will have to try to evaluate the font names -->
<xd:doc>
<xd:desc>
<xd:p>Bold sections: <xd:pre>tei:hi</xd:pre>; use <xd:pre>@rend</xd:pre> for now.</xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="*:b">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::*:b]" />
<xsl:otherwise>
<hi rend="bold">
<xsl:apply-templates select="node() | following-sibling::*[self::*:b]/node()"/>
</hi>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xd:doc>
<xd:desc>
<xd:p>Italic sections: <xd:pre>tei:hi</xd:pre>; use <xd:pre>@rend</xd:pre> for now.</xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="*:i">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::*:i]" />
<xsl:otherwise>
<hi rend="italics">
<xsl:apply-templates select="node() | following-sibling::*[self::*:i]/node()"/>
</hi>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xd:doc>
<xd:desc>
<xd:p>Group headings by level</xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="tei:head">
<xsl:variable name="level" select="@level" />
<xsl:variable name="end" select="(following-sibling::tei:l | following-sibling::tei:head[@level != $level])[1]" />
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][@level eq $level]" />
<xsl:otherwise>
<head level="{$level}">
<xsl:apply-templates select="*" />
<xsl:choose>
<xsl:when test="$end">
<xsl:apply-templates select="(following-sibling::* intersect $end/preceding-sibling::*)/*" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="following-sibling::*/*" />
</xsl:otherwise>
</xsl:choose>
</head>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xd:doc>
<xd:desc>We need to add info about the highest value for @level of any tei:head as entry point for the creation
of tei:div in the next step.</xd:desc>
</xd:doc>
<xsl:template match="tei:text">
<text>
<xsl:attribute name="maxLevel">
<xsl:value-of select="max(//tei:head/@level ! number())"/>
</xsl:attribute>
<xsl:apply-templates />
</text>
</xsl:template>
<xd:doc>
<xd:desc>Default</xd:desc>
</xd:doc>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>