No convenient way to cast one expression to the same type as another?

Given two opaque expressions $x and $y, does XQuery have a convenient 
expression that converts $x to the same (dynamic or static) type as $y?

I can write a gnarly (60+ lines, just to handle singletons) typeswitch that 
converts $x to the dynamic type of $y, provided I'm willing to settle for the 
built-in XQuery types only.  I haven't found any way to handle user-defined 
types, or to convert $x to the static type of $y.

Strangely, this operation does come up (at least for dynamic types); for 
example, the general comparison operators perform this conversion on 
xdt:untypedAtomic values in some cases.

Perhaps there should be a built-in function like
convert-to-same-type-as($exprToConvert as item*, $type as item*) as item*
?

Cheers,

Michael Brundage
Writing as
Author, "XQuery: The XML Query Language" (Addison-Wesley, to appear 2003)
Co-author, "Professional XML Databases" (Wrox Press, 2000)

not as
Technical Lead
Common Query Runtime/XML Query Processing
WebData XML Team
Microsoft

Received on Sunday, 8 June 2003 19:53:04 UTC