summaryrefslogtreecommitdiff
path: root/endnote-to-dbxml.xsl
blob: f8880dbbea4afbbb08de0375cb954d9ae06d5ea1 (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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl">

	<xsl:key name="author" match="author" use="." />

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

	<xsl:include href="util.xsl"/>

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

	<xsl:template match="authors" mode="references">

	</xsl:template>

	<xsl:template match="record">
		<xsl:param name="authors"/>

		<publication>
			<uid>
				<xsl:value-of select="rec-number" />
			</uid>
			<title>
				<xsl:apply-templates select="titles/title" mode="copy-html" />
			</title>
			<secondary_title>
				<xsl:apply-templates select="titles/secondary-title" mode="copy-html" />
				<xsl:text></xsl:text>
			</secondary_title>
			<full_title>
				<xsl:apply-templates select="periodical/full-title" mode="copy-html" />
				<xsl:text></xsl:text>
			</full_title>
			<type>
				<xsl:value-of select="ref-type/@name" />
			</type>
			<year>
				<xsl:apply-templates select="dates/year" mode="content" />
			</year>

			<authors>
				<xsl:for-each select="contributors/authors/author">
					<xsl:if test="position() &gt; 1">
						<xsl:text>,</xsl:text>
					</xsl:if>
					<xsl:value-of select="exsl:node-set($authors)/tx_likat_pubs_domain_model_authors/author[name=current()]/uid" />
				</xsl:for-each>
			</authors>
		</publication>
	</xsl:template>

	<xsl:template match="records">
		<xsl:param name="authors"/>
		<tx_likat_pubs_domain_model_publications>
			<xsl:apply-templates select="record">
				<xsl:with-param name="authors">
					<xsl:call-template name="authors" />
				</xsl:with-param>
			</xsl:apply-templates>
		</tx_likat_pubs_domain_model_publications>
	</xsl:template>

	<xsl:template match="author">
		<author>
			<xsl:variable name="pos" select="position()"/>
			<uid><xsl:value-of select="$pos"/></uid>
			<name><xsl:value-of select="." /></name>
		</author>
	</xsl:template>


	<xsl:template name="authors">
		<tx_likat_pubs_domain_model_authors>
			<xsl:apply-templates select="//author[generate-id() =
				generate-id(key('author', .)[1])]"/>
		</tx_likat_pubs_domain_model_authors>
	</xsl:template>

	<xsl:template match="/">
		<db>
			<xsl:apply-templates select="xml/records"/>

			<xsl:call-template name="authors" />
		</db>
	</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:stylesheet>