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

Re: Removing if no data - iterating through every chil

Subject: Re: Removing if no data - iterating through every child (sorry the codes a bit long)
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Fri, 3 Sep 2004 10:48:33 -0700 (PDT)
yahoo address autocomplete
Hi Bryan,
  Please try this XSL -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
	
<xsl:template match="node()">
   <xsl:variable name="flag">
     <xsl:for-each select="@*">
       <xsl:if test="normalize-space(.) != ''">
         1
       </xsl:if>
     </xsl:for-each>
     <xsl:if test="normalize-space(.) != ''">
       1
     </xsl:if>
     <xsl:for-each select="descendant::*">
        <xsl:for-each select="@*">
	  <xsl:if test="normalize-space(.) != ''">
	    1
	  </xsl:if>
	</xsl:for-each>
	<xsl:if test="normalize-space(.) != ''">
	  1
	</xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:if test="contains(normalize-space($flag),
'1')">
      <xsl:copy>
	<xsl:for-each select="@*">
	  <xsl:attribute name="{name()}">
	    <xsl:value-of select="." />
	  </xsl:attribute>
	</xsl:for-each>
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

--- Kevinjohn Gallagher <web_design_guru@xxxxxxxxxxx>
wrote:
> 
> Initially, sorry for the code seeming long. But it's
> a bit of a follow up to 
> yesterdays questions (which I solved thanks to
> y'alls help).
> 
> 
> 
> Ok, so I have an XML file, where I can have any
> number of nodes, which can 
> have any number of Children (and they can have
> children and so on).
> 
> Basically, I want to strip a node if it or it's
> children has no data, or has 
> no attributes with data anywhere in it's
> descendants.
> 
> I sort of get the logic, but fail miserably to even
> consider how to fix it 
> so that the last example works (Checkbox 6) - ie.
> Stripping a tree half way 
> down.
> 
> ANY help would be great.
> 
> Thanks ALot
> 
> Bryan.
> 
> P.S. the number of children in the example is not
> overkill, there will 
> usually be at least 4 - sorry.
> 
> 
> ORIGINAL :
> 
> 		<topNode>
> 			<Checkbox1>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long Attribute="0"/>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox1>
> 			<Checkbox2>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long> data </long>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox2>
> 			<Checkbox3>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long />
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox3>
> 			<Checkbox4>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long Attribute=""/>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox4>
> 			<Checkbox5>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long Attribute="0" attribute=""> data
> </long>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox5>
> 			<Checkbox6>
> 				<really>
> 					<long Attribute="data">
> 						<really>
> 							<really>
> 								<long/>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox6>
> 		</topNode>
> 
> 
> 
> Output :
> 
> 		<topNode>
> 			<Checkbox1>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long Attribute="0"/>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox1>
> 			<Checkbox2>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long> data </long>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox2>
> 			<Checkbox5>
> 				<really>
> 					<long>
> 						<really>
> 							<really>
> 								<long Attribute="0"> data </long>
> 							</really>
> 						</really>
> 					</long>
> 				</really>
> 			</Checkbox5>
> 			<Checkbox6>
> 				<really>
> 					<long Attribute="data" />
> 				</really>
> 			</Checkbox6>
> 		</topNode>




		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

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.