If I have this file: input file1.xml:
<schema>
<sequence>
<nodeA id="a">
<fruit id="small">
<orange id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</orange>
</fruit>
<fruit id="small">
<apple id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</apple>
</fruit>
<fruit id="medium">
<orange id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</orange>
</fruit>
</nodeA>
<nodeB id="b">
<dog id="large">
<doberman id="x" method="create">
<condition>
<color>Black</color>
</condition>
</doberman>
</dog>
</nodeB>
</sequence>
</schema>
file2.xml:
<schema>
<sequence>
<nodeA id="a">
<fruit id="small">
<melon id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</melon>
</fruit>
</nodeA>
<nodeB id="b">
<dog id="small">
<poodle id="x" method="create">
<condition>
<color>White</color>
</condition>
</poodle>
</dog>
</nodeB>
</sequence>
</schema>
After concatenation: output: concate.xml
<schema>
<sequence>
<nodeA id="a">
<fruit id="small">
<orange id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</orange>
</fruit>
<fruit id="small">
<apple id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</apple>
</fruit>
<fruit id="medium">
<orange id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</orange>
</fruit>
<fruit id="small">
<melon id="x" method="create">
<attributes>
<color>Orange</color>
<year>2000</year>
</attributes>
</melon>
</fruit>
</nodeA>
<nodeB id="b">
<dog id="large">
<doberman id="x" method="create">
<condition>
<color>Black</color>
</condition>
</doberman>
</dog>
<dog id="small">
<poodle id="x" method="create">
<condition>
<color>White</color>
</condition>
</poodle>
</dog>
</nodeB>
</sequence>
</schema>
For the concate it will depend on the file order so the node in file2.xml will be placed under the node of file1.xml (as seen on the example). And I have up to 5 files. How is this achievable using xsl transformation only, i.e the xslt will input 5 files at the same time and outputting 1 file?
This is the document structure and the point where we do merge:
<schema>
<sequence>
<nodeA id="a">
<fruit id="small">
<orange id="x" method="create">
...
</orange>
</fruit>
<fruit id="small">
...
</fruit>
<fruit id="large">
...
</fruit>
<!-- we merge below this -->
</nodeA>
<nodeB id="b">
<dog id="large">
<doberman id="x" method="create">
...
</doberman>
</dog>
<dog id="small">
<doberman id="x" method="create">
...
</doberman>
</dog>
<!-- we merge below this -->
</nodeB>
<somenode id="any">
...
</somenode>
</sequence>
</schema>
Note: If not possible concatenating only two files input will be fine as it can always be repeated for the other files. Also there are various node name in the file (nodeA, nodeB, SomeNode, etc.)so something that can generalize this problem is needed.
we can use xsl1.0 or 2.0.
Thanks very much. John
Try:
Make file1 your main document input. Pass the filename for file2 as parameter "file2". Similarly extend for multiple input files.
@John, here's a more generic solution:
You define the merge point in the
key
and you define the merge match function in thea:id
. You can fallback to XSLT 1.0 by just taking thea:id
function into your predicates.My assumptions:
to-merge
variablelocal-name()
and@id
Here is another answer. This joins at the schema/sequence/* level, rather than just nodeA and NodeB.
As a solution, its probably a bit clumsy and awkward, but it basically works. Hopefully an expert like Dimitre Novatchev will come along and offer a tidier alternative. This is about the limits of my ability.
*UPDATE 1 * I added the id attribute to the etc.
UPDATE 2 Here is the resultant output: