-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
77 lines (65 loc) · 2.56 KB
/
index.html
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
<!doctype html>
<html class="no-js" lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>ISO 20022 XML Converter</title>
<meta name="description" content="ISO 20022 XML Converter">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<!--[if lte IE 9]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
<![endif]-->
<header>
<h1>ISO 20022 XML Converter</h1>
</header>
<main>
<input type="file" id="input">
<a id="download" disabled='disabled' href="">Download</a>
</main>
<script type="text/javascript">
function transform(xml_content, xslt_url, callback) {
xslt = new XMLHttpRequest();
xslt.onreadystatechange = function() {
if (xslt.readyState == 4) {
var xml = new DOMParser().parseFromString(xml_content, "text/xml");
var processor = new XSLTProcessor();
processor.importStylesheet(xslt.responseXML);
var resultDoc = processor.transformToFragment(xml, document);
callback(resultDoc.textContent);
}
};
xslt.open("GET", xslt_url);
xslt.send(null);
}
function download(result) {
var a = document.getElementById('download');
a.href = window.URL.createObjectURL(new Blob([result], {
type: 'text/csv'
}));
a.download = targetFilename();
a.removeAttribute('disabled');
}
function targetFilename() {
var regex = /^camt.054-ESR-ASR_T_CH8609000000(\d*)_\d*_0_(\d{8})(\d{8})\.xml$/g;
var fileName = document.getElementById("input").files[0].name;
var match = regex.exec(fileName);
if (match !== null && match.length == 4) {
return 'ESR-' + match[1] + '-' + match[2] + '.csv';
}
return fileName.replace('.xml', '.csv');
}
document.getElementById("input").addEventListener("change", handleFiles, false);
function handleFiles() {
var reader = new FileReader();
reader.onload = function(e) {
transform(reader.result, 'esr.xslt', download);
}
reader.readAsText(this.files[0]);
}
</script>
</body>
</html>