使用 json-to-xml() 函数的 json 到 xml 的转换会以不希望的格式生成输出

json to xml transformation using json-to-xml() funtion produces output in undesirable format

我有 xsl 文件,我正在尝试将 xsl 模板应用于示例 json。它不是使用 json 键和值生成有效的 xml 文档,而是使用编码字符串生成格式错误的 xml。 下面是我 运行 使用的命令。

java -cp /Users/vn04pa5/.m2/repository/net/sf/saxon/Saxon-HE/9.9.1-1/Saxon-HE-9.9.1-1.jar net.sf.saxon.Transform -it:"initial-template" -xsl:"XBorderPOJSON.xsl" input='{
  "purchaseOrderNo": "yvueBluWlI",
  "sourceMarketOrderNo": "ZONWqmCorD",
  "destinationMarketOrderNo": "xFildoWLxd"}'

输出

<?xml version="1.0" encoding="UTF-8"?>yvueBluWlIZONWqmCorDxFildoWLxd

XSL 文件:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:param name="input"/>
 <xsl:template name="initial-template">
      <!--<xsl:value-of select="$input"/>-->
 <!--   <xsl:variable name="json" select="unparsed-text($input)"/>-->
    <xsl:apply-templates select="json-to-xml($input)"/>
    <!--  <xsl:value-of select="$json"/>-->
</xsl:template>
</xsl:stylesheet>

我是否必须使用专业版或 EE 版才能正常运行? 我有 java 产生相同输出的应用程序。

json-to-xml() 函数生成一个 XML 节点树。您正在将模板应用于该树的根,但您没有任何模板规则来处理这些节点。因此使用默认的模板规则;默认模板规则跳过元素和属性节点并仅输出文本节点。添加 <xsl:mode on-no-match="shallow-copy"/>,或简单地使用 xsl:copy-of(或 xsl:sequence)代替 xsl:apply-templates