On 16/12/2010 21:45, Young Matthew (4004) wrote:
hej,
 
Using latest Saxon HE with the following xpath:
     declare namespace xs="http://www.w3.org/2001/XMLSchema";
     declare namespace xsi=http://www.w3.org/2001/XMLSchema-instance;
     declare namespace pojo=http://www.klistret.com/cmdb/ci/pojo\;
     /pojo:Element[pojo:fromTimeStamp gt xs:dateTime(\"2010-07-08T16:38:00.478+02:00\")]
 
The fromTimeStamp element is a xs:dateTime

If you're using Saxon HE, then the transformation is not schema-aware, so the fact that it's an xs:dateTime is irrelevant - Saxon sees it as xs:untypedAtomic.

and what I am doing is parsing the Saxon expression into my own "expression" representation that is simplified to map the individual steps (in an xpath) to a Hibernate query.  If I don't earmark the literal with the "xs:dateTime" function the literal is a StringValue type.  This bombs since in my Hibernate code I do a restriction off the Java object (which unfortunately is a String rather than a Date).
     value = Value.convertToJava(literal.asItem());
 
 
Using the "xs:dateTime" function casts a warning:
     Warning: Comparison of xs:untypedAtomic? to xs:dateTime will fail unless the first operand is empty

I would suggest converting both sides to xs:dateTime:

xs:dateTime(pojo:fromTimeStamp) gt xs:dateTime(\"2010-07-08T16:38:00.478+02:00\")

You could compare them as strings but that would have the wrong semantics e.g. if timezones differ.


 
Plus the literal is wrapped inside a TraceExpression. 

That suggests that you have chosen somewhere to compile your code with tracing enabled.
Anyway to write the xpath expression without wrapping the literal (ie. it is automatically transformed by Saxon into a DateTimeValue)?
 

You can have the lhs automatically treated as an xs:dateTime if you make your code schema-aware (needs Saxon-EE). Automatic conversion of the rhs from untypedAtomic is possible, but not from string.

Michael Kay
Saxonica