summaryrefslogtreecommitdiff
path: root/convert.xsl
blob: 3a8eb7dcbcc67c0db43cedcbb5c3e6f0874d774d (plain)
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
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes" encoding="UTF-8" media-type="text/xml"/>

	<xsl:template match="h2" mode="conv">
		<caption>
			<xsl:attribute name="vref">
 				<xsl:choose>
					<xsl:when test="string-length(following::span[@class='verse']) > 0">
						<xsl:value-of select="following::span[@class='verse']"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="preceding::span[@class='verse']"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>

			<!-- FIXME: e.g. Psalm 145 has footnotes in caption, with incorrect reference -->
			<xsl:value-of select="text()" />
		</caption>
	</xsl:template>

	<xsl:template match="span[@class='fussnote']" mode="copy-with-notes">
		<note n1="x-studynote">
			<xsl:variable name="id">
				<xsl:value-of select="@data-param"/>
			</xsl:variable>
			<xsl:apply-templates select="//div[@id=$id]/div/p" mode="copy-with-notes"/>
		</note>
	</xsl:template>

	<xsl:template match="text()" mode="copy-with-notes">
		<xsl:if test="string-length(normalize-space(.)) > 0">
			<xsl:value-of select="." />
		</xsl:if>
	</xsl:template>

	<xsl:template match="em" mode="copy-with-notes">
		<style fs="emphasis">
			<xsl:value-of select="." />
		</style>
	</xsl:template>

	<xsl:template match="br" mode="copy-with-notes">
		<br art="x-nl" />
	</xsl:template>
	<xsl:template match="div[@class='lineBreak']" mode="copy-with-notes">
		<br art="x-nl" />
	</xsl:template>

<!--
	<xsl:template match="*" mode="error">
		<xsl:choose>
			<xsl:when test="@class='fussnote'"/>
			<xsl:when test="@class='verse'"/>
			<xsl:when test="@class='chapter'"/>
			<xsl:when test="local-name()='em'"/>
			<xsl:when test="local-name()='br'"/>
			<xsl:otherwise>
				<xsl:message terminate="yes">
					<xsl:value-of select="local-name()" />
					<xsl:value-of select="@class" />
					<xsl:apply-templates select="." mode="copy" />
				</xsl:message>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
-->

	<xsl:template name="copy-until-next-verse">
		<xsl:apply-templates select="following-sibling::*[1]" mode="copy-until-next-verse" />
	</xsl:template>
	<xsl:template name="copy-with-notes">
		<xsl:apply-templates select="text()|span[@class='fussnote']|em|br" mode="copy-with-notes" />
		<xsl:call-template name="copy-until-next-verse" />
	</xsl:template>

	<!-- Dont copy intermediate headers and annotations into verse -->
	<xsl:template match="div[@class='annotation']|h2" mode="copy-until-next-verse">
		<xsl:call-template name="copy-until-next-verse"/>
	</xsl:template>

	<xsl:template match="*" mode="copy-until-next-verse">
		<xsl:if test="not(span[@class = 'verse']) and not(@class='fussnote')">
			<xsl:text> </xsl:text>
			<xsl:call-template name="copy-with-notes" />
		</xsl:if>
	</xsl:template>

	<xsl:template match="blockquote" mode="conv">
		<xsl:apply-templates mode="conv"/>
	</xsl:template>

	<xsl:template match="p[span/@class='verse']" mode="conv">
		<vers>
			<xsl:attribute name="vnumber">
				<xsl:value-of select="span[@class='verse']"/>
			</xsl:attribute>
			<xsl:call-template name="copy-with-notes" />

			<!--<xsl:apply-templates select="*" mode="error" />-->
		</vers>
	</xsl:template>

	<xsl:template match="*" mode="conv"/>

	<xsl:template match="/">
		<chapter cnumber="{//span[@class='chapter']}">
			<xsl:apply-templates select="//div[@class='markdown']/*" mode="conv"/>
		</chapter>
	</xsl:template>
</xsl:stylesheet>