p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Moving child nodes to previous occurrance of the root node (http://p2p.wrox.com/showthread.php?t=87208)

LearnerP April 9th, 2012 02:34 AM

Moving child nodes to previous occurrance of the root node
 
Hi All,

I have structure, in which root node has 2 child nodes. One is Header and other is Detail. Header may occure once or may not occurr and Details is unbounded.
The requirement is, if Header does not exist in any of the root node then the corresponding Detail nodes must be moved to previous occurrence of the root node where Header exists. Below are the input and required output samples.

Input:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Employee xmlns:ns0="htp://example">
<EMP_Det>
<Emp_Personal_Det>
<Name>Employee1</Name>
<Age>29</Age>
<Gender>F</Gender>
</Emp_Personal_Det>
<Emp_Home_Address>
<Street>Street1</Street>
<City>City1</City>
<State>State1</State>
</Emp_Home_Address>
</EMP_Det>
<EMP_Det>
<Emp_Home_Address>
<Street>Street2</Street>
<City>City2</City>
<State>State2</State>
</Emp_Home_Address>
</EMP_Det>
<EMP_Det>
<Emp_Personal_Det>
<Name>Employee2</Name>
<Age>30</Age>
<Gender>M</Gender>
</Emp_Personal_Det>
<Emp_Home_Address>
<Street>Street3</Street>
<City>City3</City>
<State>State3</State>
</Emp_Home_Address>
</EMP_Det>
</ns0:Employee>


Output:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Employee xmlns:ns0="htp://example">
<EMP_Det>
<Emp_Personal_Det>
<Name>Employee1</Name>
<Age>29</Age>
<Gender>F</Gender>
</Emp_Personal_Det>
<Emp_Home_Address>
<Street>Street1</Street>
<City>City1</City>
<State>State1</State>
</Emp_Home_Address>
<Emp_Home_Address>
<Street>Street2</Street>
<City>City2</City>
<State>State2</State>
</Emp_Home_Address>
</EMP_Det>
<EMP_Det>
<Emp_Personal_Det>
<Name>Employee2</Name>
<Age>30</Age>
<Gender>M</Gender>
</Emp_Personal_Det>
<Emp_Home_Address>
<Street>Street3</Street>
<City>City3</City>
<State>State3</State>
</Emp_Home_Address>
</EMP_Det>
</ns0:Employee>


Please help me ASAP. Is it possible in XSLT. Thanks in Advance.

P.

mhkay April 9th, 2012 03:40 AM

I'm sorry, I don't see any Header or Detail elements in your sample data, which makes it a bit difficult to relate the prose description of your problem to your actual XML - you've abstracted the problem a bit too far.

LearnerP April 9th, 2012 04:24 AM

Hi Michael Kay,

Thanks for the reply.
Root - EMP_Det
2 Child nodes are Emp_Personal_Det, Emp_Home_Address
In which Header is Emp_Personal_Det - may exist once or not at all.
Detail is Emp_Home_Address, one or more times exists.

If Emp_Personal_Det does not exist in any of EMP_Det, then the corresponding Emp_Home_Address nodes must be moved to the previous EMP_Det which is having Emp_Personal_Det.

Please help me.

P.


All times are GMT -4. The time now is 11:47 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.