Hi Stefan,
this is a typical merging-task.
I have not an XSLT-solution,
but with the product <xml>cmp (
http://www.xmlcmp.com) you can solve
such tasks
and even much more complicated merging tasks.
For merging with <xml>cmp you need a basic-control-file and a
merge-control-file.
The basic-control-file (cmp1.xml) for your example would be:
<?xml version="1.0" encoding="UTF-8"?>
<component ident_att_name="true" >
<LOC-netto cmp_text="true" />
<LOC-comment cmp_text="true" />
<LOC cmp_text="true" />
<Coverage cmp_text="true" />
<Comment-netto cmp_text="true" />
<LOC-blank cmp_text="true" />
</component>
The merge-control-file (merge1.xml) would be:
<?xml version="1.0" encoding="UTF-8"?>
<merge>
<identity path='/component' merge='333' >
<value path='/LOC-netto' merge='3332' />
<value path='/LOC-comment' merge='3332' />
<value path='/LOC' merge='3332' />
<value path='/Coverage' merge='3332' />
<value path='/Comment-netto' merge='3332' />
<value path='/LOC-blank' merge='3332' />
</identity>
</merge>
The merge-attributes contain the merging-rules.
You can define very detailed merging-rules.
For further informations about these merging rules look at
http://www.xmlcmp.com.
Merging the two files:
$ xmlmerge.sh cmp1.xml merge1.xml example1a.xml example1b.xml >
result1.xml
Content of result-file (result1.xml):
<component name='ORCA_Common'>
<LOC-netto>2100</LOC-netto>
<LOC-blank>200</LOC-blank>
<LOC-comment>400</LOC-comment>
<LOC>2700</LOC>
<Comment-netto>20%</Comment-netto>
<Coverage>50%</Coverage>
</component>
Stefan wrote:
> Hi there!
>
> I'm very new to XML and XSLT, so while working i encountered the
> following, probably very easy to solve, problem.
>
> i've got 2 XML-files, which look like this:
>
> LinesOfCode.xml:
> <?xml version="1.0"?>
> <component name="ORCA_Common">
> <LOC-netto>2100</LOC-netto>
> <LOC-blank>200</LOC-blank>
> <LOC-comment>400</LOC-comment>
> <LOC>2700</LOC>
> <Comment-netto>20%</Comment-netto>
> </component>
>
> CodeCoverage.xml:
> <?xml version="1.0"?>
> <component name="ORCA_Common">
> <Coverage>50%</Coverage>
> </component>
>
> Both should be combined to a "component.xml", lookinf like this:
> <?xml version="1.0"?>
> <component name="ORCA_Common">
> <LOC-netto>2100</LOC-netto>
> <LOC-blank>200</LOC-blank>
> <LOC-comment>400</LOC-comment>
> <LOC>2700</LOC>
> <Comment-netto>20%</Comment-netto>
> <Coverage>50%</Coverage>
> </component>
>
> so just adding the data of the one XML to the data of the other.
>
> I wanted to use a primary source, referring to both files, looking like
> this:
> <?xml version="1.0"?>
> <index>
> <entry>LinesOfCode</entry>
> <entry>CodeCoverage</entry>
> </index>
>
> and logically the document() funcition in the xsl-file.
>
> Could you please tell me how to do this? i tried several times with
> lots of different XSL-files, but nothing seems to work.
>
> Thanks in advance!
>
> Greets, Stefan