This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Testing for CDATA


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]