This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Testing for CDATA
- To: xsl-list at mulberrytech dot com
- Subject: Re: Testing for CDATA
- From: Jeni Tennison <jeni dot tennison at epistemics dot co dot uk>
- Date: Thu, 10 Aug 2000 12:42:09 +0100
- References: <3.0.1.32.20000808195632.00a00ad0@localhost>
- Reply-To: xsl-list at mulberrytech dot com
Mike Brown wrote:
>Jeni Tennison wrote:
>>
>> test="normalize-space(text()) != ''"
>>
>
>It's usually not necessary to compare an unknown string to an empty
>string, because if the unknown string is empty, as a boolean it will be
>false already. So test="normalize-space(text())" would work just as well.
Which is absolutely correct and a great tip.
*BUT* before you go blithely deleting all the " != ''" in your tests,
remember that if you're testing the value of a variable that has been set
using its content, you are testing a *result tree fragment*, not a
*string*. 'Empty' result tree fragments are actually node sets containing
a single text node with a string-value of ''. As a node set with a node in
it, they are always 'true' (no matter that the node is an empty text node).
So, if you do:
<xsl:variable name="foo">
<!-- something that may or may not give some content -->
</xsl:variable>
then the test on whether $foo has any content should be:
test="string($foo)"
and not just:
test="$foo"
(Doh!)
Cheers,
Jeni
Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list