Re: Behaviour of fn:string on sequences

Kay, Michael wrote:
> The function calling rules tell you the answer.
> 
> Given a signature of "item()?"
> 
> - in 1.0 compatibility mode, items after the first in the sequence are 
> ignored
> 
> - otherwise, you get a type error.
> 

Thanks for the help. Please forgive any 'stupid' questions, I am trying 
to implement a small subset of XPath 2.0 at the moment and am finding it 
very hard work plowing through the 4 or 5 specifications. Is there an 
overview document that explains what all the different specifications 
are for and is a good place to start learning about it. At the moment I 
am blindly jumping between them looking for the bits and pieces that I need.

So let me get this straight (ignoring XPath 1.0 compatability mode).

  o  An empty sequence results in an empty string.
  o  A sequence with one item is the same as passing in a single item.
  o  A sequence with more than one item is an error.

That seems very inconsistent to me. Why does fn:string not take a 
sequence ? It could return a string consisting of the concatenation of 
the results of applying fn:string to each item in the sequence with 
possibly a space separator between them, although the separator could be 
supplied as an optional second parameter.

How do I get the string representation of a sequence ?
Is there another function to do this ?

On a similar note, the specification for fn:boolean says ".... If 
$srcval is an atomic value ....". However, fn:boolean takes a sequence 
so I presume that $srcval is an 'atomic value' if the sequence contains 
a single item. However, this behaviour does not appear to have any real 
meaning when applied to a sequence.
e.g. I often want to be able to tell whether a sequence is empty. In 
XPath 1.0 if I gave it a node set then it would return false if it was 
empty and true otherwise. This is also how it behaves in XPath 2.0. 
However, if I give it a sequence of atomic types (as opposed to a 
sequence of nodes) then it does not tell me whether the sequence is 
empty as a non empty sequence containing a single atomic value could 
evaluate to false.

I understand that this is a consequence of treating a sequence 
containing a single item and that item the same. However, is that really 
a good idea given the strange behaviour that it causes in relatively 
simple functions such as these two.

> Michael Kay
> 
> 
>  > -----Original Message-----
>  > From: Paul Duffin [mailto:pduffin@volantis.com]
>  > Sent: 23 October 2003 14:15
>  > To: public-qt-comments@w3.org
>  > Subject: Behaviour of fn:string on sequences
>  >
>  >
>  >
>  > fn:string does not state how it should behave when given a sequence
>  > containing multiple items. The formal semantics paper does
>  > explain that
>  > as it has an item? parameter it should be passed the first
>  > item in the
>  > sequence when in XPath 1.0 compatability mode. However, nowhere can I
>  > find how it should behave when it is not in compatability mode.
>  >
> 

Received on Thursday, 23 October 2003 11:05:28 UTC