[Bug 2678] Can't cast xs:QName to xs:QName

http://www.w3.org/Bugs/Public/show_bug.cgi?id=2678





------- Additional Comments From mike@saxonica.com  2006-01-17 19:29 -------
I was actioned to identify the textual changes needed to permit casting of QName
to QName and NOTATION to NOTATION. Note that this is not just to allow an
identity cast: it also enables casting up and down the type hierarchy.

F+O

In 5.1, delete the caveat: "except for constructors for xs:QName and types
derived from xs:NOTATION which are identical to "cast as xs:TYPE ". "

In 5.1, delete the following two paragraphs:

"Constructor functions for xs:QName and types derived from xs:QName and
xs:NOTATION, ....

The prefix within the lexical xs:QName ....

replacing them with the paragraph:

"Special rules apply to constructor functions for xs:QName and types derived
from xs:QName and xs:NOTATION: see section 5.4."

In the list of constructors (still in 5.1) replace the entry for xs:QName

* xs:QName($arg as xs:string) as xs:QName
$arg must be a xs:string literal.

with

* xs:QName($arg as xdt:anyAtomicType?) as xs:QName?
(see section 5.4 for special rules)

In section 5.3, add a new second paragraph:

"Special rules apply to constructor functions for types derived from xs:QName
and xs:NOTATION: see section 5.4."

Add a new section 5.4 Constructors for xs:QName and xs:NOTATION:

<new>
Special rules apply to constructor functions for the types xs:QName and
xs:NOTATION, for two reasons:

* The lexical representation of these types uses namespace prefixes, whose
meaning is context-dependent

* Values cannot belong directly to the type xs:NOTATION, only to its subtypes.

These constraints result in the following restrictions:

* Conversion from a string to a value of type xs:QName or xs:NOTATION (including
types derived from these) is permitted only if the string is written as a string
literal. This applies whether the conversion is expressed using a constructor
function or using the "cast as" syntax. Such a conversion can be regarded as a
pseudo-function, which is always evaluated statically. It is also permitted for
these constructors and casts to take a dynamically-supplied argument in the
normal way, but as the casting table (see section 17) indicates, the only
arguments that are supported in this case are values of type xs:QName or
xs:NOTATION respectively.

* There is no constructor function for xs:NOTATION. Constructors are defined,
however, for xs:QName, for types derived from xs:QName, and for types derived
from xs:NOTATION.

When converting from a string, the prefix within the lexical xs:QName supplied
as the argument is resolved to a namespace URI using the statically known
namespaces from the static context. If the lexical xs:QName has no prefix, the
namespace URI of the resulting expanded-QName is the default element/type
namespace from the static context. Components of the static context are
discussed in Section C.1 Static Context ComponentsXP. A static error is raised
[err:FONS0004] if the prefix is not bound in the static context. As described in
Section 2.1 TerminologyDM, the supplied prefix is retained as part of the
expanded-QName value.
</new>

In 17.1.1, delete "A static error is raised [err:XPST0083]XP if the argument to
a cast for xs:QName or a type derived from xs:QName or xs:NOTATION is not an
xs:string literal.", replacing it with "If the argument to such a cast is
computed dynamically, error XPTY0004 is raised if the value is of any type other
than xs:QName or xs:NOTATION respectively (including the case where it is an
xs:string)"

In 17.3, change "It is always possible..." to "Except in the case of
xs:NOTATION, it is always possible..."

In 17.5, add a bullet 2a: "If TT is derived from xs:NOTATION, assume for the
purposes of this rule that casting to xs:NOTATION succeeds."

XPATH BOOK

In section 3.10.2 (casting) change this text in 4a:

"If the target type of a cast expression is xs:QName, or is a type that is
derived from xs:QName or xs:NOTATION, the input expression must be a string
literal; otherwise a static error [err:XPST0083] is raised.

Note:

The reason for this rule is that construction of an instance of one of these
target types requires knowledge about namespace bindings. If the input
expression is not a literal, it might be derived from an input document whose
namespace bindings are different from the statically known namespaces.
" 

to read

<new>If the target type of a cast expression is xs:QName, or is a type that is
derived from xs:QName or xs:NOTATION, and if the primitive type of the input is
not the same as the primitive base type of the target type, then the cast is
permitted only in the case where input expression takes the form of a string
literal. All other cases result in a type error [XPTY0004].

Note:

The reason for this rule is that construction of an instance of one of these
target types from a string requires knowledge about namespace bindings. If the
input expression is not a literal, it might be derived from an input document
whose namespace bindings are different from the statically known namespaces.
</new>

Received on Tuesday, 17 January 2006 19:29:59 UTC