-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWORD2TEI.xsl
162 lines (147 loc) · 4.87 KB
/
WORD2TEI.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
158
159
160
161
162
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="w">
<xsl:output method="xml" indent="yes"/>
<!-- Root template -->
<xsl:template match="/">
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>
<xsl:value-of select="//w:title"/>
</title>
</titleStmt>
<publicationStmt>
<p>Converted from Word document</p>
</publicationStmt>
<sourceDesc>
<p>Created from a Word document</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<xsl:apply-templates select="//w:body"/>
</body>
<!-- Back matter for both footnotes and endnotes -->
<back>
<!-- Footnotes section -->
<div type="footnotes">
<head>Footnotes</head>
<xsl:apply-templates select="//w:footnotes/w:footnote[not(@w:type='separator' or @w:type='continuationSeparator')]"/>
</div>
<!-- Endnotes section -->
<div type="endnotes">
<head>Endnotes</head>
<xsl:apply-templates select="//w:endnotes/w:endnote[not(@w:type='separator' or @w:type='continuationSeparator')]"/>
</div>
</back>
</text>
</TEI>
</xsl:template>
<!-- Paragraph template -->
<xsl:template match="w:p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<!-- Heading 1 -->
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val='Heading1']">
<div type="section">
<head>
<xsl:apply-templates/>
</head>
</div>
</xsl:template>
<!-- Text run template -->
<xsl:template match="w:r">
<xsl:choose>
<!-- Bold text -->
<xsl:when test="w:rPr/w:b">
<hi rend="bold">
<xsl:apply-templates/>
</hi>
</xsl:when>
<!-- Italic text -->
<xsl:when test="w:rPr/w:i">
<hi rend="italic">
<xsl:apply-templates/>
</hi>
</xsl:when>
<!-- Regular text -->
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Footnote reference in main text -->
<xsl:template match="w:r[w:footnoteReference]">
<note type="footnoteRef">
<xsl:attribute name="n">
<xsl:value-of select="w:footnoteReference/@w:id"/>
</xsl:attribute>
</note>
</xsl:template>
<!-- Endnote reference in main text -->
<xsl:template match="w:r[w:endnoteReference]">
<note type="endnoteRef">
<xsl:attribute name="n">
<xsl:value-of select="w:endnoteReference/@w:id"/>
</xsl:attribute>
</note>
</xsl:template>
<!-- Footnote content -->
<xsl:template match="w:footnote">
<note type="footnote">
<xsl:attribute name="xml:id">
<xsl:value-of select="concat('fn', @w:id)"/>
</xsl:attribute>
<xsl:apply-templates/>
</note>
</xsl:template>
<!-- Endnote content -->
<xsl:template match="w:endnote">
<note type="endnote">
<xsl:attribute name="xml:id">
<xsl:value-of select="concat('en', @w:id)"/>
</xsl:attribute>
<xsl:apply-templates/>
</note>
</xsl:template>
<!-- Text template -->
<xsl:template match="w:t">
<xsl:value-of select="."/>
</xsl:template>
<!-- Line break -->
<xsl:template match="w:br">
<lb/>
</xsl:template>
<!-- Table template -->
<xsl:template match="w:tbl">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<!-- Table row -->
<xsl:template match="w:tr">
<row>
<xsl:apply-templates/>
</row>
</xsl:template>
<!-- Table cell -->
<xsl:template match="w:tc">
<cell>
<xsl:apply-templates/>
</cell>
</xsl:template>
<!-- List template -->
<xsl:template match="w:p[w:pPr/w:numPr]">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
</xsl:stylesheet>