I've got an XML file with the following structure (multiple "entity" nodes):
<!-- entities.xml -->
<root>
<entity template="foo-template" kind="foo" name="bar">
<groups>
<group id="1">
<definition id="1" name="foobar" />
</group>
</groups>
</entity>
</root>
Many entity
nodes have similar attributes and children nodes. I'd like to allow users to create entity
templates in a separate file. Referencing the template will be done as follows:
<entity template="foo-template" kind="foo" ... />
Every attribute and child node from "foo-template" should be copied into the entity
, except for those that already exist (i.e. allow overriding the template).
I'm not very familiar with XSLT. Is it the right tool for this task, or am I better off implementing this without it?
I'm using C++ and RapidXml, but can use other XML libraries.
Edit: example.
Template file:
<!-- 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 file:
<!-- 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>
So the output contains group 1 from "entities.xml" and group 2 from "templates.xml". No need to merge group
nodes with the same id.