Have a look in the XPath 2.0 spec Appendix B, Type Promotion and Operator Mapping [1] and XQuery 1.0 and XPath 2.0 Functions and Operators spec section 17, Casting [2]. “If an operator in the operator mapping tables expects an operand of type ET, that operator can be applied to an operand of type AT if type AT can be converted to type ET by a combination of type promotion and subtype substitution.”
2. For expressions such as 5 = ‘5’, it is doing a comparison between a numeral and a string. I’m not sure what is supposed to happen in this case, as decimal is not derived from string and vice versa, and the type promotion rules do not cover this case. It looks like the syntax is correct but the semantics is not allowed. I’m guessing an error should be thrown, perhaps during/after the expression parsing phase, as you should know the type of each value in the expression and can determine whether the evaluation between two types is valid, or just do it in the evaluation phase as the expression is being evaluated. 3. I believe the numeric literal 5 is of type decimal (I think I read somewhere that numeric literals are type decimal). Since the first operand is a decimal and the second operand is an integer, and integer is derived from decimal, you don’t have to do any casting – just use the decimal validator’s compare method to compare both decimal and integer (this is a subtype substitution). 4. You would first cast the decimal 5.1 to an integer, then the string literal 5 to a double and then promote the first operand from an integer to a double (Type promotion 1b, a value of type decimal or any type derived from decimal, i.e. integer, can be promoted to either double or float.) and then compare the two operand’s values. You must perform all casts defined explicitly in the expression as the casts may fail, and then do implicit type promotions or subtype substitutions as necessary to perform the comparison. [1] http://www.w3.org/TR/xpath20/#id-type-promotion-and-operator-mapping [2] http://www.w3.org/TR/xquery-operators/#casting -- View this message in context: http://www.nabble.com/Type-Alternatives%3A-XPath-Evaluation-tp21155338p21170909.html Sent from the Xerces - J - Dev mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
