summaryrefslogtreecommitdiff
path: root/convert.xsl
blob: 3cdb1c6e6d49cb70217168e033b84f771833cb2c (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<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">
		<!-- FIXME: missing space between style tags -->
		<!--<xsl:if test="string-length(normalize-space(.)) > 0 or (not(parent/child::*[1]=.) and not(parent/child::*[last()]=.))">-->
			<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="strong" mode="copy-with-notes">
		<STYLE fs="bold">
			<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|strong|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="div[@class='annotation']" mode="conv"/>
	<xsl:template match="div[@class='lineBreak']" mode="conv"/>
	<xsl:template match="br|em|strong" mode="conv"/>
	<xsl:template match="p" mode="conv"/>

	<xsl:template match="*" mode="conv">
		<xsl:message terminate="no">
			<xsl:text>Unhandled tag </xsl:text>
			<xsl:value-of select="local-name()" />
			<xsl:text> </xsl:text>
			<xsl:value-of select="@*" />
			<xsl:value-of select="." />
		</xsl:message>
	</xsl:template>

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