max() function problem in XQuery using Saxon

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ismailj
    New Member
    • Mar 2007
    • 7

    max() function problem in XQuery using Saxon

    Hi,

    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:

    <effectiveTim e 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.Dy namicPathError: 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.

    Thanks,
    Ismail
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    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.
    Thanks,
    Dorin.

    Comment

    • ismailj
      New Member
      • Mar 2007
      • 7

      #3
      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.

      Ismail

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        Use string(max(...) ) function to convert the max number to string.

        Comment

        • ismailj
          New Member
          • Mar 2007
          • 7

          #5
          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.xp ath.DynamicErro r: Failure converting {2007-03-29} to a number
          java.lang.Runti meException: net.sf.saxon.xp ath.DynamicErro r: Failure converting {2007-03-29} to a number
          at org.apache.xmlb eans.impl.xquer y.saxon.XBeansX Query.execQuery (XBeansXQuery.j ava:82)
          at org.apache.xmlb eans.impl.store .Query$SaxonQue ryImpl$SaxonQue ryEngine.
          cursorExecute(Q uery.java:269)
          at org.apache.xmlb eans.impl.store .Query$SaxonQue ryImpl.cursorEx ecute(Query.jav a:170)
          at org.apache.xmlb eans.impl.store .Query.cursorEx ecQuery(Query.j ava:48)
          at org.apache.xmlb eans.impl.store .Cursor._execQu ery(Cursor.java :1328)
          at org.apache.xmlb eans.impl.store .Cursor._execQu ery(Cursor.java :1323)
          at org.apache.xmlb eans.impl.store .Cursor.execQue ry(Cursor.java: 3814)
          at Controller.exec ute(Controller. java:282)


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

          Thanks,
          Ismail

          Comment

          • dorinbogdan
            Recognized Expert Contributor
            • Feb 2007
            • 839

            #6
            Try to use a method like in this link.
            ( that uses for loop and xs:dateTime:
            Code:
            max(for $d in //@modified return xs:dateTime($d))
            )

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

            Thanks,
            Dorin.

            Comment

            • ismailj
              New Member
              • Mar 2007
              • 7

              #7
              Thanks a lot. It works for me now. for loop within max has worked fine for me.
              Thanks once again

              Ismail

              Comment

              • dorinbogdan
                Recognized Expert Contributor
                • Feb 2007
                • 839

                #8
                Glad to hear that.
                You're always welcome.

                God bless you,
                Dorin.

                Comment

                • mtstorm
                  New Member
                  • Jan 2008
                  • 1

                  #9
                  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

                  Comment

                  Working...