2016-09-23 20 views
0

私は入力XMLを持っています。ここで、S:Fault xmlns:ns4 = "http://www.w3.org/2003/05/soap-envelope"これはfaultstingノードからデータを取得することに問題があります。 。動作していない名前空間の問題

<?xml version="1.0" encoding="UTF-8"?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> 
      <faultcode>S:Server</faultcode> 
      <faultstring>The GTIN is not valid or the system can not map the Company Prefix to an existing Company Prefix from the Setting</faultstring> 
     </S:Fault> 
    </S:Body> 
</S:Envelope> 

XLSTコード...

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="example" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns4="http://www.w3.org/2003/05/soap-envelope" 
exclude-result-prefixes="S ns4"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <xsl:template match="/S:Envelope"> 
      <ns0:MT_CreateSerialNumberResponse_IB xmlns:ns0="example"> 
      <serialNumberList xmlns="urn:abcd:1"> 
       <body> 
        <message> 
         <xsl:value-of select="S:Body/ns4:Fault/ns4:faultstring"/> 
        </message> 
       </body> 
      </serialNumberList> 
     </ns0:MT_CreateSerialNumberResponse_IB> 
    </xsl:template> 
</xsl:stylesheet> 

期待される結果...私は何か

<ns0:MT_CreateSerialNumberResponse_IB xmlns:ns0="example"> 
    <serialNumberList xmlns="urn:abcd:1"> 
     <body><message>The GTIN is not valid or the system can not map the Company Prefix to an existing Company Prefix from the Setting</message> 
     </body> 
    </serialNumberList> 
</ns0:MT_CreateSerialNumberResponse_IB> 

答えて

1

この

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="example" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns4="http://www.w3.org/2003/05/soap-envelope" 
exclude-result-prefixes="S ns4"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <xsl:template match="/S:Envelope"> 
      <ns0:MT_CreateSerialNumberResponse_IB xmlns:ns0="example"> 
      <serialNumberList xmlns="urn:abcd:1"> 
       <body> 
        <message> 
         <xsl:value-of select="S:Body/S:Fault/faultstring"/> 
        </message> 
       </body> 
      </serialNumberList> 
     </ns0:MT_CreateSerialNumberResponse_IB> 
    </xsl:template> 
</xsl:stylesheet> 
+0

XSLT検証のための無料のオンラインツールがあります。http:// xslttestが。 appspot.com/ – Naidu

1
  1. を試してみてくださいを逃した場合、名前付けられた入力XMLでのノードが存在しないコードのエラーを見つける助けてくださいns4:。これにより、名前空間宣言xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"が完全に冗長化されます(XMLとXSLTの両方で)。

  2. デフォルトの(接頭辞なし)のみが継承されます。 faultstring要素には接頭辞がなく、スコープ内にデフォルトの名前空間宣言はありません。それは、(S:Envelopeのコンテキストから)それはノー名前空間にあることを意味し、それへのパスは次のとおりです。

    S:Body/S:Fault/faultstring

関連する問題