[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

removing nodes to parent based on all child nodes not

Subject: removing nodes to parent based on all child nodes not having text value
From: "Cindy Lard" <Cindy.Lard@xxxxxxxxxxx>
Date: Wed, 03 Dec 2008 15:22:10 -0600
 removing nodes to parent based on all child nodes not
I am new to XSLT and I am trying to clean up an XML file built from a
mainframe generated text file that contains all possible elements for all
nodes. In the new XML I only need to copy the nodes that actually have
elements that have text values. Is there a way to test the deepest child of an
element for text value and then copy all it's ancestors back to the root? For
example, in the attached input under the element <Entity> only <Individual> or
<Business> should exist and not both. If any child elements have text value
for the element <Individual> all child nodes should be copied, while the
<Business> element and all it's child nodes should not be copied to the new
XML file. See example input and output files.

Input


<Registration>
 <UserName>DID1901</UserName>
 <ActivityType>25</ActivityType>
 <ActivityDate>2008-10-30T12:10:26</ActivityDate>
 <RegistrationCounty>19</RegistrationCounty>
 <Registrants>
  <Registrant>
   <Entity>
    <Individual>
     <Prefix/>
     <FirstName></FirstName>/>
     <LastName></LastName>/>
     <Middle/>
     <Suffix/>
    </Individual>
    <Business>
     <MailingAddress>
      <Address>
       <MailingAddressType/>
       <MailingAddressLine1>123 Street</MailingAddressLine1>
       <MailingAddressLine2/>
      </Address>
     </MailingAddress>
    </Business>
   </Entity>
  </Registrant>
 </Registrants>
</Registration>



Output


<Registration>
 <UserName>DID1901</UserName>
 <ActivityType>25</ActivityType>
 <ActivityDate>2008-10-30T12:10:26</ActivityDate>
 <RegistrationCounty>19</RegistrationCounty>
  <Registrants>
  <Registrant>
   <Entity>
    <Individual>
     <Prefix/>
     <FirstName>Joe</FirstName>/>
     <LastName>Doe</LastName>/>
     <Middle/>
     <Suffix/>
    </Individual>
   </Entity>
  </Registrant>
 </Registrants>
</Registration>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.