我有这个来源:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<sc:GetFdrRewardsResponse xmlns:sc="http://somecompany.com/soa/cardaccount1.1/schema"
xmlns:sc_1="http://somecompany.com/soa/common1.1/schema"
xmlns:sc_2="http://somecompany.com/soa/common/schema"
xmlns:sc_3="http://somecompany.com/soa/cardaccount/schema">
<sc_1:ResponseCode>0000</sc_1:ResponseCode>
<sc_1:ResponseMessage>Successful Execution</sc_1:ResponseMessage>
<sc_1:CorrelationId>1234</sc_1:CorrelationId>
<sc:FdrRewards>
<sc_2:BankNumber>0175</sc_2:BankNumber>
<sc:IsRewardsMember>true</sc:IsRewardsMember>
<sc:IsEligibleToRedeem>true</sc:IsEligibleToRedeem>
<sc_3:AmazingRewardsBalance>10442.00</sc_3:AmazingRewardsBalance>
<sc_3:CashBackSavingsBalance>0.00</sc_3:CashBackSavingsBalance>
</sc:FdrRewards>
</sc:GetFdrRewardsResponse>
</soapenv:Body>
</soapenv:Envelope>
并且需要这个结果:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<sc_3:GetFdrRewardsResponse
xmlns:sc_1="http://somecompany.com/soa/common1.1/schema"
xmlns:sc_2="http://somecompany.com/soa/common/schema"
xmlns:sc_3="http://somecompany.com/soa/cardaccount/schema" >
<sc_1:ResponseCode>0000</sc_1:ResponseCode>
<sc_1:ResponseMessage >Successful Execution</sc_1:ResponseMessage>
<sc_1:CorrelationId >1234</sc_1:CorrelationId>
<sc_3:FdrRewards>
<sc_2:BankNumber >0175</sc_2:BankNumber>
<sc_3:AmazingRewardsBalance>10442.00</sc_3:AmazingRewardsBalance>
<sc_3:CashBackSavingsBalance>0.00</sc_3:CashBackSavingsBalance>
</sc_3:FdrRewards>
</sc_3:GetFdrRewardsResponse>
</soapenv:Body>
</soapenv:Envelope>
我正在使用这个转换:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sc="http://somecompany.com/soa/cardaccount1.1/schema"
xmlns:sc_1="http://somecompany.com/soa/common1.1/schema"
xmlns:sc_2="http://somecompany.com/soa/common/schema"
xmlns:sc_3="http://somecompany.com/soa/cardaccount/schema"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="sc:IsRewardsMember"/>
<xsl:template match="sc:IsEligibleToRedeem"/>
<xsl:template match="sc:*">
<xsl:element name="sc_3:{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这几乎可以工作。它将生成的命名空间声明放在每个子元素上,而不是在父元素中声明一次。
有任何想法吗?一个完整的 XSLT 文件会很棒......