let
$without-checksum := substring($value, 1, 11),
$letter-as-numbers-string :=
string-join(
for $code in string-to-codepoints($without-checksum)
return
if ($code >= string-to-codepoints('A') and string-to-codepoints('Z') >= $code) then
(: Letters A-Z :)
xs:string($code - string-to-codepoints('A') + 10)
else if ($code >= string-to-codepoints('0') and string-to-codepoints('9') >= $code) then
(: Digits 0-9 :)
xs:string($code - string-to-codepoints('0'))
(: Unrecognized characters :)
else
'',
''
),
$letter-as-numbers-digits :=
for $code in string-to-codepoints($letter-as-numbers-string)
return xs:decimal(codepoints-to-string($code)),
$reversed-digits := reverse($letter-as-numbers-digits),
$group-1-digits := $reversed-digits[position() mod 2 = 1],
$group-2-digits := $reversed-digits[position() mod 2 = 0],
$group-1-x2-decimals := for $d in $group-1-digits return $d * 2,
$group-1-x2-string := string-join(for $d in $group-1-x2-decimals return string($d), ''),
$group-1-x2-digits := for $code in string-to-codepoints($group-1-x2-string)
return xs:decimal(codepoints-to-string($code)),
$sum-digits := sum(($group-1-x2-digits, $group-2-digits)),
$checksum-computed := string((10 - ($sum-digits mod 10)) mod 10),
$checksum-provided := substring($value, 12, 1)
return $checksum-computed = $checksum-provided | | documentation | Walidacja cyfry kontrolnej identyfikatora ISIN |
|