【问题标题】:XSLT transformation JSON to XML Error "Content is not allowed in prolog"XSLT 将 JSON 转换为 XML 错误“序言中不允许内容”
【发布时间】:2019-09-23 10:30:30
【问题描述】:

我想将 JSON 文件转换为 xml。

java -jar c:\saxon\saxon9he.jar -s:C:json -xsl:C:test.xsl -o:C:xml

用于转换的 XSLT:

>     <?xml version="1.0" encoding="ISO-8859-1"?>
>     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
>         <xsl:output method="xml" indent="yes"/>
>         <xsl:param name="input" select="'../json/test.json'"/>
>         <xsl:template name="xsl:initial-template">
>             <xsl:apply-templates select="json-to-xml(unparsed-text($input))" mode="copy"/>
>         </xsl:template>
>         <xsl:template match="node() | @*" mode="copy">
>             <xsl:copy>
>                 <xsl:apply-templates select="node() | @*" mode="copy"/>
>             </xsl:copy>
>         </xsl:template>    
>     </xsl:stylesheet>

我认为处理器需要一个 XML 文件作为输入。我必须使用哪个处理器还是有其他错误?

提前致谢!

【问题讨论】:

    标签: json xslt saxon xslt-3.0


    【解决方案1】:

    您可以使用命令行选项-it 来开始处理命名模板xsl:template name="xsl:initial-template"。然后,您可以将任何 JSON 文件作为参数传入,就像您的示例已经在代码中所做的那样,在命令行上添加 input=foo.json 以更改/设置该全局参数。所以根本不要使用-s,而是使用-it(如给定的)并为input参数添加正确的参数值,无论是在您拥有的代码中还是在命令行中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-30
      • 1970-01-01
      • 2023-04-10
      • 2012-07-19
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多