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.
Yes; but the text goes on to make clear that the first sentence was an
informal description, and the formal specification is that it returns all
characters whose position p satisfies p >= arg2 and p < arg2 + arg3.
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?
I think it's a consequence of the design philosophy adopted for XSLT 1.0 and
XPath 1.0 that run-time errors are to be avoided at all costs. It's a
logical approach if you start by saying "what we should do if the user asks
for substring($x, 1, 5) and the string is only 4 characters long?" It makes
sense there to return the whole string. But if we accept a limit that's
beyond the right-hand end of the string, it becomes logical to accept a
limit that's beyond the left-hand end...
Anyway, for better or worse, that's the way it's specified, and it's
certainly not something we can change now.
Michael Kay