[xquery-talk] xqts:CastableAs648 variable castable as

Michael Kay mike at saxonica.com
Tue Mar 6 10:16:26 PST 2007

> I know Saxon honours this behaviour of returning false for 
> this, but I still find it a bit odd to not be able to test 
> without casting the referenced value.
> let $var := "ABC" return $var castable as xs:QName
> I would be glad if someone could give their opinion on this 
> issue or point me to any previous discussion.

The restriction that "cast as xs:QName" (and therefore "castable as
xs:QName") should only work on string literals is a rather odd one, in that
it appears to violate the principle of orthogonality. The reason for the
restriction was the feeling that it didn't make sense for the result of a
cast to be context-sensitive: it means that an optimizer, before rearranging
an expression, has to do special checks that it isn't moving a cast to a
place where the namespace context is different. In fact I think the
rationale used at the time is a little questionable, but it's a restriction
that does no harm: if you want to construct a QName, then you ought to know
what the namespace and local name components of the QName are, and you can
then use the fn:QName() function to construct it unambiguously.

Or perhaps you're pointing to a slightly different oddity, which is that
($var castable as xs:QName) feels more like a syntax error than an
expression that should return false. Well, the problem here is where to draw
the line. We decided that "castable as" should always return true or false,
and that we wouldn't try to make a distinction between cases where the cast
would fail as a type error (invalid input type) and those where it would
fail as a dynamic error (invalid input value), because we felt that
distinction was too subtle to impose on users. Then we simply extrapolated
that policy to this case.

Michael Kay

More information about the talk mailing list