2016-09-21 7 views
0

を避けるために:XSLTは..私は、入力XML等を有していて、名前空間

<?xml version="1.0" encoding="UTF-8"?> 
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
     <S:Body> 
      <ListResponse xmlns="urn:abcde:xyz:1"> 
       <Gtins> 
        <Gtin> 
         <gtinID>11111</gtinID> 
         <name>222222</name> 
         <label>S11111 - EA</label> 
         <description>XYZ</description> 
         <value>11111</value> 
        </Gtin> 
        <Gtin> 
         <gtinID>999999</gtinID> 
         <name>999999</name> 
         <label>asdfg</label> 
         <description>ghgj</description> 
         <value>999999</value> 
        </Gtin> 
       </Gtins> 
      </ListResponse> 
     </S:Body> 
    </S:Envelope> 

はどのようにして、各ノードGTIN]のすべての値を選択して、XSLTによる名前空間を避けるのですか?

出力XMLがあるべき...

<ns0:RFC xmlns:ns0="http://asd.com"> 
    <Gtins> 
     <Gtin> 
     <gtinID>11111</gtinID> 
     <name>222222</name> 
     <label>S11111 - EA</label> 
     <description>XYZ</description> 
     <value>11111</value> 
     </Gtin> 
     <Gtin> 
     <gtinID>999999</gtinID> 
     <name>999999</name> 
     <label>asdfg</label> 
     <description>ghgj</description> 
     <value>999999</value> 
     </Gtin> 
    </Gtins> 
    </ns0:RFC> 
+1

[this](http://stackoverflow.com/help/mcve)を読んで質問を編集してください。 – uL1

+0

名前空間は**使用される**、避けられない*。ここをクリックしてください:http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 –

+0

マイケルに感謝しますが、値を取得しません。 – Sdey

答えて

0

結論/要約コメントの、他方はすでに質問に答え。

@ michael.hor257kのアドバイスで、このスレッドをご覧ください。あなたが持っているのと同じ問題への答えを受け入れました。 Use of namespace

問題:あなたのXML名前空間でその要素を置きます。

解決方法:スタイルシートに同じ名前空間を宣言し、接頭辞を割り当て、その接頭辞を使用してソースXMLの要素を指定します。あなたの与えられた入力に


、起動して、このベースを使用して独自に継続:

<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:abc="urn:abcde:xyz:1"> 

    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/S:Envelope"> 
     <!-- select any child - exemplary --> 
     <xsl:value-of select="S:Body/abc:ListResponse/abc:Gtins/abc:Gtin/abc:gtinID" /> 
    </xsl:template> 

</xsl:stylesheet> 

さらに:

これはあなたの同等バージョンです入力-xml:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="urn:abcde:xyz:1"> 
    <S:Body> 
     <abc:ListResponse> 
      <abc:Gtins> 
       <abc:Gtin> 
        <abc:gtinID>11111</abc:gtinID> 
        <abc:name>222222</abc:name> 
        <abc:label>S11111 - EA</abc:label> 
        <abc:description>XYZ</abc:description> 
        <abc:value>11111</abc:value> 
       </abc:Gtin> 
       <abc:Gtin> 
        <abc:gtinID>999999</abc:gtinID> 
        <abc:name>999999</abc:name> 
        <abc:label>asdfg</abc:label> 
        <abc:description>ghgj</abc:description> 
        <abc:value>999999</abc:value> 
       </abc:Gtin> 
      </abc:Gtins> 
     </abc:ListResponse> 
    </S:Body> 
</S:Envelope> 

名前空間には理由があります。それらを使用し、「私はそれらを理解していないので、私はそれらを取り除きたい」という理由だけでそれらを取り除かないでください。私が間違ってはいけない、あなたの結果 - xmlは名前空間がなくてもかまいません。それでは、多くの例があります。

1

はあなたの出発点としてこれを試してみてください:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xyz="urn:abcde:xyz:1" 
exclude-result-prefixes="S xyz"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/S:Envelope"> 
    <ns0:RFC xmlns:ns0="http://asd.com"> 
     <Gtins> 
      <xsl:for-each select="S:Body/xyz:ListResponse/xyz:Gtins/xyz:Gtin"> 
       <Gtin> 
        <gtinID> 
         <xsl:value-of select="xyz:GtinID"/> 
        </gtinID> 
        <!-- more here --> 
       </Gtin> 
      </xsl:for-each>   
     </Gtins> 
    </ns0:RFC> 
</xsl:template> 

</xsl:stylesheet> 

それとももっと簡単:

を210

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xyz="urn:abcde:xyz:1" 
exclude-result-prefixes="S xyz"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/S:Envelope"> 
    <ns0:RFC xmlns:ns0="http://asd.com"> 
     <Gtins> 
      <xsl:apply-templates select="S:Body/xyz:ListResponse/xyz:Gtins/xyz:Gtin"/> 
     </Gtins> 
    </ns0:RFC> 
</xsl:template> 

<xsl:template match="*"> 
    <xsl:element name="{local-name()}"> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 
+0

Working Michael ...ありがとうございます! – Sdey

+0

@Sdey質問に答えた場合は、回答を受け入れて閉じてください。 –

関連する問題