0
XSLTの初心者はここにあります。私は何かのように見えるXMLブロックを持っていますが、要素名に基づいて、そのコンテンツを変更できる必要があります。問題は、XMLに接頭辞を付けるかどうかということです。接頭語要素の内容を変更する要素名に基づくXSLT
<POIS xmlns:tns="http://example.com/integration/docs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:POI>
<tns:CTL>
<tns:transaction_date/>
<tns:record_qualifier/>
<tns:start_date>2012-10-12 </tns:start_date>
<tns:test_indicator>P</tns:test_indicator>
</tns:CTL>
</tns:POI>
</tns:POIS>
かどうか::
プレフィックスXMLは次のようになります私は価値がある場合_dateで終わる要素の内容を変更したい
<POIS xmlns="http://example.com/integration/docs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<POI>
<CTL>
<transaction_date/>
<record_qualifier/>
<start_date>2012-10-12</start_date>
<test_indicator>P</test_indicator>
</CTL>
</POI>
</POIS>
。
だから、可能な出力は次のようになります。
<POIS xmlns:tns="http://example.com/integration/docs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:POI>
<tns:CTL>
<tns:transaction_date/>
<tns:record_qualifier/>
<tns:start_date>20121012 </tns:start_date>
<tns:test_indicator>P</tns:test_indicator>
</tns:CTL>
</tns:POI>
</tns:POIS>
これは私がこれまで持っているものです。
問題は、それがTNSと文句を言うことです:接頭辞または入れたときに変更された要素の名前空間接頭辞のないXML要素の空の名前空間。
どのようなソリューションですか?これはユーティリティの変換ですので、可能な限り一般的なままにしておきたいと思います。
<xsl:stylesheet version="2.0"
xmlns:xp20="http://www.oracle.com/XSL/Transform/
java/oracle.tip.pc.services.functions.Xpath20"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()[ends-with(name(), '_date')]">
<xsl:choose>
<xsl:when test="(text())" >
<xsl:element name="{name()}" >
<xsl:value-of select ="xp20:format-dateTime(text(),'[Y0001][M01][D01]')" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
あなたのXMLは整形されていません: ''、 ''終了タグ、 ''タグの接頭辞が一貫しません。 XMLを修正してください。 –
''を ''に変更してみてください。 –
残念ながら、空の名前空間 ' 20120430 'を入れているので、まだ失敗します。 –
rafter