XSL Transformation with recursive elements

3motions

New Member
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":\[code\]<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>\[/code\]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/Child_Fs" ancestor. Meaning that the maximal depth for an F element should be of only two occurrances (F/Child_Fs/F/Childfs). The other important requirement here is to keep all data (attributes and text inclusive) intact, it is just a relocation operation:\[code\]<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>\[/code\]I would appreciate it a lot if anyone could give me a hint on this. Till now I've not been able to come up with a correct XSL Stylesheet.Many thanks in advance.
 
Back
Top