473,241 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

XSL Transformation with recursive elements

Hello,

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
  1.     <A>
  2.         <B>
  3.             <F id="1">
  4.                 <J/>
  5.                 <K/>
  6.                 <Child_Fs>
  7.                     <F id="1.1">
  8.                         <J/>
  9.                         <K/>
  10.                         <Child_Fs>
  11.                             <F id="1.1.1">
  12.                                 <J/>
  13.                                 <K/>
  14.                                 <Child_Fs>
  15.                                         ...
  16.                                 </Child_Fs>
  17.                             </F>
  18.                             <F id="1.1.2">
  19.                                 ...
  20.                             </F>
  21.                             <F id="1.1.3">
  22.                                 ...
  23.                             </F>
  24.                             <F id="1.1.4">
  25.                                 ...
  26.                             </F>
  27.                             .
  28.                             .
  29.                             .
  30.                         </Child_Fs>
  31.                     </F>
  32.                     <F id="1.2">
  33.                         ...
  34.                     </F>
  35.                     <F id="1.3">
  36.                         ...
  37.                     </F>
  38.                     <F id="1.4">
  39.                         ...
  40.                     </F>
  41.                     .
  42.                     .
  43.                     .
  44.                 </Child_Fs>
  45.             </F>
  46.             <F id="2">
  47.                 ...
  48.             </F>
  49.             <F id="3">
  50.                 ...
  51.             </F>
  52.             <F id="4">
  53.                 ...
  54.             </F>
  55.             .
  56.             .
  57.             .
  58.             <G/>
  59.             <H/>
  60.             <I/>
  61.         </B>
  62.         <C/>
  63.         <D/>
  64.         <E/>
  65.     </A>
  66.  

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
  1.     <A>
  2.         <B>
  3.             <F id="1">
  4.                 <J/>
  5.                 <K/>
  6.                 <Child_Fs>
  7.                     <F id="1.1">
  8.                         <J/>
  9.                         <K/>
  10.                         <Child_Fs>
  11.                         </Child_Fs>
  12.                     </F>
  13.                     <F id="1.1.1">
  14.                         <J/>
  15.                         <K/>
  16.                         <Child_Fs>
  17.                         </Child_Fs>
  18.                     </F>
  19.                     ...
  20.                     <F id="1.1.2">
  21.                         ...
  22.                     </F>
  23.                     <F id="1.1.3">
  24.                         ...
  25.                     </F>
  26.                     <F id="1.1.4">
  27.                         ...
  28.                     </F>
  29.                     .
  30.                     .
  31.                     .
  32.                     <F id="1.2">
  33.                         ...
  34.                     </F>
  35.                     <F id="1.3">
  36.                         ...
  37.                     </F>
  38.                     <F id="1.4">
  39.                         ...
  40.                     </F>
  41.                     .
  42.                     .
  43.                     .
  44.                 </Child_Fs>
  45.             </F>
  46.             <F id="2">
  47.                 ...
  48.             </F>
  49.             <F id="3">
  50.                 ...
  51.             </F>
  52.             <F id="4">
  53.                 ...
  54.             </F>
  55.             .
  56.             .
  57.             .
  58.             <G/>
  59.             <H/>
  60.             <I/>
  61.         </B>
  62.         <C/>
  63.         <D/>
  64.         <E/>
  65.     </A>
  66.  
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.
Jul 16 '12 #1
1 1803
Anas Mosaad
185 128KB
Hint: In a for-each loop or a template that matches your Child_Fs you can use \\F to indicate all F node under the Child_Fs node.
Jan 6 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: bearophileHUGS | last post by:
(This is a repost from another python newsgroup). While using some nested data structures, I've seen that I'd like to have a function that tells me if a given data structure contains one or more...
4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
1
by: walexand | last post by:
I have mistake by counting a recursive element. Can someone help me. XML Sample File ---------------------------------------------------- <content> <section> <title>index1</title> <section>...
2
by: rankam | last post by:
Hi There, We have a requirement for recursive elements within a XML document? Is it possible to design it through XML Schema? And what are implications using recursive elements when using DOM...
1
by: Paul Guz | last post by:
I've discovered a quirk of .Net System.Xml.Xsl.XSLTransfrom that doesn't seem to exist in the MSXML2 transformation. When calling a recursive template for the first time, don't pass a parameter...
0
by: projectbeach | last post by:
Hi, I've been struggling to create a valid XML schema that implements the following innocent-looking concept: A box may contain a bunch of bags (possibly 0). A bag must contain a bunch of...
5
by: monmonja | last post by:
Hi i'm new to xsl and i have been using smarty php templating but its just so hard to read codes in smarty/php/flash than xml/xsl/flash, i rather sacrifice speed then not being able to read code...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
1
by: indyanguy | last post by:
Hello, I am trying to create a XML schema to validate a XML document. The XML document has recursive <Section> elements (as shown below). Can someone help me create the XSD for the recursive part...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.