2016-11-14 8 views
0

を接頭辞の名前空間を削除します。XSLT - これは、SOAPヘッダとボディとの私のXMLである特定のノードのXMLに

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <RequestResponse xmlns="http://tempuri.org/"> 
      <a:RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting" 
      xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
       <a:Message>Message text testing.</a:Message> 
       <a:Response>false</a:Response> 
      </a:RequestResult> 
     </RequestResponse> 
    </s:Body> 
</s:Envelope> 

私はRequestResultノードからのみプレフィックスを削除する必要があります。この

<a:RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting" 
      xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 

乃至 :

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

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

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

    <xsl:template match="/"> 
     <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
      <s:Body> 
       <xsl:apply-templates /> 
      </s:Body> 
     </s:Envelope> 
    </xsl:template> 

    <xsl:template match="RequestResult |RequestResult//*"> 
     <xsl:element name="a:{name()}" 
      namespace="http://schemas.datacontract.org/2004/07/Testing"> 
      <xsl:namespace name="a" 
       select="'http://schemas.datacontract.org/2004/07/MockupTesting'" /> 
      <xsl:namespace name="i" 
       select="'http://www.w3.org/2001/XMLSchema-instance'" /> 
      <!-- <xsl:copy-of select="namespace::*" /> --> 
      <xsl:apply-templates select="node()|@*" /> 
     </xsl:element> 
    </xsl:template> 

</xsl:stylesheet> 

私は何を追加するか、ということを削除する修正する必要があります。

<RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting" 
      xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 

これは私がバージョン2で使用XSLT設定ファイルですそのノードの接頭辞?

+1

をあなたは名前空間接頭辞を「削除」することはできません大部分のケースでは、そのようなことをする必要はありません。あなたのケースでそれが必要だと思う理由を説明できますか? – Tomalak

+0

私が消費するWSDLは@Tomalakを必要とするので – gtx911

+0

申し訳ありませんが、それは満足のいく説明ではありません。私は「なぜあなたはそれが必要なのですか?」と尋ねました。あなたは「私はそれが必要だから」と答えました。私はあなたがそれよりも良い理由を与える必要があると思う。 – Tomalak

答えて

0

ノードから「プレフィックスを削除する」ことはできません。接頭辞はノードの名前の一部です。プレフィックスを削除するには、おそらく別の名前で新しいノードを作成しなければなりません - あなたの例のように - 別の名前空間に:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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

<xsl:template match="a:RequestResult"> 
    <xsl:element name="RequestResult" namespace="http://tempuri.org/"> 
     <xsl:copy-of select="namespace::*"/> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 
+0

しかし、私はその名前空間を追加すると動作しません – gtx911

+0

@ gtx911謎の中で話を止めてください。上記の変換はあなたが求めた** exact **結果を生成します。他のものが必要な場合は、質問を編集して明確にしてください。あなたの他の質問にも同じことが当てはまります:http://stackoverflow.com/a/40589393/3016153 –

関連する問題