xslt-3.0 - XSLT 3:将 xml 转换为 json
问题描述
当我尝试使用 XSLT3 将 XML 转换为 JSON 时 <xsl:copy-of select="xml-to-json($finalOutPut, map { 'indent' : false() })"/>
我收到以下错误:net.sf.saxon.s9api.SaxonApiException: xml-to-json: element found in wrong namespace: Q{}wrapper
基本上我正在将一个 xml 转换为另一个 xml,重命名某些字段。将此 xml 作为输入传递给 xml-to-json() 。
有什么建议么?
解决方案
使用的 XML 格式xml-to-json
在 XSLT 3.0 规范 ( https://www.w3.org/TR/xslt-30/#json-to-xml-mapping ) 以及 XPath 和 XQuery 3.1 函数规范中都指定了:https ://www.w3.org/TR/xpath-functions/#json 。
基本上所有元素都需要在命名空间中,http://www.w3.org/2005/xpath-functions
并且是map
、array
、string
、boolean
等number
,以反映 JSON 数据类型。
错误消息表明您的输入包含一个wrapper
在 no namespace 中命名的元素,因此这肯定不是该函数的正确格式。您将需要使用额外的转换步骤将您的 XML 转换为函数期望的格式。
推荐阅读
- javascript - 在纯 JS 刽子手中防止重复输入字母的麻烦
- sql - 选择值为“如果 Id 存在于另一个表/视图中”的列
- c# - Unity如何在OnTriggerEnter2D中放置多个if语句?
- node.js - Sequelize 和 Postgres;如何设置值边界(总最小值/mac);和/或对更新运行验证
- ansible - ANSIBLE:访问 YAML 清单中的“深层”变量
- c# - Windows Presentation Foundation 如何使用代码将项目添加到 Listview
- powershell - 如何使用 Powershell 删除所有有异常的组?
- python-3.x - Tensorflow - 如何获得预测函数结果的准确性?
- sql-server - SET ANSI_WARNINGS ON 未将 ARITHABORT 值设置为 ON。文档是否正确?
- javascript - 带有 json 数据的香蕉精灵 js 动画(正向/反向和淡入淡出)