File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Product and Other Certifications and the fly likes null value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "null value" Watch "null value" New topic
Author

null value

Feda Bashbishi
Greenhorn

Joined: Feb 25, 2004
Posts: 7
Hello,
I have a Q.
In XSLT, how can I use the <xsl:if> condition to check if a context node's value (i.e. node()) is null? something similar to "if (string == null) ...."
thanks,


fb
Hari Vignesh Padmanaban
Ranch Hand

Joined: Oct 07, 2003
Posts: 578
No. You cant !!!
The syntax for xsl:if is as follows
<xsl:if test= boolean-expression>
<!-- processing -->
</xsl:if>
Teh attribute test is required and teh condition is tested only based on the value returned by the boolean expression. This can be only "true", "false", 0 (for false). It cannot be null !!!
An example is:


hope this helps
Vidya Ravi
Greenhorn

Joined: Mar 03, 2004
Posts: 14
Hey,
Try this
- <xsl:if test="normalize-space(<Node Name here> ) !=''">

</xsl:if>

[Edited:]
Vidya,
Welcome to Javaranch. When posting code like this, please
disable the smiles using the toggle at the bottom of the page.
[ March 03, 2004: Message edited by: Madhav Lakkapragada ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
No. You cant !!!
Yes, you can. See the example from Vidya above.
Additionally, you could also check the length of the string,
take a look at the string functions available.

- m
Hari Vignesh Padmanaban
Ranch Hand

Joined: Oct 07, 2003
Posts: 578
Guess I was wrong !!! :roll:
Sorry Feda..
Vidya and Madhav, Thanks for lettimg me know
Good to see some participation
[ March 03, 2004: Message edited by: Hari Vignesh Padmanaban ]
Feda Bashbishi
Greenhorn

Joined: Feb 25, 2004
Posts: 7
yes Madhav. On the same line of thought, this is what I did:
1. Defined my node value-without the children nodes-with xsl:variable.
<xsl:variable name="rootValue"><xsl:value-of select="child::root/text()"/></xsl:variable>
2. checked for null value
<xsl:if test="string-length($rootValue) != 0"><xsl:value-of select="$rootValue"/></xsl:if>
Or:
inside the defined template
<xsl:if test="string-length(text()) !=0">whatever goes here</xsl:if>

thanks,
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Good to see some participation
What do you mean?
You think you could mislead people and we will let you get away with it.....
- m
Hari Vignesh Padmanaban
Ranch Hand

Joined: Oct 07, 2003
Posts: 578
You think you could mislead people and we will let you get away with it.....
- m[/QB]

Thats what I meant by participation !!!
making sure people are not misleaded and also help people who are wrong realize what is right !!! hats off to you guys
And, i think (to be safe ..not sure ) that even though it is possible to test if teh node is null, the value returned by the functions used would still be NOT null. So it goes on with my point "No YOU CANT" just with a slight modification
No. You cant check for null as such in a xsl:if statement, but can use other functions that would return 0 or false to indicate that it is a null node
regards
hari
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
You cant check for null as such in a xsl:if statement, but can use other functions that would return 0 or false to indicate that it is a null node
Whatever makes you happy, Hari.....
- m
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null value