次の構造の XML ファイルがあります (複数の「エンティティ」ノード)。
<!-- entities.xml -->
<root>
<entity template="foo-template" kind="foo" name="bar">
<groups>
<group id="1">
<definition id="1" name="foobar" />
</group>
</groups>
</entity>
</root>
多くのentity
ノードには、同様の属性と子ノードがあります。entity
ユーザーが別のファイルにテンプレートを作成できるようにしたいと思います。テンプレートの参照は次のように行われます。
<entity template="foo-template" kind="foo" ... />
「foo-template」のすべての属性と子ノードはentity
、既存のものを除いて、 にコピーする必要があります (つまり、テンプレートのオーバーライドを許可します)。
私は XSLT にあまり詳しくありません。それはこのタスクに適したツールですか、それともそれなしでこれを実装したほうがよいでしょうか?
私は C++ と RapidXml を使用していますが、他の XML ライブラリも使用できます。
編集: 例.
テンプレート ファイル:
<!-- templates.xml -->
<templates>
<entity template="foo-template" name="n/a" model="baz">
<groups>
<group id="1">
<definition id="1" name="def1" />
<definition id="2" name="def2" />
</group>
<group id="2">
<definition id="1" name="def3" />
<definition id="2" name="def4" />
</group>
</groups>
</entity>
</templates>
出力ファイル:
<!-- output.xml -->
<root>
<entity kind="foo" name="bar" model="baz">
<groups>
<group id="1">
<definition id="1" name="foobar" />
</group>
<group id="2">
<definition id="1" name="def3" />
<definition id="2" name="def4" />
</group>
</groups>
</entity>
</root>
したがって、出力には「entities.xml」のグループ 1 と「templates.xml」のグループ 2 が含まれます。group
同じ ID を持つノードをマージする必要はありません。