I have an XML with approximately the following structure, the relevant characteristic here the recursive relation of the element pair "F" and "Child_Fs". "Child_Fs" can contain any number of "F" and "F" can contain only one "Child_Fs":
Expand|Select|Wrap|Line Numbers
- <A>
- <B>
- <F id="1">
- <J/>
- <K/>
- <Child_Fs>
- <F id="1.1">
- <J/>
- <K/>
- <Child_Fs>
- <F id="1.1.1">
- <J/>
- <K/>
- <Child_Fs>
- ...
- </Child_Fs>
- </F>
- <F id="1.1.2">
- ...
- </F>
- <F id="1.1.3">
- ...
- </F>
- <F id="1.1.4">
- ...
- </F>
- .
- .
- .
- </Child_Fs>
- </F>
- <F id="1.2">
- ...
- </F>
- <F id="1.3">
- ...
- </F>
- <F id="1.4">
- ...
- </F>
- .
- .
- .
- </Child_Fs>
- </F>
- <F id="2">
- ...
- </F>
- <F id="3">
- ...
- </F>
- <F id="4">
- ...
- </F>
- .
- .
- .
- <G/>
- <H/>
- <I/>
- </B>
- <C/>
- <D/>
- <E/>
- </A>
My actual XML doesn't contains IDs, I just wrote them in this example for ilustration purposes.
So what I would like to get after the transformations is the following XML, in which all "F" elements are children of their corresponding highest "F" ancestor. Meaning that the maximal depth for an F element should be of only two occurrances. The other important requirement here is to keep all data (attributes and text inclusive) intact, it is just a relocation operation:
Expand|Select|Wrap|Line Numbers
- <A>
- <B>
- <F id="1">
- <J/>
- <K/>
- <Child_Fs>
- <F id="1.1">
- <J/>
- <K/>
- <Child_Fs>
- </Child_Fs>
- </F>
- <F id="1.1.1">
- <J/>
- <K/>
- <Child_Fs>
- </Child_Fs>
- </F>
- ...
- <F id="1.1.2">
- ...
- </F>
- <F id="1.1.3">
- ...
- </F>
- <F id="1.1.4">
- ...
- </F>
- .
- .
- .
- <F id="1.2">
- ...
- </F>
- <F id="1.3">
- ...
- </F>
- <F id="1.4">
- ...
- </F>
- .
- .
- .
- </Child_Fs>
- </F>
- <F id="2">
- ...
- </F>
- <F id="3">
- ...
- </F>
- <F id="4">
- ...
- </F>
- .
- .
- .
- <G/>
- <H/>
- <I/>
- </B>
- <C/>
- <D/>
- <E/>
- </A>
Many thanks in advance.