-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert_tei-to-yaml_functions.xsl
157 lines (150 loc) · 9.35 KB
/
convert_tei-to-yaml_functions.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"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:oape="https://openarabicpe.github.io/ns"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
version="3.0">
<xsl:output method="text" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" name="text"/>
<xsl:strip-space elements="*"/>
<!-- this stylesheet translates <tei:biblStruct>s to YAML -->
<!-- toggle debugging messages -->
<!-- <xsl:include href="../../oxygen-project/OpenArabicPE_parameters.xsl"/>-->
<xsl:variable name="v_new-line" select="'
'"/>
<xsl:variable name="v_quot" select="''''"/>
<xsl:variable name="v_comma" select="','"/>
<xsl:variable name="v_tab" select="' '"/>
<!-- testing -->
<!--<xsl:template match="/">
<xsl:apply-templates select="descendant::tei:biblStruct" mode="m_tei-to-yaml"/>
</xsl:template>-->
<xsl:template match="tei:biblStruct" mode="m_tei-to-yaml">
<xsl:copy-of select="oape:bibliography-tei-to-yaml(., 'ar', false())"/>
</xsl:template>
<xsl:function name="oape:bibliography-tei-to-yaml">
<xsl:param name="p_input"/>
<xsl:param name="p_lang"/>
<!-- param to select wether a YAML block should be part of a list or independent -->
<xsl:param name="p_indent"/>
<xsl:variable name="v_title-analytic">
<xsl:value-of select="$v_quot"/>
<xsl:choose>
<xsl:when test="$p_input/tei:analytic/tei:title[@level = 'a'][@xml:lang = $p_lang]">
<xsl:value-of select="$p_input/tei:analytic/tei:title[@level = 'a'][@xml:lang = $p_lang][1]"/>
</xsl:when>
<xsl:when test="$p_input/tei:analytic/tei:title[@level = 'a']">
<xsl:value-of select="$p_input/tei:analytic/tei:title[@level = 'a'][1]"/>
</xsl:when>
</xsl:choose>
<xsl:value-of select="$v_quot"/>
</xsl:variable>
<xsl:variable name="v_title-monogr">
<xsl:value-of select="$v_quot"/>
<xsl:choose>
<xsl:when test="$p_input/tei:monogr/tei:title[@level = 'j'][@xml:lang = $p_lang]">
<xsl:apply-templates select="$p_input/tei:monogr/tei:title[@level = 'j'][@xml:lang = $p_lang][1]" mode="m_plain-text"/>
</xsl:when>
<xsl:when test="$p_input/tei:monogr/tei:title[@level = 'j']">
<xsl:apply-templates select="$p_input/tei:monogr/tei:title[@level = 'j'][1]" mode="m_plain-text"/>
</xsl:when>
</xsl:choose>
<!-- sub title -->
<xsl:if test="$p_input/tei:monogr/tei:title[@level='j'][@type='sub']">
<xsl:text>: </xsl:text>
<xsl:choose>
<xsl:when test="$p_input/tei:monogr/tei:title[@level = 'j'][@type='sub'][@xml:lang = $p_lang]">
<xsl:apply-templates select="$p_input/tei:monogr/tei:title[@level = 'j'][@type='sub'][@xml:lang = $p_lang][1]" mode="m_plain-text"/>
</xsl:when>
<xsl:when test="$p_input/tei:monogr/tei:title[@level = 'j'][@type='sub']">
<xsl:apply-templates select="$p_input/tei:monogr/tei:title[@level = 'j'][@type='sub'][1]" mode="m_plain-text"/>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:value-of select="$v_quot"/>
</xsl:variable>
<!-- output -->
<xsl:if test="$p_indent = true()"><xsl:text>- </xsl:text></xsl:if>
<xsl:text>id: </xsl:text><xsl:value-of select="$v_quot"/><xsl:value-of select="$p_input/tei:analytic/tei:idno[@type='BibTeX']"/><xsl:value-of select="$v_quot"/><xsl:value-of select="$v_new-line"/>
<!-- titles -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>title: </xsl:text>
<xsl:value-of select="$v_title-analytic"/><xsl:value-of select="$v_new-line"/>
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>container-title: </xsl:text>
<xsl:value-of select="$v_title-monogr"/><xsl:value-of select="$v_new-line"/>
<!-- volume, issue, pages -->
<xsl:apply-templates select="$p_input/tei:monogr/tei:biblScope" mode="m_tei-to-yaml">
<xsl:with-param name="p_indent" select="$p_indent"/>
</xsl:apply-templates>
<!-- IDs -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>URL: </xsl:text><xsl:value-of select="$v_new-line"/>
<xsl:apply-templates select="$p_input/tei:analytic/tei:idno[@type='url']" mode="m_tei-to-yaml"/>
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>OCLC: </xsl:text><xsl:value-of select="$v_new-line"/>
<xsl:apply-templates select="$p_input/tei:monogr/tei:idno[@type='OCLC']" mode="m_tei-to-yaml"/>
<!-- author, editor -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>author: </xsl:text>
<xsl:apply-templates select="$p_input/tei:analytic/tei:author" mode="m_tei-to-yaml">
<xsl:with-param name="p_lang" select="$p_lang"/>
</xsl:apply-templates>
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>editor: </xsl:text>
<xsl:apply-templates select="$p_input/tei:monogr/tei:editor" mode="m_tei-to-yaml">
<xsl:with-param name="p_lang" select="$p_lang"/>
</xsl:apply-templates>
<!-- language -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>language: </xsl:text><xsl:value-of select="$p_input/tei:monogr/tei:textLang/@mainLang"/><xsl:value-of select="$v_new-line"/>
<!-- imprint -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>type: </xsl:text><xsl:value-of select="$v_new-line"/>
<!-- dates -->
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:text>issued: </xsl:text><xsl:apply-templates select="$p_input/tei:monogr/tei:imprint/tei:date[@when][1]" mode="m_tei-to-yaml"/><xsl:value-of select="$v_new-line"/>
</xsl:function>
<xsl:template match="tei:idno" mode="m_tei-to-yaml">
<xsl:value-of select="$v_tab"/><xsl:text>- </xsl:text><xsl:value-of select="$v_quot"/><xsl:value-of select="."/><xsl:value-of select="$v_quot"/><xsl:value-of select="$v_new-line"/>
</xsl:template>
<xsl:template match="tei:date[@when]" mode="m_tei-to-yaml">
<xsl:value-of select="$v_quot"/>
<xsl:value-of select="@when"/>
<xsl:value-of select="$v_quot"/>
</xsl:template>
<xsl:template match="tei:author | tei:editor" mode="m_tei-to-yaml">
<xsl:param name="p_lang"/>
<xsl:apply-templates select="if(tei:persName[@xml:lang = $p_lang]) then(tei:persName[@xml:lang = $p_lang][1]) else(tei:persName[1])" mode="m_tei-to-yaml"/><xsl:value-of select="$v_new-line"/>
</xsl:template>
<xsl:template match="tei:persName" mode="m_tei-to-yaml">
<xsl:value-of select="$v_new-line"/><xsl:value-of select="$v_tab"/><xsl:text>- </xsl:text>
<xsl:choose>
<xsl:when test="tei:surname">
<xsl:apply-templates select="tei:surname" mode="m_tei-to-yaml"/>
<xsl:apply-templates select="tei:forename" mode="m_tei-to-yaml"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$v_quot"/><xsl:apply-templates select="." mode="m_plain-text"/><xsl:value-of select="$v_quot"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="tei:surname" mode="m_tei-to-yaml">
<xsl:text>family: </xsl:text><xsl:value-of select="$v_quot"/><xsl:apply-templates select="." mode="m_plain-text"/><xsl:value-of select="$v_quot"/><xsl:value-of select="$v_new-line"/>
</xsl:template>
<xsl:template match="tei:forename" mode="m_tei-to-yaml">
<xsl:value-of select="$v_tab"/><xsl:value-of select="$v_tab"/><xsl:text>given: </xsl:text><xsl:value-of select="$v_quot"/><xsl:apply-templates select="." mode="m_plain-text"/><xsl:value-of select="$v_quot"/><xsl:value-of select="$v_new-line"/>
</xsl:template>
<xsl:template match="tei:biblScope" mode="m_tei-to-yaml">
<xsl:param name="p_indent"/>
<xsl:if test="$p_indent = true()"><xsl:value-of select="$v_tab"/></xsl:if><xsl:value-of select="@unit"/><xsl:text>: </xsl:text>
<xsl:value-of select="$v_quot"/>
<xsl:choose>
<xsl:when test="@from = @to">
<xsl:value-of select="@from"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@from"/><xsl:text>-</xsl:text><xsl:value-of select="@to"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$v_quot"/>
<xsl:value-of select="$v_new-line"/>
</xsl:template>
<!-- plain text output: beware that heavily marked up nodes will have most whitespace omitted -->
<xsl:template match="text()" mode="m_plain-text">
<!-- <xsl:value-of select="normalize-space(replace(.,'(\w)[\s|\n]+','$1 '))"/>-->
<!-- <xsl:text> </xsl:text>-->
<xsl:value-of select="normalize-space(.)"/>
<!-- <xsl:text> </xsl:text>-->
</xsl:template>
</xsl:stylesheet>