0

我正在尝试使用 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="issue" 或 "/issue" 替换 match="/" 结果是一样的,我做错了什么?

4

1 回答 1

1

/匹配文档节点或文档片段节点,您的项目不是节点而是 XPath 3.1 映射,用于match="."匹配任何项目,match=".[. instance of map(*)]"匹配任何地图项目。

于 2021-12-08T14:30:01.283 回答