Re: [xsl] xpath2 functions returning ()

Subject: Re: [xsl] xpath2 functions returning ()
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 4 Jan 2002 15:49:09 +0000
David,

> Xpath 2 seems to want to treat () special in many contexts. Most of
> which seem unfortunate:-) The example above is one, sum() returning
> the empty sequence instead of 0 is another (that seems to be much
> worse, and will mean that you will almost always have to special
> case any value returned from sum() to check if it is empty and if so
> replace it with 0)

I can understand the use of the empty sequence in *some* of the cases,
where the function is supposed to return a value for which there is no
legal and sensible 'null' value. For a QName (the result of the name()
function), for example, what would you use as a 'no QName' value? Or
for a dateTime?

But I agree that it's confusing, particularly because empty sequences
just disappear when you create a sequence that includes them. That's
where if-absent() is going to come in handy, I think.

Using if-absent() in this example:

  <xsl:value-of select="for $e in ancestor::node()
                            return if-absent(name($e), '')"
                separator="/" />

[I worry about if-absent() though - don't the arguments against having
if as a function apply to the if-absent() function as well (i.e. you
might not want the second argument to be evaluated)?]

The sum() function is an example where, I agree, it just seems
unnecessary, since 0 is a sensible alternative. I guess that the
argument is that if you get back 0 then you don't know whether that's
because there were no items to sum or because they actually summed to
0. But you can always check the number of items in the sequence
separately, and it seems to me that the number of times that you need
to make the distinction is far less than the number of times when the
distinction really doesn't matter.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread