This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Check if element is empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Check if element is empty" Watch "Check if element is empty" New topic

Check if element is empty

Nils Persson

Joined: May 25, 2001
Posts: 21
I want to check if an element is empty (or = 0). How do I do that?
Can I use <xsl:if test=???>?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Using <xsl:if test="name"> tests if the named element is present, so <xsl:if test="not(name)"> should test for its absence.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
Check this:

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Vikram Das

Joined: Jun 18, 2001
Posts: 6
Hi Nils,
If you wanna chk whether the tag is empty (as in this case <tag></tag> ) or whether the tag is not there at all ... you can use a generic thing which will do both of it ... Assuming that the tag is <name>, you can use the xsl given below to do this,
<xsl:if test="count(name/text()) != 0">
Hope this helps...
I agree. Here's the link:
subject: Check if element is empty
Similar Threads
Drag and Drop using jQuery
Can Empty Element contain child nodes?
onblur javascript error
Checking Multiple Variables for One Condition
Migration from WL10.1 to WL10.3 [Descriptor not found: META-INF/annotation-manifest.xml]