summaryrefslogtreecommitdiff
path: root/convert-style-to-html.xsl
blob: 985896430c0cabc197d2846249f72112f4ac9198 (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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

	<xsl:output method="xml" indent="yes" encoding="UTF-8"  />

	<!-- Convert endnote style definitions declarations to html tags -->
	<!-- TODO: <author>Editors,</author> bzw <author>Editor,</author> -->
	<xsl:template match="style" name="style">

		<xsl:param name="oldface" select="@face"/>
		<xsl:param name="exclude" select="''" />

		<xsl:variable name="face">
			<xsl:call-template name="string-replace-all">
				<xsl:with-param name="text" select="$oldface" />
				<xsl:with-param name="replace" select="$exclude" />
				<xsl:with-param name="by" select="''" />
			</xsl:call-template>
		</xsl:variable>

		<xsl:choose>
			<xsl:when test="contains($face, 'subscript')">
				<sub>
					<xsl:call-template name="style">
						<xsl:with-param name="oldface" select="$face"/>
						<xsl:with-param name="exclude" select="'subscript'"/>
					</xsl:call-template>
				</sub>
			</xsl:when>
			<xsl:when test="contains($face, 'superscript')">
				<sub>
					<xsl:call-template name="style">
						<xsl:with-param name="oldface" select="$face"/>
						<xsl:with-param name="exclude" select="'superscript'"/>
					</xsl:call-template>
				</sub>
			</xsl:when>
			<xsl:when test="contains($face, 'italic')">
				<em>
					<xsl:call-template name="style">
						<xsl:with-param name="oldface" select="$face"/>
						<xsl:with-param name="exclude" select="'italic'"/>
					</xsl:call-template>
				</em>
			</xsl:when>
			<xsl:when test="contains($face, 'boldface')">
				<strong>
					<xsl:call-template name="style">
						<xsl:with-param name="oldface" select="$face"/>
						<xsl:with-param name="exclude" select="'boldface'"/>
					</xsl:call-template>
				</strong>
			</xsl:when>
			<xsl:when test="contains($face, 'normal')">
				<xsl:call-template name="style">
					<xsl:with-param name="oldface" select="$face"/>
					<xsl:with-param name="exclude" select="'normal'"/>
				</xsl:call-template>
			</xsl:when>

			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>

		</xsl:choose>
	</xsl:template>

	<!-- Drop style definitions from author-tags -->
	<xsl:template match="author/style">
		<xsl:apply-templates />
	</xsl:template>

	<xsl:template match="*">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates />
		</xsl:copy>
	</xsl:template>

	<xsl:template name="string-replace-all">
		<xsl:param name="text" />
		<xsl:param name="replace" />
		<xsl:param name="by" />
		<xsl:choose>
			<xsl:when test="$replace = ''">
				<xsl:value-of select="$text" />
			</xsl:when>
			<xsl:when test="contains($text, $replace)">
				<xsl:value-of select="substring-before($text,$replace)" />
				<xsl:value-of select="$by" />
				<xsl:call-template name="string-replace-all">
					<xsl:with-param name="text" select="substring-after($text,$replace)" />
					<xsl:with-param name="replace" select="$replace" />
					<xsl:with-param name="by" select="$by" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

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

</xsl:stylesheet>