Re: Erratum substring() function in XPath 1.0?

In a message dated 22/03/02 11:46:42 GMT Standard Time, 
Michael.Kay@softwareag.com writes:


> No. Following the detailed specification, substring("12345", 0, 3) selects
> all characters whose position is >= 0 and < 3. The position of the "3" is 
> 3,
> which is not <3, therefore it is not included in the result.
> 
> Michael Kay
> 
> > -----Original Message-----
> > From: Svgdeveloper@aol.com [mailto:Svgdeveloper@aol.com]
> > Sent: 21 March 2002 21:26
> > To: www-xpath-comments@w3.org
> > Subject: Erratum substring() function in XPath 1.0?
> > 
> > 
> > It seems to me that the following bullet point for the 
> > substring() function 
> > is incorrect:
> > 
> > substring("12345", 0, 3) returns "12" 
> > 
> > Shouldn't it read
> > substring("12345", 0, 3) returns "123"?
> > 
> > Andrew Watt 

Michael,

Thanks for the prompt response. However, I am not yet convinced that the 
description of the substring() function is totally coherent.

The example which I quoted uses as its second argument the number zero, which 
given that the first character in a string is numbered as one means that the 
argument is, arguably, in error since it refers to a character which doesn't 
exist.

The first sentence of the description of the substring() function states that 
the third argument is the "length" of the string returned. However a string 
"12" has, as I understand the term "length" (and as it is used in relation to 
the string-length() function) a length of 2, not 3 as the third argument 
would suggest.

The problem seems to arise from the seeming acceptance of invalid/unreal 
values for the second argument and (I assume) third argument.

For example,
substring("12345", 3, 8) would return "345" I assume, again the "length" 
would diverge from the value of the third argument. I guess that, in some 
surreal sense, you could argue that the length *is* 8 - made up of 3 real 
characters and 5 non-existent ones. <shrug/>

If, as seems to be the case, the substring() function's third argument may 
not always return the "length" of the returned string maybe the reference to 
length should be deleted or qualified in the first sentence.

Perhaps I am being obtuse - I often am :) - but why is a value of 0, for 
example, permitted for the second argument to the function?

Andrew Watt

Received on Friday, 22 March 2002 11:00:38 UTC