Re: checking for a null value

Subject: Re: checking for a null value
From: Mike Brown <mike@xxxxxxxx>
Date: Tue, 16 May 2000 21:25:22 -0600 (MDT)
Next time, put a subject in your message headers.

> <DEPOSIT>
>   <A>fixedDeposit</A>
>   <B>RecurringDeposit</B>
> </DEPOSIT>
> 
> In the above mentioned case, some times the value of
> either A or B will be null, but while i extract the
> info through stylesheet, i have to check for the
> element which has null and i must not print it.
>
> how can we check for a null value in an element in XSL

The value is actually a text node child of the element node 'A':

<xsl:if test="A/text()">
will be true if there exists a text node child of any 'A' element children
of the current node

An element node's string-value is the concatenation of the character data
from all its text node descendants (children, grandchildren, etc). Often
it is easy to just test the element node itself:

<xsl:if test="normalize-space(A)">
will be true if the string-value of any of the 'A' element children of
the current node contain more than just whitespace characters

<xsl:if test="A=''">
will be true if the string-value of any of the 'A' element children of the
current node is empty

However, I think it is good practice to be a little more specific:

<xsl:if test="normalize-space(A[1]/text())"/>
will be true if any of the text node children of the first 'A' element
child of the current node contain more than just whitespace characters

   - Mike
___________________________________________________________
Mike J. Brown, software engineer, Webb Interactive Services
XML/XSL stuff: http://www.skew.org/    http://www.webb.net/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread