all groups > dotnet xml > august 2003 >
You're in the

dotnet xml

group:

get rid of empty nodes



get rid of empty nodes chris NO[at]SPAM yahoo.com
8/29/2003 11:21:45 AM
dotnet xml: Okay, this is probably a really stupid question - but I just can't figure it
out.

I have a large xml document which is being transformed into another using
..net xsl - some elements inside of which do not have any data at some times
but do at others. If they don't have any data, I want to suppress the
generation of the tag completely in the resulting xml.

So for example, if I have a document:

<root>
<a>alksjdfsd</a>
<b>sdkfjlsdkf</b>
<c/>
<d>askdjf</d>
</root>

and i run it throught the transform, i want:

<new_root>
<new_a>asdfasf</new_a>
<new_b>askljfs</new_b>
<new_d>asdfasdf</new_d>
</new_root>

Something simple i'm missing????

Cheers

Chris

Re: get rid of empty nodes Oleg Tkachenko
8/29/2003 2:26:41 PM
[quoted text, click to view]

Well, you can merely test if an element has no children nodes and
generate nothing then:

<xsl:template match="c">
<xsl:if test="node()">
<new_c>
<xsl:apply-templates/>
</new_c>
</xsl:if>
</xsl:template>

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
AddThis Social Bookmark Button