简体   繁体   English

saxonjs 忽略 json 输入的匹配规则

[英]saxonjs ignores match rules for json input

I'm trying to convert a json input into xml by using saxonjs, this is a simplified version of my code我正在尝试使用 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');
    });

My xslt stylesheet is like this:我的 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>

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?结果总是空的或更准确地说<?xml version="1.0" encoding="utf-8"?>如果我用 match="issue" 或 "/issue" 替换 match="/" 结果是一样的,我究竟做错了什么?

/ matches a document node or document fragment node, your item is not a node but an XPath 3.1 map, use match="." /匹配文档节点或文档片段节点,您的项目不是节点,而是 XPath 3.1 map,使用match="." to match any item, match=".[. instance of map(*)]" to match any map item.匹配任何项目, match=".[. instance of map(*)]"匹配任何 map 项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM