Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 9th, 2012, 02:34 AM
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.
Reply With Quote
  #2 (permalink)  
Old April 9th, 2012, 03:40 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old April 9th, 2012, 04:24 AM
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

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find child node when there is mentioned (child::*) mlohokare XSLT 3 May 12th, 2009 12:40 PM
Accessing a node bases on child node value musman0047 XSLT 1 February 27th, 2009 12:26 PM
Moving server root outside virtual machine centaury Internet Information Services 3 October 7th, 2008 12:10 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Moving the MySQL Database Root Directory miguelm BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 26th, 2005 02:13 PM



All times are GMT -4. The time now is 02:58 AM.


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