1

SOAPドキュメントの名前空間を変更する必要があります。名前空間のみを変更する必要があり、他のすべてのSOAPはそのままにしておきます。

これが私のSOAPドキュメントです。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:tar="namespace1" 
                  xmlns:tar1="namespace1">
   <soapenv:Header/>
   <soapenv:Body>
      <tar:RegisterUser>
         <tar1:Source>?</tar1:Source>
         <tar1:Profile>
            <tar1:EmailAddress>?</tar1:EmailAddress>

            <tar1:NewEmailAddress>?</tar1:NewEmailAddress>

            <tar1:GivenName>?</tar1:GivenName>

         </tar1:Profile>
      </tar:RegisterUser>
   </soapenv:Body>
</soapenv:Envelope>

namespace1たとえばnamespace2で変更したい。これが私の変容です:

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:old="namespace1"
    xmlns:new="namespace2">

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="old:*">
        <xsl:element name="{local-name()}" xmlns="namespace2" >
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

しかし、実行すると、次の出力が得られます。

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar="namespace1" xmlns:tar1="namespace1">
   <soapenv:Header/>
   <soapenv:Body>
      <RegisterUser>
         <Source>?</Source>
         <Profile>
            <EmailAddress>?</EmailAddress>

            <NewEmailAddress>?</NewEmailAddress>

            <GivenName>?</GivenName>

         </Profile>
      </RegisterUser>
   </soapenv:Body>
</soapenv:Envelope>

名前空間だけを変更したい。要素から削除されたプレフィックスではありません。多分誰かが問題がどこにあるか知っていますか?

4

1 に答える 1

2

この変換

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:tar="namespace2" xmlns:tar1="namespace2"
  xmlns:old="namespace1">

  <xsl:output omit-xml-declaration="yes"/>

  <xsl:variable name="vNewNamespaces" select=
   "document('')/*/namespace::*[name()='tar' or name()='tar1']"/>

    <xsl:template match="@*|node()">
     <xsl:copy-of select="."/>
    </xsl:template>

    <xsl:template match="*">
        <xsl:element name="{name()}">
          <xsl:copy-of select=
          "namespace::*[not(name()='tar' or name()='tar1')] | $vNewNamespaces"/>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="old:*">
        <xsl:element name="{name()}" xmlns="namespace2" >
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

提供されたXMLドキュメントに適用した場合

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:tar="namespace1"
                  xmlns:tar1="namespace1">
    <soapenv:Header/>
    <soapenv:Body>
        <tar:RegisterUser>
            <tar1:Source>?</tar1:Source>
            <tar1:Profile>
                <tar1:EmailAddress>?</tar1:EmailAddress>
                <tar1:NewEmailAddress>?</tar1:NewEmailAddress>
                <tar1:GivenName>?</tar1:GivenName>
            </tar1:Profile>
        </tar:RegisterUser>
    </soapenv:Body>
</soapenv:Envelope>

必要な正しい結果を生成します

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar="namespace2" xmlns:tar1="namespace2">
    <soapenv:Header/>
    <soapenv:Body>
        <tar:RegisterUser>
            <tar1:Source>?</tar1:Source>
            <tar1:Profile>
                <tar1:EmailAddress>?</tar1:EmailAddress>
                <tar1:NewEmailAddress>?</tar1:NewEmailAddress>
                <tar1:GivenName>?</tar1:GivenName>
            </tar1:Profile>
        </tar:RegisterUser>
    </soapenv:Body>
</soapenv:Envelope>
于 2012-07-27T13:26:38.020 に答える