【发布时间】:2022-01-13 11:53:12
【问题描述】:
我正在尝试使用 saxonjs 将 json 输入转换为 xml,这是我的代码的简化版本
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');
});
我的 xslt 样式表是这样的:
<?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>
结果总是空的或更准确地说是<?xml version="1.0" encoding="utf-8"?> 如果我将 match="/" 替换为 match="issue" 或 "/issue" 结果是一样的,我做错了什么?
【问题讨论】:
标签: json xml xslt xslt-3.0 saxon-js