View Single Post
  #1 (permalink)  
Old April 9th, 2012, 02:34 AM
LearnerP LearnerP is offline
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.