XML to JSON Transformation in XSLT 3.0 [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-02 14:08:57

You need to transform your XML into the XML vocabulary expected by the xml-to-json function, which you can do using template rules such as

<xsl:template match="*[*|@*]" mode="to-json">
  <fn:map key="{local-name()}">
    <xsl:apply-templates select="@*, *" mode="to-json"/>
  </fn:map>
</xsl:template>

<xsl:template match="@* | *[not(*)]" mode="to-json">
  <fn:string key="{local-name()}">
    <xsl:value-of select="."/>
  </fn:string>
</xsl:template>

and then pass the result of this transformation to the xml-to-json function.

The detail will depend on what you want to do about namespaces, how you want to detect that elements/attributes should be treated as numeric or boolean, whether you want to generate null or "" for empty elements, etc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!