【问题标题】:saxonjs 忽略 json 输入的匹配规则
【发布时间】: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>

结果总是空的或更准确地说是&lt;?xml version="1.0" encoding="utf-8"?&gt; 如果我将 match="/" 替换为 match="issue" 或 "/issue" 结果是一样的,我做错了什么?

【问题讨论】:

    标签: json xml xslt xslt-3.0 saxon-js


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 2016-02-03
      • 1970-01-01
      相关资源
      最近更新 更多