質問
それが可能かどうかはわかりません。私はXSLTなどに非常に慣れていないのですが、おそらくここで助けてくれる人がいるかもしれません。それは少しトリッキーであり、私はインターネット上でそのようなものを見つけていません:
問題は、名前空間が宣言されたすべての入力xmlがあり、それにわずかな変更(属性の追加または削除、または他の場所へのシフト)を加えるだけでよいことです。しかし同時に、ドキュメントのドキュメントタグ内の名前空間参照を更新する必要があります。したがって、たとえば、入力xmlは次のようになります。
<order
xmlns="some.url.01"
xmlns:ns2="some.other.url"
xmlns:ns3="another.one"
>
<orderEntry>
<orderControl>
<mandant>test</mandant>
<businessUnit>test</businessUnit>
<inboundChannel>test</inboundChannel>
<timestamp>timestamp</timestamp>
<requestedDocuments>
<ns2:document>orderForm</ns2:document>
</requestedDocuments>
</orderControl>
</orderEntry>
</order>
結果のxmlは次のようになります。
<order
xmlns="some.url.02"
xmlns:ns2="some.other.url.02"
xmlns:ns3="another.one.02"
>
<orderEntry>
<orderControl>
<mandant>test</mandant>
<businessUnit>test</businessUnit>
<inboundChannel>test</inboundChannel>
<!-- deleted timestamp for example -->
<requestedDocuments>
<ns2:document>orderForm</ns2:document>
</requestedDocuments>
</orderControl>
</orderEntry>
</order>
しかし、私が得る唯一のものは:
<order
xmlns="some.url.02"
>
<orderEntry>
<orderControl>
<mandant>test</mandant>
<businessUnit>test</businessUnit>
<inboundChannel>test</inboundChannel>
<!-- deleted timestamp for example -->
<requestedDocuments>
<ns2:document xmlns:ns2="some.other.url.02">orderForm</ns2:document>
</requestedDocuments>
</orderControl>
</orderEntry>
</order>
さて、1人か2人にとってはそれほど大したことではないかもしれませんが、要求された変更(名前空間の変更を除いて、出力ドキュメントは入力ドキュメントと1対1に見える必要があるという制限がありますおよび削除)。
私のXSLTは次のようになります。
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="some.url.02"
xmlns:ns2="some.other.url.02"
xmlns:ns3="another.one.02"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="name(.) != 'timestamp'">
<xsl:element name="{node-name(.)}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{node-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
誰か助けてもらえますか?名前空間は扱いにくいです:(
PS:私のエントリを編集した人:ありがとう:)
解決
名前空間属性を使用して、出力要素に名前空間を設定できます。
<xsl:element name="{node-name(.)}" namespace="http://www.bar.org">
// ...
</xsl:element>
名前空間はURIでなければならないことに注意してください。これは知っていると思いますが、例ではURIを使用することをお勧めします。
ここに、優れたZVONチュートリアルへのリンクがあります。これは例を実行しました。 http://www.zvon.org/xxl/XSLTreference/Output/xslt_element_namespace。 html
名前空間には注意が必要です。ご存知のように、接頭辞は意味的に無関係ですが、多くのシステムでは審美的な理由から接頭辞を選択できます。 Saxonもご覧ください( http://saxon.sourceforge.net/ )
編集ここで答えが見つかると思います: 要素属性の名前空間ではなくXSLTルートタグの名前空間
他のヒント
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1_src="some.url.01"
xmlns:ns2_src="some.other.url"
xmlns:ns3_src="another.one"
xmlns="some.url.02"
xmlns:ns2="some.other.url.02"
xmlns:ns3="another.one.02"
>
<!--
Note that all the source namespaces got their own new "*_src" prefix.
The target namespaces take over the original prefixes.
"some.url.02" is the new global namespace.
-->
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- the identity template to copy everything, unless
it has been declared otherwise -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- three templates to handle elements -->
<xsl:template match="ns1_src:*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
<xsl:template match="ns2_src:*">
<xsl:element name="ns2:{local-name()}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
<xsl:template match="ns3_src:*">
<xsl:element name="ns3:{local-name()}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
<!-- three templates to handle attributes -->
<xsl:template match="@ns1_src:*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<xsl:template match="@ns2_src:*">
<xsl:attribute name="ns2:{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<xsl:template match="@ns3_src:*">
<xsl:attribute name="ns3:{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<!-- timestamps will be ignored -->
<xsl:template match="ns1_src:timestamp" />
</xsl:stylesheet>
出力:
<order xmlns="some.url.02">
<orderEntry>
<orderControl>
<mandant>test</mandant>
<businessUnit>test</businessUnit>
<inboundChannel>test</inboundChannel>
<requestedDocuments>
<ns2:document xmlns:ns2="some.other.url.02">orderForm</ns2:document>
</requestedDocuments>
</orderControl>
</orderEntry>
</order>
<xsl:template match="a:*">
<xsl:element name="{local-name()}"
namespace="http://example.com/B">
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:element>
</xsl:template>
接頭辞 a
を持つ名前空間内の要素を検索し、名前空間 http://example.com/B
と同じ名前を持つ要素に置き換えます。すべての属性が「そのまま」コピーされ、すべての子が評価されます。
必要に応じて、またはその周辺にカスタム処理を追加します。