-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtransform_version_6.xsl
67 lines (55 loc) · 2.78 KB
/
transform_version_6.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func="http://exslt.org/functions"
xmlns:ewp="http://example.org"
exclude-result-prefixes="ewp"
extension-element-prefixes="func"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- Enclose the value of an element between two markers (_ and _) -->
<xsl:function name="ewp:dumpElement">
<xsl:param name="elValue"/>
<xsl:param name="elName"/>
<xsl:value-of select="concat('_', $elName, '=', $elValue,'_')"/>
</xsl:function>
<!-- Enclose the value of an attribute between two markers (_@ and @_) -->
<xsl:function name="ewp:dumpAttribute">
<xsl:param name="attValue"/>
<xsl:param name="attName"/>
<xsl:value-of select="concat('_@', $attName, '=', $attValue,'@_')"/>
</xsl:function>
<xsl:template match="/">
<iias>
<xsl:for-each select="//*[local-name()='iia']">
<iia>
<iia-id>
<xsl:value-of select="*[local-name()='partner'][1]/*[local-name()='iia-id']"/>
</iia-id>
<text-to-hash>
<xsl:for-each select="*[local-name()='partner']">
<xsl:value-of select="ewp:dumpElement(*[local-name()='iia-id'], concat('iia-id', '_', position()))"/>
</xsl:for-each>
<xsl:for-each select="*[local-name()='cooperation-conditions']/*"> <!-- for each mobility -->
<xsl:for-each select=".//*"> <!-- iterate over the inside elements -->
<!-- but excluding receiving/sending contacts (and their children) and receiving-academic-year-id -->
<xsl:if test="count(ancestor::*[local-name() = 'sending-contact']) = 0 and
count(ancestor::*[local-name() = 'receiving-contact']) = 0 and
local-name() != 'receiving-academic-year-id'"
>
<xsl:if test="count(*) = 0"> <!-- process the element only if it has no children -->
<xsl:value-of select="ewp:dumpElement(., concat(local-name(../..), '.',
local-name(..), '.',
local-name(.)))"/> <!-- the element value -->
</xsl:if>
</xsl:if>
</xsl:for-each>
<!-- finally the first and the last academic year, as per version 7 -->
<xsl:value-of select="ewp:dumpElement(*[local-name()='receiving-academic-year-id'][1], 'receiving-first-academic-year-id')"/>
<xsl:value-of select="ewp:dumpElement(*[local-name()='receiving-academic-year-id'][last()], 'receiving-last-academic-year-id')"/>
</xsl:for-each>
</text-to-hash>
</iia>
</xsl:for-each>
</iias>
</xsl:template>
</xsl:stylesheet>