forked from eprintsug/crosswalks_sgul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symplectic_xwalks_toolkit_mapping.xsl
92 lines (83 loc) · 4.92 KB
/
symplectic_xwalks_toolkit_mapping.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
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pubs="http://www.symplectic.co.uk/publications/atom-api"
xmlns:dim="http://www.dspace.org/xmlns/dspace/dim"
exclude-result-prefixes="pubs dim"
version="1.0">
<xsl:import href="symplectic_xwalks_toolkit_mapping_fieldtypes.xsl" />
<xsl:import href="symplectic_xwalks_toolkit_list.xsl" />
<xsl:import href="symplectic_xwalks_toolkit_utils.xsl" />
<xsl:template name="_map_fields">
<xsl:param name="elements" />
<xsl:param name="repo_field" />
<xsl:param name="date-format" />
<xsl:param name="max" />
<xsl:variable name="_max">
<xsl:choose>
<xsl:when test="$repository-type='eprints'">
<xsl:choose>
<xsl:when test="boolean($config-eprints-fields/*[@name=$repo_field]/@multiple)"><xsl:value-of select="$max" /></xsl:when>
<xsl:otherwise><xsl:text>1</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$max" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="_render_field_mapping">
<xsl:with-param name="field" select="$repo_field" />
<xsl:with-param name="value">
<xsl:call-template name="_render_mapping_occurrences">
<xsl:with-param name="elements" select="$elements" />
<xsl:with-param name="repo_field" select="$repo_field" />
<xsl:with-param name="date-format" select="$date-format" />
<xsl:with-param name="max" select="$_max" />
<xsl:with-param name="_elements_to_iterate" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="_render_mapping_occurrences">
<xsl:param name="elements" />
<xsl:param name="repo_field" />
<xsl:param name="date-format" />
<xsl:param name="max" />
<xsl:param name="_elements_to_iterate" />
<xsl:choose>
<xsl:when test="contains($elements, ',')">
<xsl:call-template name="_render_mapping_occurrences">
<xsl:with-param name="elements" select="normalize-space(substring-before($elements, ','))" />
<xsl:with-param name="repo_field" select="$repo_field" />
<xsl:with-param name="date-format" select="$date-format" />
<xsl:with-param name="max" select="$max" />
<xsl:with-param name="_elements_to_iterate" select="normalize-space(substring-after($elements, ','))" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fields" select="pubs:field[@name=normalize-space($elements)]" />
<xsl:variable name="field_values" select="$fields/pubs:people/*|$fields/pubs:keywords/*|$fields/pubs:items/*|$fields/*[local-name()!='items' and local-name()!='keywords' and local-name()!='people']" />
<xsl:for-each select="$field_values">
<xsl:if test="$max='' or position() <= $max">
<xsl:call-template name="_render_field_occurrence">
<xsl:with-param name="field" select="$repo_field" />
<xsl:with-param name="value">
<xsl:apply-templates select="." mode="mapping">
<xsl:with-param name="name"><xsl:value-of select="ancestor::pubs:field/@name" /></xsl:with-param>
<xsl:with-param name="repo_field" select="$repo_field" />
<xsl:with-param name="date-format" select="$date-format" />
</xsl:apply-templates>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
<xsl:if test="$_elements_to_iterate and ($max='' or count($field_values) < $max)">
<xsl:call-template name="_render_mapping_occurrences">
<xsl:with-param name="elements" select="$_elements_to_iterate" />
<xsl:with-param name="repo_field" select="$repo_field" />
<xsl:with-param name="date-format" select="$date-format" />
<xsl:with-param name="max"><xsl:if test="$max > 0"><xsl:value-of select="$max - count($field_values)"/></xsl:if></xsl:with-param>
<xsl:with-param name="_elements_to_iterate" />
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>