2017-02-15 11 views
0

をxmlペイロードに追加する以下の行の後に1つの名前空間を追加する必要があります。XSLTを使用した名前空間の追加

<?xml version="1.0" encoding="UTF-8"?> 
<ep:Document xmlns:ep="namespace here" 
xmlns:gk="namespace here" 
xmlns:sh="namespace here" schemaVersion="" creationDate=""> 

この後、私は名前空間のxmlnsを追加するNEDD:XSI = "http://www.w3.org/2001/XMLSchema-instance">

予想される出力は

<?xml version="1.0" encoding="UTF-8"?> 
<ep:Document xmlns:ep="namespace here" 
xmlns:gk="namespace here" 
xmlns:sh="namespace here" schemaVersion="" creationDate=""xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
する必要があります

助けてもらえますか? 私の要求を詳しく説明しましょう。実際の入力メッセージでは、名前空間なしでペイロードを取得しています。それは以下のようなものです。

<?xml version="1.0" encoding="UTF-8"?> 
<document> 
</document> 

で、残りのペイロードがあるドキュメントです。

その後、XSLTコードを使用してペイロードに名前空間とプレフィックスを追加しました。下の が私のXSLTコードです。

</xsl:stylesheet> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:ep="namespace here" 
xmlns:sh="namespace here" 
xmlns:gk="namespace here"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 


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

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

<xsl:template match="Extension|Extension//*"> 
<xsl:element name="gk:{name()}"> 
    <xsl:apply-templates select="node()|@*"/> 
    </xsl:element> 
    </xsl:template> 

<xsl:template match="Header|Header//*"> 
<xsl:element name="sh:{name()}"> 
    <xsl:apply-templates select="node()|@*"/> 
    </xsl:element> 

このコード私は以下のようなルックスを取得していた出力を使用した後。ポストで述べたように

<?xml version="1.0" encoding="UTF-8"?> 
<ep:Document xmlns:ep="namespace here" 
xmlns:gk="namespace here" 
xmlns:sh="namespace here" schemaVersion="" creationDate=""> 

とpayload.so残りの私は、既存のコードのスキーマのバージョンとのCreationDate後のもう一つの名前空間を必要としています。あなたが期待するよう

+0

"ep:Document"要素を扱う部分は、既存のXSLTを見る必要があります。余計な必要条件であることに注意してください。出力に 'xsi'接頭辞のバインディングが必要な場合、プロセッサは自動的にそれをインクルードします(またはエラーをスローします)。 –

+0

私の要求を詳述しましょう。実際の入力ペイロードでは、名前空間なしでメッセージを受信して​​います。 –

+0

私は自分の質問を編集しました。詳細を見つけてください。 –

答えて

0

あなたxsl:stylesheet要素に必要な名前空間宣言を追加した場合、すなわち:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ep="namespace here" 
xmlns:sh="namespace here" 
xmlns:gk="namespace here" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

それははおそらくは、出力のルートep:Document要素の開始タグ内に表示されます。 XSLTプロセッサには冗長な名前空間宣言を含める必要がないため、「おそらく」と言います。

開始タグに表示される属性と名前空間の宣言の順序は制御できません。その注文は定義上重要ではない。

+0

だから、スキーマのバージョンと作成日はxmlns:xsi名前空間の後に来るでしょうか?それ以前ではない? –

+0

これは、あなたのXSLTプロセッサーによって決まります。ほとんどのプロセッサは、最初にすべての名前空間をリストし、次に属性をリストします。 XSLTプロセッサは実際のXML *ファイルではなくXML *ツリー*で動作することに注意してください。プロセスの最後でのみ、結果ツリーがシリアル化されて出力ファイルが作成されます。 –

関連する問題