-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransform.js
40 lines (34 loc) · 980 Bytes
/
transform.js
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
import { join } from 'path';
import SaxonJS from 'saxon-js';
/* GET request */
export const transformGet = (req, res) => {
const transformViewFilePath = join(req.context.folder.root, req.context.folder.views, 'transform.html')
res.sendFile(transformViewFilePath);
};
/* POST request */
export const transformPost = (req, res) => {
const { "stylesheet": stylesheetFileName } = req.query;
const stylesheetFilePath = join(req.context.folder.stylesheets, stylesheetFileName);
const source = req.rawBody;
const params = { ...req.params };
SaxonJS.transform({
stylesheetFileName: stylesheetFilePath,
sourceText: source,
stylesheetParams: params,
destination: "serialized",
outputProperties:{
method: "xml",
indent: false
}
},
"async"
)
.then(output => {
res.set('Content-Type', 'text/xml');
res.send(output.principalResult);
})
.catch(error => {
/* console.error(error); */
res.status(400).send(error.message);
});
};