RE: [F&O] Casting to xs:NOTATION, xs:QName not clarified

> (2) We cannot cast or construct xs:QName and xs:NOTATION
>     from strings in general, i.e. the following expressions 
> are invalid:
>        fn:string(<a>b</a>) cast as xs:QName
>        xs:QName(xs:string("a"))
> 
> Could you please explain why it makes sense to prohibit the 
> examples from (2)? 

The reason that casting of an arbitrary string to a QName or NOTATION is not
permitted is that the result is context-sensitive. Does it make sense to
read a string from a source document and then cast it to a QName, using the
prefix bindings declared in the query or stylesheet? We decided that it
didn't. If you want to convert a lexical QName to a QName, we provide a
function to do that (the fn:QName() function) and this allows you to specify
explicitly the namespace context that you want to use.

When you write xs:QName("abc:fred"), the prefix abc must be declared in the
static context. So casting doesn't make sense unless you know statically
what prefixes you are likely to encounter. If the string has been read from
a source document, then the document author is supposed to have a free
choice of prefix, which means that resolving the QName using the prefixes
declared in the query or stylesheet makes no sense. You want to resolve them
against the prefixes declared in the source document, which is what the
fn:QName function does.

Michael Kay
http://www.saxonica.com/ 

Received on Friday, 28 January 2005 09:17:45 UTC