2017-02-16 1 views
0

で名前空間を変更するには:私はテストのために使用するXMLメッセージがあるXSLTは、私はXSLコードの下に使用して、要素の属性の名前空間を変更しようとしている要素

<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:ns2="http://www.ean-ucc.org/schemas/1.3.1/eanucc"> 
    <xsl:output encoding='UTF-8' indent='yes' method='xml'/> 

    <!-- copy everything into the output --> 
    <xsl:template match='@*|node()'> 
     <xsl:copy> 
      <xsl:apply-templates select='@*|node()'/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="IRenvelope"> 
     <IRL xmlns:xsd="http://www.xx.com"> 
      <xsl:copy-of select="node()|@*"/> 
     </IRL> 
    </xsl:template> 
</xsl:stylesheet> 

<GMessage xmlns="http://www.giffgaff.uk/CM/envelope"> 
<EnvelopeVersion>2.0</EnvelopeVersion> 
    <body> 
    <IRenvelope xmlns="http://www.mnv.com/elc/sap"> 
      <Keys> 
       <Key Type="TaxOfficeNumber">635</Key> 
      </Keys> 
     </IRenvelope> 
    </body> 
</GMessage> 

私はそれを動作させることができませんでしたし、名前空間は変化していませんが、同じ結果を証明しています。助けてください?次のように

出力XMLがなければ:

 <GMessage xmlns="http://www.giffgaff.uk/CM/envelope"> 
     <EnvelopeVersion>2.0</EnvelopeVersion> 
      <body> 
      <IRenvelope xmlns="http://www.xx.com"> 
       <Keys> 
        <Key Type="TaxOfficeNumber">635</Key> 
       </Keys> 
       </IRenvelope> 
      </body> 
     </GMessage> 
+0

入力XMLでは、要素「IRenvelope」は、名前空間「htt」の下にあります。 p:// www.mnv.com/elc/sap'となります。しかし、あなたのXSLTはこの名前空間のない要素 'IRenvelope'にマッチします。また、作成している要素、 'IRL'は空の名前空間に入ります。 'http:// www.xx.com'の下に置くには、要素名に' xsd'接頭辞( 'xsd:IRL')をつけます。フィードバックをお寄せください: –

+0

thkx私はIRENAVEがネームスの下に落ちて、添付された出力を私に提供するために何をするのですか?任意の入力をpls? –

答えて

1

ザ・XSLTは、あなたが望む結果を得るのに役立ちます下に:ここでは

<xsl:stylesheet 
    version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsd="http://www.xx.com" 
    xmlns:ns="http://www.mnv.com/elc/sap" 
    exclude-result-prefixes="ns"> 
    <xsl:output encoding='UTF-8' indent='yes' method='xml'/> 

    <!-- copy everything into the output --> 
    <xsl:template match='@*|node()'> 
     <xsl:copy> 
      <xsl:apply-templates select='@*, node()'/> 
     </xsl:copy> 
    </xsl:template> 

    <!-- template to match ns:IRenvelope element and creating a new element --> 
    <xsl:template match="ns:IRenvelope"> 
     <xsl:element name="IRL" namespace="http://www.xx.com"> 
      <xsl:apply-templates select="@*, node()"/> 
     </xsl:element> 
    </xsl:template> 

    <!-- template to change the namespace 
     of the elements 
     from "http://www.mnv.com/elc/sap" 
     to "http://www.xx.com" --> 
    <xsl:template match="ns:*"> 
     <xsl:element name="{local-name()}" namespace="http://www.xx.com"> 
      <xsl:apply-templates select="@*, node()"/> 
     </xsl:element> 
    </xsl:template> 

</xsl:stylesheet> 

は、最後の2つのテンプレートがns:IRenvelopeとすべて一致し名前空間がそれぞれhttp://www.mnv.com/elc/sapの要素があります。 xsl:elementとその名前空間属性を使用して、新しい名前空間を持つ新しい要素を作成することができます。

また、接頭辞を用いて所望の名前空間を宣言し、以下のように要素を作成することができます:ちょうど,(カンマ)を交換

|(パイプ)を使用する:XSLT-1.0の場合

<xsd:IRL xmlns:xsd="http://www.xx.com"> 
    ... 
</xsd:IRL> 
<xsl:apply-templates select="@* | node()"/> 
+0

こんにちは。私はこのxsltを試してみましたが、それはあまり役に立たなかった。元のXMLと同じ結果になります。 –

+0

本当ですか? http://xsltransform.net/gWEamLU –

+0

私はaltova xmlのスパイを介してテストしようとしましたが、そこで働くことができませんでした:( –

関連する問題