File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!