【发布时间】:2021-07-22 13:27:33
【问题描述】:
我想使用 XSLT 将 JSON 转换为 XML。但无法达到预期的输出。 下面是 JSON 请求:
{
"Store": [
{
"Book": "Cartoons",
"ID": "ABC"
}
]
}
我尝试过的 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:emp="http://www.semanticalllc.com/ns/employees#"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:j="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="xs math xd h emp"
version="3.0"
expand-text="yes">
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="json-to-xml(.)/*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@key]" xpath-default-namespace="http://www.w3.org/2005/xpath-functions">
<xsl:element name="{@key}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
但我的响应是空的。
【问题讨论】:
-
我想您的 json 需要在 xml 文件中,或者您将 json 作为根参数传递:请参阅:stackoverflow.com/q/58113843/3710053
-
我已经浏览了链接并尝试了。但仍然不适合我。是否可以使用 XSLT 2.0 或 1.0 版本进行转换?
-
一切皆有可能......“有志者事竟成。”但现在我建议考虑使用 3.0。因此,请将您的 xslt/xml 更新为您的最新尝试。
-
我已经更新了我尝试使用您提供的链接的 XSLT。同样的问题。不工作。
标签: json xml xslt ibm-datapower