【问题标题】:XSLT String building with loop使用循环构建 XSLT 字符串
【发布时间】:2015-12-08 09:08:50
【问题描述】:

我正在尝试使用 XSLT 执行以下操作,看起来应该相当简单,但我似乎无法理解。

发件人:

<xml version="1.0" encoding="utf-8"?>
<updateUserDetails>
    <updateUserInfo>
        <userIdentifier>9999</v1:userIdentifier>
        <firstName>K1</v1:firstName>
        <lastName>T1</v1:lastName>
    <updateUserInfo>
    <updateUserInfo>
        <userIdentifier>9998</v1:userIdentifier>
        <firstName>K2</v1:firstName>
        <lastName>T2</v1:lastName>
    </updateUserInfo>
</updateUserDetails>

收件人:

"userIdentifier": "9999"
{
"firstName": "K1",
"lastName": "T1"
}
"userIdentifier": "9998"
{
"firstName": "K2",
"lastName": "T2"
}

【问题讨论】:

  • 这是 JSON 输出吗?如果是这样,请考虑标记以便其他 SO 人员可以找到它。我知道有很多关于 XML 到 JSON 转换的 Q/A。另外,由于最终使用格式不同,您不能使用 XSLT 样式表,但必须使用 C#、Java、PHP、Python、VB 等编码语言。
  • 是的,它是通过 PowerPoint 进行的 JSON 转换,必须使用 XSLT 来获取格式,端点通信已处理,但需要正确提交,更新标签,谢谢。
  • 您的 XML 格式不正确。您删除了前缀,但不是到处都是,加上 XML 声明中缺少的字符。另请注意,如果没有名称空间,XSLT 会有所不同。因此,发布 XML 尽可能接近原始文件是有意义的,包括命名空间。
  • 实际上,JSON 看起来也不像格式良好的 JSON...
  • 请搜索 XSLT + JSON,研究示例,如果在实现这些示例时遇到特定问题,请返回。

标签: json xslt powerpoint


【解决方案1】:

究竟是什么问题?

<xsl:template match="updateUserInfo">
"userIdentifier": "<xsl:value-of select='userIdentifier'/>"
{
  "firstName": "<xsl:value-of select='firstName'/>",
  "lastName": "<xsl:value-of select='lastName'/>"
}
</xsl:template>

您可能会遇到一些小问题,因为您的输入不是有效的 XML,并且您想要的输出不是有效的 JSON,但我希望您能解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 2016-08-14
    相关资源
    最近更新 更多