1

クライアントから次の石鹸の封筒が届きました

<soap:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Header>
  <wsa:Action>http://company.com/services/InterfacePoint/CallResponse</wsa:Action>
  <wsa:MessageID>uuid:85fafb9d-9ec0-4017-a367-4f9043812310</wsa:MessageID>
  <wsa:To>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:To>
  <wsse:Security>
     <wsu:Timestamp wsu:Id="Timestamp-dc059677-19f6-4b2c-a69b-ec0dffc6b1db">
        <wsu:Created>2013-03-28T16:24:33Z</wsu:Created>
        <wsu:Expires>2013-03-28T16:29:33Z</wsu:Expires>
     </wsu:Timestamp>
  </wsse:Security>
</soap:Header>
<soap:Body>
  <TXLife xsi:schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.22.00.XSD" xmlns="http://ACORD.org/Standards/Life/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  .
  .
  . 
  </TXLife>
 </soap:Body> 
</soap:Envelope>

soap:Body内部にあるものを取得し、他のすべてを破棄することに興味があります。私はXSLTそれを抽出するためにこれを書きました

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  <xsl:template match="soap:Envelope/soap:Body">
      <xsl:copy-of select="@*|node()" />    
  </xsl:template> 
</xsl:stylesheet>

これXSLTは、soap エンベロープにヘッダーがない場合は正常に機能しますが、これを上記に適用するとXML、ヘッダー要素の値も出力されるため、生成される出力は次のようになります。

http://company.com/services/InterfacePoint/CallResponseuuid:85fafb9d-9ec0-4017-a367-4f9043812310http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous2013-03-28T16:24:33Z2013-03-28T16:29:33Z<TXLife xmlns="http://ACORD.org/Standards/Life/2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xsi:schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.22.00.XSD">
.
.
.
</TXLife>

しかし、私は出力を次のようにしたい:

<TXLife xmlns="http://ACORD.org/Standards/Life/2">
.
.
.
</TXLife>

他の名前空間が存在するかどうかは気にしません。

4

1 に答える 1

3

これは、コンテンツを出力にコピーするテキスト ノードのデフォルト テンプレートがあるためです。アプローチを機能させるには、追加してそれを抑制する必要があります

<xsl:template match="text()" />

ここで、soap:Body子要素が 1 つだけあれば、整形式の結果が得られますが、追加の名前空間宣言が含まれます。

コピーではなく ID テンプレートを使用して、別の角度から問題に取り組みます。XSLT 2.0 には、不要な名前空間宣言を削除するcopy-namespaces="no"ために使用できる便利な機能があります。<xsl:copy>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <!-- extract just the first child of the body -->
  <xsl:template match="/">
    <xsl:apply-templates select="/soap:Envelope/soap:Body/*[1]" />
  </xsl:template>

  <!-- identity template, but dropping namespace declarations not used
       directly by this element -->
  <xsl:template match="@*|node()">
    <xsl:copy copy-namespaces="no">
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <!-- drop xsi:schemaLocation attributes -->
  <xsl:template match="@xsi:schemaLocation" />
</xsl:stylesheet>
于 2013-03-28T17:00:46.057 に答える