【问题标题】:How to extract this XML Objects with XSLT如何使用 XSLT 提取此 XML 对象
【发布时间】:2016-11-05 06:50:54
【问题描述】:

我想从 XML 文件中提取 JSONx 数据以转换为 JSON。所以我需要从这个文件中提取 json:object

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/ envelope/">
<soapenv:Body>
<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/
jsonx" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi:schemaLocation="http://www.datapower.com/ schemas/json jsonx.xsd">
<json:string name="Number">XXX</json :string>
<json:string name="name">XXX</json:string> <json:string name="Date">4/84</json:string> <json:string name="amount">123</json:string>
</json:object> </soapenv:Body>
</soapenv:Envelope>

结果应该是这样的

<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/
jsonx" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi:schemaLocation="http://www.datapower.com/ schemas/json jsonx.xsd">
<json:string name="Number">XXX</json :string>
<json:string name="name">XXX</json:string> <json:string name="Date">4/84</json:string> <json:string name="amount">1234</json:string>
</json:object> 

【问题讨论】:

    标签: json xml xslt


    【解决方案1】:

    假设 XSLT 2.0 您可以使用 xsl:copy-ofcopy-namespaces="no" 排除 SOAP 命名空间:

    <xsl:template match="/">
        <xsl:copy-of select="//object" xpath-default-namespace="http://www.ibm.com/xmlns/prod/2009/jsonx" copy-namespaces="no"/>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多