首页 > 解决方案 > 如何使用 XSLT 将 JSON 请求转换为 XML?

问题描述

我们以 JSON 形式接收具有不同值的输入请求。我必须使用 XSLT 1.0 将传入请求转换为 XML。我尝试使用带有函数 json-to-xml() 的 XSLT 3.0 进行转换,但它对我不起作用。我应该如何使用 XSLT 1.0 版转换传入请求?

要求:

{
  "Text": [
    {
      "from": "9878744785",
      "to": "998777945"
    }
  ]
}

预期反应:

<?xml version="1.0" encoding="UTF-8"?>
<Text>
<from>9878744785</from>
<to>998777945</to>
</Text>

XSLT 我试过:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0">

  <xsl:output indent="yes"/>


  <xsl:template match="/">
    <xsl:copy-of select="json-to-xml(root)"/>
  </xsl:template>

</xsl:stylesheet>

标签: jsonxmlxslt

解决方案


推荐阅读