Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null value

 
Feda Bashbishi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic