如何使用XSLT提取此XML对象

时间:2016-07-03 11:24:43

标签: json xml xslt

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

<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> 

1 个答案:

答案 0 :(得分:0)

假设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>