Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] removing nodes to parent based on all child nodes not having text value

From: "Vasu Chakkera" <vasucv@--------->
To:
Date: 12/4/2008 10:16:00 AM
> <xsl:template match="node()|@*">
> <xsl:copy>
>  <xsl:apply-templates select="node()|@*"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="*[not(descendant::text())]"/>
> </xsl:stylesheet>

That was not complete ..

The below is what i meant..

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
 <xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[not(descendant::text())]"/>
</xsl:stylesheet>


2008/12/4 Vasu Chakkera <vasucv@xxxxxxxxx>:
> Cindy,
> There are two questions in your mail.
>>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?
>
>
> and the scond is :
>
>>>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.
>
> The first one is fairly simple..
>
> <xsl:template match="node()|@*">
> <xsl:copy>
>  <xsl:apply-templates select="node()|@*"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="*[not(descendant::text())]"/>
> </xsl:stylesheet>
>
> Will do your job. That is i am ignoring the elements that do not have
> any text node descendants..
>
> for the second one,
>
> its not very clear what you want.
>
> if between <individual> and <business>,  only one has the text data ,
> then your problem is solved by above template. but
> if <individual> and <business> both contain text data , then  you
> would only want to pick one and not both.
> So which one would you want to pick?
> which has priority over the other?
>
> Vasu
>
> 2008/12/3 Cindy Lard <Cindy.Lard@xxxxxxxxxxx>:
>> 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>
>>
>>
>
>
>
> --
> Vasu Chakkera
> Numerical Algorithms Group Ltd.
> Oxford
> www.vasucv.com
>



-- 
Vasu Chakkera
Numerical Algorithms Group Ltd.
Oxford
www.vasucv.com


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent