如何使用 XSLT 1.0 更改 xml 根命名空间

问题描述 投票:0回答:1

我是 XSLT 映射新手,我有一项任务需要更改根命名空间。

这是我的示例 xml

<ns1:ShipStatusResponse xmlns:ns1="http://test.com/pi/VN/ABC/Invoice/10">
  <httpcode>200</httpcode>
  <httpstatus>OK</httpstatus>
  <httpresult>test</httpresult>
</ns1:ShipStatusResponse>

我的预期输出 xml 会是这样的

<ns1:ShipStatusResponse xmlns:ns1="http://test.com/pi/ERP/FICO/Invoice/10">
  <httpcode>200</httpcode>
  <httpstatus>OK</httpstatus>
  <httpresult>test</httpresult>
</ns1:ShipStatusResponse>
xslt namespaces
1个回答
0
投票

您基本上需要 (a) 一个身份模板来默认复制不更改的内容,以及 (b) 一个规则,例如

<xsl:template match="ns1:ShipStatusResponse" xmlns:ns1="http://test.com/pi/VN/ABC/Invoice/10">
  <xs:element name="ns1:{local-name()}" namespace="http://test.com/pi/ERP/FICO/Invoice/10">
    <xsl:apply-templates/>
  </xs:element>
</xsl:template> 

让它使用正确的名称空间前缀可能会遇到一些困难,因为 XSLT 1.0 不提供关于结果文档中使用的名称空间前缀的保证(在以后的版本中有更多说明)。

© www.soinside.com 2019 - 2024. All rights reserved.