Subject: Re: [xsl] 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) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Removing if no data - iterati, Kevinjohn Gallagher | Thread | Re: [xsl] Removing if no data - ite, Kevinjohn Gallagher |
RE: [xsl] Newby Question..., Pieter Reint Siegers | Date | [xsl] RE: sorting titles w stopword, Susan Campbell |
Month |