473,397 Members | 1,972 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,397 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 1808
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.