0

私はこのソースを持っています:

<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 ファイルがあれば素晴らしいでしょう.....

4

1 に答える 1

0

XSLT を次のように変更すると:

<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:GetFdrRewardsResponse">
        <sc_3:GetFdrRewardsResponse>
            <xsl:apply-templates select="node()|@*"/>
        </sc_3:GetFdrRewardsResponse>
    </xsl:template>
</xsl:stylesheet>

目的の出力はほぼ希望どおりですが、出力には次の名前空間が含まれています。

xmlns:sc="http://somecompany.com/soa/cardaccount1.1/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

でも誰も傷つけてはいけません

于 2013-02-19T20:23:27.747 に答える