[Home] [By Thread] [By Date] [Recent Entries]
At 2008-12-05 09:32 -0600, Cindy Lard wrote:
Thank you all so much for your help. The example data was not correct as you pointed out. The input and desired output should have been as follows: Fine, that's a one line change, and the result is below. If no descendant elements have a text value as is the case with <Individual> that node and all descendant nodes of that element need to be stripped out. Wow, I hope that wasn't too confusing. Yes it wasn't too confusing. Having the example helps. All the templates I have used thus far will strip out any element with no text value, which removes the needed (dare I say required) elements of <MailingAddressType/> and <MailingAddressLine2/> under the <Address> element. I hope the code below helps. All I changed was the match criteria for the elements that are preserved. It is all in how you say it! :{)} . . . . . . . . . Ken
<!--preserve all elements whose descendant has text or who has a parent that
has a leaf child with text-->
<xsl:template match="*[.//*[normalize-space(.)] or
../*[not(*) and normalize-space(.)]]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template><xsl:template match="*"> <!--do nothing for elements that don't have a text value descendant--> </xsl:template> <xsl:template match="@*"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet> T:\ftemp>type cindy1.xml <Registration> <UserName>DID1901</UserName> <ActivityType>25</ActivityType> <ActivityDate>2008-10-30T12:10:26</ActivityDate> <RegistrationCounty>19</RegistrationCounty> <Registrants> <Registrant> <Entity> <Individual> <Prefix/> <FirstName/> <LastName/> <Middle/> <Suffix/> </Individual> <Business> <MailingAddress> <Address> <MailingAddressType/> <MailingAddressLine1>123 Street</MailingAddressLine1> <MailingAddressLine2/> </Address> </MailingAddress> </Business> </Entity> </Registrant> </Registrants> </Registration> T:\ftemp>call xslt cindy1.xml cindy.xsl cindy1.out T:\ftemp>type cindy1.out
<?xml version="1.0" encoding="utf-8"?><Registration>
<UserName>DID1901</UserName>
<ActivityType>25</ActivityType>
<ActivityDate>2008-10-30T12:10:26</ActivityDate>
<RegistrationCounty>19</RegistrationCounty>
<Registrants>
<Registrant>
<Entity><Business> <MailingAddress> <Address> <MailingAddressType/> <MailingAddressLine1>123 Street</MailingAddressLine1> <MailingAddressLine2/> </Address> </MailingAddress> </Business> </Entity> </Registrant> </Registrants> </Registration> T:\ftemp>rem Done! -- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



