I'm trying to convert a json input into xml by using saxonjs, this is a simplified version of my code
const fs = require('fs');
const saxonJS = require('saxon-js');
const input = JSON.stringify({issue: {id: 'A001', number: 200 }});
saxonJS.transform({
stylesheetLocation: './issues.sef.json',
sourceType: 'json',
sourceText: JSON.stringify(input),
destination: 'serialized'}, 'async').then(data => {
console.log(data.principalResult);
res.status(200).send('Ok');
});
})
.catch(err => {
console.log(err);
res.status(500).send('error');
});
My xslt stylesheet is like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<Issue xmlns="urn:mycompany:2021">
</Issue>
</xsl:template>
</xsl:stylesheet>
The result is always empty or more precisely <?xml version="1.0" encoding="utf-8"?>
If I replace match="/" with match="issue" or "/issue" the result is the same, what am I doing wrong?
CodePudding user response:
/
matches a document node or document fragment node, your item is not a node but an XPath 3.1 map, use match="."
to match any item, match=".[. instance of map(*)]"
to match any map item.