RE: [F&O] CER-09 xs:double parameters to fn:substring

> F&O 7.4.3
> 
> Making the positional parameters to fn:substring be xs:double 
> instead of xs:integer adds complexity and confusion for no 
> obvious benefit. If the rationale is to take advantage of the 
> automatic promotion rules, it is difficult to come up with 
> realistic use cases involving mathematic expressions on 
> substring positions that would lead to values requiring such 
> promotion. Request that if there is no sound justification, 
> change the signatures to use xs:integer instead.
> 

The justification for this decision was:

(a) because XPath 1.0 had no conditional expression, a popular
workaround is to write, for example

substring("abcd", 1 div $condition, 1000)

which evaluates to "abcd" if $condition is true (1) and to "" if
$condition is false (0). This relies on substring() accepting +INF as an
argument.

There is no alternative way of writing this expression that would work
under both XPath 1.0 and XPath 2.0, so we would be forcing a
"single-shot" transition if we stopped supporting it.

(b) because with untyped data, the expression @offset - 1 produces a
double, and the expression

substring("abcd", 1, @offset - 1)

would therefore fail.

I agree that the signature is less than ideal.

Michael Kay

Received on Tuesday, 17 February 2004 12:29:48 UTC