-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
101 lines (85 loc) · 4.25 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>ISO 20022 CAMT053 to OFX XML Converter</title>
<meta name="description" content="ISO 20022 XML Converter">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
</head>
<body>
<main class="container">
<header class="headings">
<h1>Bank statement XML convertor</h1>
<h2>ISO 20022 CAMT.053 to OFX free online conversion</h2>
</header>
<section>This simple webpage loads the bank statement with account balance and all transactions - exported as an XML file from an European (esp. Swiss) online banking systems in <a href="https://www.iso20022.org/">ISO20022</a> SEPA <a href="https://www.six-group.com/dam/download/banking-services/standardization/sps/ig-cash-management-delta-guide-sps2022-en.pdf">camt.053 XML format</a>, it transforms the data and generates <a href="https://financialdataexchange.org/ofx">Open Financial Exchange (OFX) format</a> suitable for import into <a href="https://www.xero.com/">Xero</a> and other accounting and financial systems.
</section>
<input id="input" type="file" >
<a id="download" role="button" onClick="return(buttonClick())" href="">Convert & Download</a>
<blockquote>
<b>Secure - your data are not submitted anywhere.</b> Conversion happens directly in your web browser locally using in-browser XSLT transformation (camt2ofx.xsl) without any server.
Open-source code including the XSL transformation itself is available at <a href="https://github.com/maptiler/iso2ofx">https://github.com/maptiler/iso2ofx</a>.
</blockquote>
</main>
<script type="text/javascript">
function transform(xml_content, xslt_url, callback) {
xslt = new XMLHttpRequest();
xslt.onreadystatechange = function() {
if (xslt.readyState == 4) {
// strip namespace - to process all versions of CAMT.053.001*
var xml_no_ns = xml_content.replace(/<(\w+)([^>]*)\s+xmlns="urn:iso:std:iso:20022:tech:xsd:camt\.053\.001[^"]+"\s*([^>]*)>/, '<$1$2$3>');
// console.log(xml_no_ns);
var xml = new DOMParser().parseFromString(xml_no_ns, "text/xml");
var processor = new XSLTProcessor();
processor.importStylesheet(xslt.responseXML);
var resultDoc = processor.transformToFragment(xml, document);
// callback(resultDoc.textContent);
callback('<?xml version="1.0" encoding="UTF-8"?>\n'+new XMLSerializer().serializeToString(resultDoc));
}
};
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/xml'
}));
a.download = targetFilename();
}
function targetFilename() {
var fileName = document.getElementById("input").files[0].name;
return fileName.replace('.xml', '.ofx');
}
document.getElementById("input").addEventListener("change", handleFiles, false);
function handleFiles() {
var reader = new FileReader();
reader.onload = function(e) {
transform(reader.result, 'camt2ofx.xsl', download);
}
reader.readAsText(this.files[0]);
}
function buttonClick() {
var i = document.getElementById("input");
if (i.files.length == 0) {
alert("Choose CAMT053 XML file exported from your online banking first"); return false;
}
}
</script>
<script type="module">
/* TODO - finish the MT940 support first
import * as mt940 from './mt940-js/index.js';
fetch('test.mt940')
.then((response) => response.arrayBuffer())
.then((buffer) => {
mt940.read(buffer).then((statements) => {
// List of the Statements
console.log(statements);
});
});
*/
</script>
</body>
</html>