This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using condition expression with an empty string variable
- To: "Yang" <sfyang at unisvr dot net dot tw>
- Subject: Re: [xsl] Using condition expression with an empty string variable
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 21 Jun 2001 13:02:36 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <000901c0fa44$3e041930$1601800a@hqlab.unisvr>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Sun-fu,
> I have applied the following condition expression successfully to my
> job. And this expression pattern is suggested by Jeni back in May
> xsl list.(msg00890.htm)
>
> [@FacilityID[string($office)]=$office]
>
> which is supposed to handle situations as:
> when variable **office** is a given string, then the condition will be
> applied.
> when variable **office** is an empty string, then the condition will not
> be used.
>
> Now I try to apply the expression to a simple case like example
> below, it does not function correctly for the given empty string, it
> produces a set of empty nodes instead. Why?
I think it's because the left hand side is an empty node set, being
compared against an empty string. When a node set is compared for
equality against a string, then it returns true only if there's a node
whose value is equal to that string. With an empty node set, that's
never the case.
I think that in the other situations you must have been doing
something to convert the empty node set into an empty string (e.g.
using substring() or translate() on it). When the two empty strings
were compared, then that returns true.
The solution is to force the conversion of the empty node set to a
string using the string() function:
string(@FacilityID[string($office)]) = $office
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list