-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
340 lines (316 loc) · 11.2 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html
lang="en"
data-bs-theme="dark"
>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous"
/>
<link
rel="icon"
href="flip-brandmark-transparent-bkgd.svg"
type="image/x-icon"
/>
<title>Flip Online XSLT Parser</title>
</head>
<body>
<div class="container-fluid">
<!-- 1st row -->
<h1 style="text-align: center">Flip Online XSLT Parser</h1>
<!-- 2nd row -->
<div class="row align-items-end">
<!-- csv editor wrapper -->
<div class="col">
<!-- to put p tag and label components on the same row-->
<div class="row">
<div class="col"><p>CSV Input:</p></div>
<div class="col text-end">
<label>
<input
type="checkbox"
id="hasHeader"
/>
CSV has a header line
</label>
</div>
</div>
<!-- csv editor -->
<div id="csvEditor"></div>
</div>
<!-- xslt wrapper -->
<div class="col">
<!-- to put p tag and label components on the same row-->
<div class="row justify-content-end">
<div class="col"><p>XML Output Template:</p></div>
<div class="col text-end">
<button
id="csvToXmlBtn"
class="btn btn-primary btn-sm"
>
Convert to XML
</button>
</div>
</div>
<!-- xml template editor -->
<div id="xmlTempEditor"></div>
</div>
</div>
<div class="row">
<div
class="col-12"
style="height: 4px"
></div>
</div>
<!-- 3rd row -->
<div class="row">
<div class="col">
<p>XSLT Input XML:</p>
<div
id="xsltInputXmlEditor"
onChange="parse()"
></div>
</div>
<div class="col">
<p>XSLT:</p>
<div
id="xsltEditor"
onChange="parse()"
></div>
</div>
<div class="col">
<p>XSLT Output XML:</p>
<div id="xsltOutputXmlEditor"></div>
</div>
</div>
</div>
<script
async
src="https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.min.js"
crossorigin="anonymous"
></script>
<script type="importmap">
{
"imports": {
"@popperjs/core": "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/esm/popper.min.js",
"bootstrap": "https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.esm.min.js"
}
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script>
$(document).ready(function () {
var xsltOutputXmlEditor = $("#xsltOutputXmlEditor");
var xsltProcessor = new XSLTProcessor();
var xmlSerializer = new XMLSerializer();
var csvEditor = ace.edit("csvEditor", {
theme: "ace/theme/nord_dark",
mode: "ace/mode/javascript",
autoScrollEditorIntoView: true,
maxLines: 10,
minLines: 100,
fontSize: "10pt",
tabSize: 2,
hasCssTransforms: true,
wrap: true,
printMargin: false,
value: "Enter or paste CSV here",
});
var xmlTempEditor = ace.edit("xmlTempEditor", {
theme: "ace/theme/nord_dark",
mode: "ace/mode/xml",
autoScrollEditorIntoView: true,
maxLines: 10,
minLines: 100,
fontSize: "10pt",
tabSize: 2,
hasCssTransforms: true,
wrap: true,
printMargin: false,
});
const xmlTemplate = `<Row>
<Cell FieldNo="1">{field1}</Cell>
<Cell FieldNo="2">{field2}</Cell>
<Cell FieldNo="3">{field3}</Cell>
<Cell FieldNo="4">{field4}</Cell>
<Cell FieldNo="5">{field5}</Cell>
<Cell FieldNo="6">{field6}</Cell>
<Cell FieldNo="7">{field7}</Cell>
<Cell FieldNo="8">{field8}</Cell>
<Cell FieldNo="9">{field9}</Cell>
<Cell FieldNo="10">{field10}</Cell>
<Cell FieldNo="11">{field11}</Cell>
<Cell FieldNo="12">{field12}</Cell>
<Cell FieldNo="13">{field13}</Cell>
<Cell FieldNo="14">{field14}</Cell>
<Cell FieldNo="15">{field15}</Cell>
<Cell FieldNo="16">{field16}</Cell>
<Cell FieldNo="17">{field17}</Cell>
<Cell FieldNo="18">{field18}</Cell>
<Cell FieldNo="19">{field19}</Cell>
<Cell FieldNo="20">{field20}</Cell>
<Cell FieldNo="21">{field21}</Cell>
<Cell FieldNo="22">{field22}</Cell>
<Cell FieldNo="23">{field23}</Cell>
<Cell FieldNo="24">{field24}</Cell>
<Cell FieldNo="25">{field25}</Cell>
<Cell FieldNo="26">{field26}</Cell>
<Cell FieldNo="27">{field27}</Cell>
<Cell FieldNo="28">{field28}</Cell>
<Cell FieldNo="29">{field29}</Cell>
<Cell FieldNo="30">{field30}</Cell>
<Cell FieldNo="31">{field31}</Cell>
<Cell FieldNo="32">{field32}</Cell>
<Cell FieldNo="33">{field33}</Cell>
<Cell FieldNo="34">{field34}</Cell>
<Cell FieldNo="35">{field35}</Cell>
<Cell FieldNo="36">{field36}</Cell>
<Cell FieldNo="37">{field37}</Cell>
<Cell FieldNo="38">{field38}</Cell>
<Cell FieldNo="39">{field39}</Cell>
<Cell FieldNo="40">{field40}</Cell>
<Cell FieldNo="41">{field41}</Cell>
<Cell FieldNo="42">{field42}</Cell>
<Cell FieldNo="43">{field43}</Cell>
<Cell FieldNo="44">{field44}</Cell>
<Cell FieldNo="45">{field45}</Cell>
<Cell FieldNo="46">{field46}</Cell>
<Cell FieldNo="47">{field47}</Cell>
<Cell FieldNo="48">{field48}</Cell>
<Cell FieldNo="49">{field49}</Cell>
<Cell FieldNo="50">{field50}</Cell>
<Cell FieldNo="51">{field51}</Cell>
<Cell FieldNo="52">{field52}</Cell>
<Cell FieldNo="53">{field53}</Cell>
<Cell FieldNo="54">{field54}</Cell>
<Cell FieldNo="55">{field55}</Cell>
<Cell FieldNo="56">{field56}</Cell>
<Cell FieldNo="57">{field57}</Cell>
<Cell FieldNo="58">{field58}</Cell>
<Cell FieldNo="59">{field59}</Cell>
<Cell FieldNo="60">{field60}</Cell>
<Cell FieldNo="61">{field61}</Cell>
<Cell FieldNo="62">{field62}</Cell>
<Cell FieldNo="63">{field63}</Cell>
<Cell FieldNo="64">{field64}</Cell>
<Cell FieldNo="65">{field65}</Cell>
<Cell FieldNo="66">{field66}</Cell>
<Cell FieldNo="67">{field67}</Cell>
<Cell FieldNo="68">{field68}</Cell>
<Cell FieldNo="69">{field69}</Cell>
<Cell FieldNo="70">{field70}</Cell>
<Cell FieldNo="71">{field71}</Cell>
<Cell FieldNo="72">{field72}</Cell>
<Cell FieldNo="73">{field73}</Cell>
<Cell FieldNo="74">{field74}</Cell>
<Cell FieldNo="75">{field75}</Cell>
<Cell FieldNo="76">{field76}</Cell>
<Cell FieldNo="77">{field77}</Cell>
<Cell FieldNo="78">{field78}</Cell>
<Cell FieldNo="79">{field79}</Cell>
<Cell FieldNo="80">{field80}</Cell>
<Cell FieldNo="81">{field81}</Cell>
<Cell FieldNo="82">{field82}</Cell>
<Cell FieldNo="83">{field83}</Cell>
<Cell FieldNo="84">{field84}</Cell>
<Cell FieldNo="85">{field85}</Cell>
<Cell FieldNo="86">{field86}</Cell>
<Cell FieldNo="87">{field87}</Cell>
<Cell FieldNo="88">{field88}</Cell>
<Cell FieldNo="89">{field89}</Cell>
</Row>`;
xmlTempEditor.setValue(xmlTemplate);
var xsltInputXmlEditor = ace.edit("xsltInputXmlEditor", {
theme: "ace/theme/nord_dark",
mode: "ace/mode/xml",
autoScrollEditorIntoView: true,
maxLines: 100,
minLines: 100,
fontSize: "10pt",
tabSize: 2,
hasCssTransforms: true,
wrap: true,
printMargin: false,
});
var xsltEditor = ace.edit("xsltEditor", {
theme: "ace/theme/nord_dark",
mode: "ace/mode/xml",
autoScrollEditorIntoView: true,
maxLines: 100,
minLines: 100,
fontSize: "10pt",
tabSize: 2,
hasCssTransforms: true,
wrap: true,
printMargin: false,
value: "Enter or paste XSLT here",
});
var xsltOutputXmlEditor = ace.edit("xsltOutputXmlEditor", {
theme: "ace/theme/nord_dark",
mode: "ace/mode/xml",
autoScrollEditorIntoView: true,
maxLines: 100,
minLines: 100,
fontSize: "10pt",
tabSize: 2,
hasCssTransforms: true,
wrap: true,
printMargin: false,
readOnly: true,
});
$("#csvToXmlBtn").click(function convertToXML() {
const topSection = `<?xml version="1.0"?>
<root>\n`;
const bottomSection = `\n</root>`;
var csvInput = csvEditor.getSession().getValue();
var hasHeader = document.getElementById("hasHeader").checked;
var xmlTemplate = xmlTempEditor.getSession().getValue();
var xmlOutput = "";
Papa.parse(csvInput, {
complete: function (results) {
const csvData = hasHeader ? results.data.slice(1) : results.data;
var rowSection = "";
csvData.forEach((row) => {
var xmlRow = xmlTemplate.replace(/{field(\d+)}/g, function (match, capture) {
var cellValue = row[capture - 1];
return cellValue !== undefined ? cellValue : "";
});
rowSection += xmlRow;
});
xmlOutput = topSection + rowSection + bottomSection;
xsltInputXmlEditor.setValue(xmlOutput);
},
});
});
function transformXML() {
try {
var xmlSource = xsltInputXmlEditor.getSession().getValue();
var xslSource = xsltEditor.getSession().getValue();
xsltProcessor.reset();
xsltProcessor.importStylesheet($.parseXML(xslSource));
resultDocument = xsltProcessor.transformToFragment($.parseXML(xmlSource), document);
xsltOutputXmlEditor.setValue(xmlSerializer.serializeToString(resultDocument));
} catch (error) {
xsltOutputXmlEditor.setValue(error.message);
}
}
xsltInputXmlEditor.getSession().on("change", function () {
setTimeout(transformXML, 100);
});
xsltEditor.getSession().on("change", function () {
setTimeout(transformXML, 100);
});
});
</script>
</body>
</html>