-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtei2speedata.xsl
70 lines (59 loc) · 2.27 KB
/
tei2speedata.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
<?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"
version="2.0" xpath-default-namespace="http://www.tei-c.org/ns/1.0">
<xsl:output indent="no"/>
<xsl:template match="/">
<data>
<xsl:apply-templates select="TEI/text/body/div"/>
</data>
</xsl:template>
<xsl:template match="TEI/text/body/div">
<xsl:apply-templates select="head|stage|sp"/>
</xsl:template>
<xsl:template match="head">
<head><xsl:value-of select="."/></head><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="stage">
<stage><xsl:apply-templates/></stage><xsl:text>
</xsl:text>
</xsl:template>
<!-- Initial -->
<xsl:template match="node() | @*" mode="initial" xpath-default-namespace="">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="initial"/>
</xsl:copy>
</xsl:template>
<xsl:template match="part[. = ../part[1]]" mode="initial" xpath-default-namespace="">
<part><xsl:value-of select="concat(upper-case(substring(.,2,1)), substring(.,3))"/></part>
</xsl:template>
<xsl:template match="sp">
<xsl:choose>
<!-- First item, render with initial -->
<xsl:when test=". = ../sp[1]">
<xsl:variable name="foo">
<speaker capital="{substring(ab/text()[matches(.,'\S+')][1],1,1)}" center="true" name="{speaker}"><xsl:apply-templates select="ab/*|ab/text()[matches(.,'\S+')]"/></speaker>
</xsl:variable>
<xsl:apply-templates select="$foo" mode="initial"/>
</xsl:when>
<xsl:otherwise>
<speaker name="{speaker}"><xsl:apply-templates select="ab/*|ab/text()[matches(.,'\S+')]"/></speaker>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="stage/lb">
<br/>
</xsl:template>
<xsl:template match="hi">
<part type="italic"><xsl:value-of select="."/></part>
</xsl:template>
<xsl:template match="ab/stage">
<part type="stage"><xsl:value-of select="."/></part>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="ab/text()">
<part><xsl:value-of select="string(.)"></xsl:value-of></part>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>