On Mon, Feb 03, 2020 at 03:24:48PM +0100, Christian Grün scripsit:
for $value in $xmlReport/csv/record/Payment_Amount where $value castable as xs:double return xs:double($value)
That errors out! [XPTY0004] Cannot convert element()* to xs:double+: $xmlReport_1/element(csv)/element(record)/element(Payment_Amount)[. castable as xs:double].
Did you get this error message for the suggested "for" clause, or a let clause?
The type is on a let clause that derives its value from a for:
let $made as xs:double+ := for $value in $xmlReport/csv/record/Payment_Amount where $value castable as xs:double return $value
The XQuery pandora box provides a lot of type conversions that are all working slightly different: If you specify a type after the let clause, it is (close to) identical to the "treat as" expression. Treating values as another values won’t trigger explicit casts; this is your element nodes won’t be converted to doubles.
I have learned something! Thank you, that makes it make sense.
However, if you specify types in functions, …
declare function local:bla($made as xs:double+) { ... }
…the values will be "promoted" to the specific type (and this is similar to casts).
And now I have learned something else. :)
That's very helpful; much appreciated.
-- Graydon