470,590 Members | 2,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

max() function problem in XQuery using Saxon


I'm using Weblogic 9.2 which uses Saxon 8.1.1 as its XQuery Engine. I'm using max function and in the argument I'm passing the node which has two dateTime values. It is giving exception.

Following is part of my XML Document:

<effectiveTime value="2007-03-20T18:10:15"/>

Following is part of my XQuery:

$maxTime := (max($bodySect[code/@code='11502-2']/entry/observation/effectiveTime/@value))

It is giving following exception:

net.sf.saxon.DynamicPathError: Cannot convert {2007-02-13T18:10:15} to a number.

Basically, it is trying to convert it into double.
However, the documentation says that comparison can be done with same base type and return max from that. Here we have same base type i.e., xs:dateTime. So, I think there is some conflict between w3c specification and Saxon implementation or may be Iím misinterpreting it.

Hope somebody can help me.

Mar 29 '07 #1
8 3749
839 Expert 512MB
Welcome to TheScripts TSDN...

Try to declare $maxTime as a string variable, and see if it works.
Then convert or parse the string using Java, as desired.
If not, please let us know.
Mar 29 '07 #2
Thanks for quick response.

I've tried. But its giving another error:

Required type of value of variable $maxTime [unallocated] is xs:string; supplied value has type xs:double

Reason is that max function requires double as argument, and when it get String, it tries to convert it into double, but due to presence of special characters in the string, it can't.. I think there should be some method which should accept datetime as argument and return their max. Would it be possible? Your expert opinion in this regard will really help me.

Mar 29 '07 #3
839 Expert 512MB
Use string(max(...)) function to convert the max number to string.
Mar 29 '07 #4
No effect. Same exception. I think I'm unable to understand you the problem. Now I'm re-trying. Basically, it gives exception on the argument of max which is date & time in string format (i.e., 2007-03-30T13:55:15), but max function accepts in double format. And if it is not double (which is in my case), then it tries to convert it into double, which is also not possible (in my case) b/c special characters can't be converted into double.

So, making it string after exception is raised obviously don't have any effect. Exception is raised before converting into string by string(max(...), so it throws

net.sf.saxon.xpath.DynamicError: Failure converting {2007-03-29} to a number
java.lang.RuntimeException: net.sf.saxon.xpath.DynamicError: Failure converting {2007-03-29} to a number
at org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery .execQuery(XBeansXQuery.java:82)
at org.apache.xmlbeans.impl.store.Query$SaxonQueryImp l$SaxonQueryEngine.
at org.apache.xmlbeans.impl.store.Query$SaxonQueryImp l.cursorExecute(Query.java:170)
at org.apache.xmlbeans.impl.store.Query.cursorExecQue ry(Query.java:48)
at org.apache.xmlbeans.impl.store.Cursor._execQuery(C ursor.java:1328)
at org.apache.xmlbeans.impl.store.Cursor._execQuery(C ursor.java:1323)
at org.apache.xmlbeans.impl.store.Cursor.execQuery(Cu rsor.java:3814)
at Controller.execute(Controller.java:282)

Hope you will now understand what I mean. Anyway, I appreciate your prompt respose.

Mar 30 '07 #5
839 Expert 512MB
Try to use a method like in this link.
( that uses for loop and xs:dateTime:
Expand|Select|Wrap|Line Numbers
  1. max(for $d in //@modified return xs:dateTime($d)) 

If not helpful, please post the XML and XSL you are using.

Mar 30 '07 #6
Thanks a lot. It works for me now. for loop within max has worked fine for me.
Thanks once again

Mar 30 '07 #7
839 Expert 512MB
Glad to hear that.
You're always welcome.

God bless you,
Mar 30 '07 #8
I have the same problem. I read the post and there is a reference to a link (3 posts ago) that is dead. Could you please share the solution. I'm pretty stuck :-(. I use Saxon 9.

Kind regards,
Maarten Storm
Jan 7 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tom Corcoran | last post: by
reply views Thread by Benjamin G. Jones | last post: by
7 posts views Thread by Jeff Kish | last post: by
1 post views Thread by FBS | last post: by
8 posts views Thread by Clamps | last post: by
1 post views Thread by Philipp Schumann | last post: by
3 posts views Thread by Bloody Viking | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.