Subject: Re: [xsl] removing nodes to parent based on all child nodes not having text value From: "Cindy Lard" <Cindy.Lard@xxxxxxxxxxx> Date: Mon, 08 Dec 2008 10:09:52 -0600 |
Ken....thank you so very much. I believe this will work nicely. In this case there only needs to be either <Individual> or <Business> under <Entity>. Either the registration is for an individual or business. Both should not exist in the same file. Because the business registration information is being pulled from a legacy system certain information required in the XML may not be available, such as <MailingAddressType/> and <MailingAddressLine2/> as in the preceding example. However, if any descendant element of a child has a text value such as <MailingAddressLine1>123 Street</MailingAddressLine1> it's parent and siblings all need to be copied even if those siblings have no text value the nodes need to be copied. 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 T:\ftemp>type cindy.xsl<?xml version="1.0" encoding="US-ASCII"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ( http://www.w3.org/1999/XSL/Transform%22 ); version="1.0"> <!--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>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] removing nodes to parent , G. Ken Holman | Thread | [xsl] Call for Participation: Proce, B Tommie Usdin |
[xsl] Counting records, Bradley, Peter | Date | Re: [xsl] Counting records, Martin Honnen |
Month |