-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.xslt
155 lines (133 loc) · 4.82 KB
/
common.xslt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common" xmlns:func="http://exslt.org/functions"
xmlns:str="http://exslt.org/strings" xmlns:my="http://example.org/my"
extension-element-prefixes="func str exsl">
<!-- exclude-result-prefixes="my" -->
<xsl:output indent="yes" method="xml" />
<xsl:template name="path">
<xsl:for-each select="parent::*">
<xsl:call-template name="path" />
</xsl:for-each>
<xsl:value-of select="name()" />
<xsl:text>/</xsl:text>
</xsl:template>
<func:function name="my:ISO17442">
<xsl:param name="lei" />
<func:result select="my:modulo(my:convert($lei), 97) = 1" />
</func:function>
<func:function name="my:ISO6166">
<xsl:param name="isin" />
<xsl:variable name="checkdigit" select="substring($isin,12,1)" />
<xsl:variable name="digits" select="my:convert(substring($isin,1,11))" />
<xsl:variable name="weightedsum" select="my:weightedsum($digits)" />
<func:result select="my:modulo(10 - my:modulo($weightedsum,10),10) = $checkdigit" />
</func:function>
<func:function name="my:weightedsum">
<xsl:param name="digits" />
<xsl:variable name="d"
select="substring(concat(substring('0000000000000000000000',1,22 - string-length($digits) ),$digits),1,22)" />
<xsl:variable name="twice"
select="
concat(
2*substring($d,2,1),
2*substring($d,4,1),
2*substring($d,6,1),
2*substring($d,8,1),
2*substring($d,10,1),
2*substring($d,12,1),
2*substring($d,14,1),
2*substring($d,16,1),
2*substring($d,18,1),
2*substring($d,20,1),
2*substring($d,22,1))" />
<xsl:variable name="once"
select="substring($d,1,1) +
substring($d,3,1) +
substring($d,5,1) +
substring($d,7,1) +
substring($d,9,1) +
substring($d,11,1) +
substring($d,13,1) +
substring($d,15,1) +
substring($d,17,1) +
substring($d,19,1) +
substring($d,21,1)" />
<func:result select="sum(str:split($twice,'')) + $once" />
<!-- <func:result select="sum(str:split($twice,''))" /> -->
</func:function>
<func:function name="my:convert">
<xsl:param name="value" />
<func:result
select="
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace(
str:replace($value,
'A','10'),
'B','11'),
'C','12'),
'D','13'),
'E','14'),
'F','15'),
'G','16'),
'H','17'),
'I','18'),
'J','19'),
'K','20'),
'L','21'),
'M','22'),
'N','23'),
'O','24'),
'P','25'),
'Q','26'),
'R','27'),
'S','28'),
'T','29'),
'U','30'),
'V','31'),
'W','32'),
'X','33'),
'Y','34'),
'Z','35')" />
</func:function>
<func:function name="my:modulo">
<xsl:param name="dividend" />
<xsl:param name="divisor" />
<xsl:choose>
<xsl:when test="not($dividend > 9999999999999999)">
<func:result select="$dividend mod $divisor" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vLen" select="string-length($dividend)" />
<xsl:variable name="vLen1" select="$vLen -1" />
<xsl:variable name="vPart1" select="substring($dividend, 1, $vLen1)" />
<xsl:variable name="vPart2" select="substring($dividend, $vLen1 +1)" />
<xsl:variable name="vMod1" select="my:modulo($vPart1, $divisor)" />
<xsl:variable name="vMod2" select="$vPart2 mod $divisor" />
<func:result select="(10*$vMod1 + $vMod2) mod $divisor" />
</xsl:otherwise>
</xsl:choose>
</func:function>
</xsl:stylesheet>