1
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <soapenv:Body>
      <tns:send xmlns:tns="http://www.test.com/Service/v3">
         <NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT">

            <NS2:Body>
               <NS2:New>
                  <NS2:Pharmacy>
                     <NS2:Identification>
                        <NS2:ID>
                           <NS2:IDValue>01017</NS2:IDValue>
                           <NS2:IDQualifier>94</NS2:IDQualifier>
                           <NS2:IDRegion>SCA</NS2:IDRegion>
                            <NS2:IDState>CA</NS2:IDState>
                        </NS2:ID>
                             </NS2:Identification>
                             </NS2:Pharmacy>
                    </NS2:New>
            </NS2:Body>
         </NS2:Message>
      </tns:send>
   </soapenv:Body>
</soapenv:Envelope>

スキーマ バージョン 3.0 http://www.test.com/Service/v3にあるこの xml があります。バージョン 1 http://www.test.com/Service/v1にダウングレードする必要があります。そのために、XSL を使用して変換しています。

        <?xml version="1.0" encoding="ISO-8859-1"?>
        <xsl:stylesheet version="2.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
            xmlns:booga="http://schemas.xmlsoap.org/wsdl/"
            xmlns:tns="http://www.test.com/Service/v3"
            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:src="http://www.ncpdp.org/schema/SCRIPT"
        > 


        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

        <xsl:strip-space elements="*"/>


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

           </xsl:copy>

         </xsl:template>

         <xsl:template match="tns:*">
            <!-- Output a new element in the new namespace -->
            <xsl:element name="tns:{local-name()}" namespace="http://www.test.com/Service/v1">
              <!-- Copy all child attributes and nodes 
             <xsl:apply-templates select="node()|@*"/> -->
            <xsl:apply-templates  />
            </xsl:element>
          </xsl:template>

        </xsl:stylesheet>

しかし、私はこのような結果を得ます

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <soapenv:Body>
      <tns:send xmlns:tns="http://www.test.com/Service/v3">
         <NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" xmlns:tns="http://www.test.com/Service/v3">

            <NS2:Body>
               <NS2:New>
                  <NS2:Pharmacy>
                     <NS2:Identification>
                        <NS2:ID>
                           <NS2:IDValue>01017</NS2:IDValue>
                           <NS2:IDQualifier>94</NS2:IDQualifier>
                           <NS2:IDRegion>SCA</NS2:IDRegion>
                            <NS2:IDState>CA</NS2:IDState>
                        </NS2:ID>
                         </NS2:Identification>
                         </NS2:Pharmacy>
                    </NS2:New>
            </NS2:Body>
         </NS2:Message>
      </tns:send>
   </soapenv:Body>
</soapenv:Envelope>

私の出力XMLでは、これを取得します

<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT"   xmlns:tns="http://eps.pdxinc.com/webservice/Rxservice/v3"> 

なぜこれが に追加されたのNS2:Messageですか?

xmlns:tns="http://eps.pdxinc.com/webservice/Rxservice/v3 

入力xmlにはありませんでした。

欠けているものがあります。誰かが問題を指摘できれば本当にありがたいです。

出力で作成しようとしているのは次のとおりです。

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <tns:send xmlns:tns="http://www.test.com/Service/v1">
            <NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" >

                <NS2:Body>
                    <NS2:New>
                        <NS2:Pharmacy>
                            <NS2:Identification>
                                <NS2:ID>
                                    <NS2:IDValue>01017</NS2:IDValue>
                                    <NS2:IDQualifier>94</NS2:IDQualifier>
                                    <NS2:IDRegion>SCA</NS2:IDRegion>
                                    <NS2:IDState>CA</NS2:IDState>
                                </NS2:ID>
                            </NS2:Identification>
                        </NS2:Pharmacy>
                    </NS2:New>
                </NS2:Body>
            </NS2:Message>
        </tns:send>
    </soapenv:Body>
</soapenv:Envelope>

私が適用している XSL ドキュメントは xmlns:tns="http://www.test.com/Service/v3NS2:Message.

元のタグは次のとおりです。

<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT">

XSLを適用した後、次のように変更されました:

<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" xmlns:tns="http://www.test.com/Service/v3>

この名前空間がどこに追加されるのかわかりません。

私が望んでいたのは、タグ内に変換xmlns:tns="http://www.test.com/Service/v3することだけでした。xmlns:tns="http://www.test.com/Service/v3tns:send

4

1 に答える 1

3

これを試して...

XML 入力

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <tns:send xmlns:tns="http://www.test.com/Service/v3">
            <NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT">

                <NS2:Body>
                    <NS2:New>
                        <NS2:Pharmacy>
                            <NS2:Identification>
                                <NS2:ID>
                                    <NS2:IDValue>01017</NS2:IDValue>
                                    <NS2:IDQualifier>94</NS2:IDQualifier>
                                    <NS2:IDRegion>SCA</NS2:IDRegion>
                                    <NS2:IDState>CA</NS2:IDState>
                                </NS2:ID>
                            </NS2:Identification>
                        </NS2:Pharmacy>
                    </NS2:New>
                </NS2:Body>
            </NS2:Message>
        </tns:send>
    </soapenv:Body>
</soapenv:Envelope>

XSLT 1.0 (バージョンを変更した場合は 2.0)

(編集:プレフィックスが重要ではないことを示すために、「tns」プレフィックスを「djh」に変更しました。)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:djh="http://www.test.com/Service/v3"
    xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|comment()|processing-instruction()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="djh:*">
        <xsl:element name="{name()}" namespace="http://www.test.com/Service/v1">
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>  
    </xsl:template>

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

</xsl:stylesheet>

XML 出力

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <tns:send xmlns:tns="http://www.test.com/Service/v1">
         <NS2:Message xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" release="006" version="010">
            <NS2:Body>
               <NS2:New>
                  <NS2:Pharmacy>
                     <NS2:Identification>
                        <NS2:ID>
                           <NS2:IDValue>01017</NS2:IDValue>
                           <NS2:IDQualifier>94</NS2:IDQualifier>
                           <NS2:IDRegion>SCA</NS2:IDRegion>
                           <NS2:IDState>CA</NS2:IDState>
                        </NS2:ID>
                     </NS2:Identification>
                  </NS2:Pharmacy>
               </NS2:New>
            </NS2:Body>
         </NS2:Message>
      </tns:send>
   </soapenv:Body>
</soapenv:Envelope>
于 2012-10-06T22:27:23.380 に答える