IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  sort by in xquery : problem with alphanumerical values

    Posted Tue July 06, 2004 06:05 PM

    Hello!

    I want to sort a document with sort by clause, but I’ve problem to have a good sorting. In my document wich look like this :

    <documents>
    <document>
    <number>001</number>
    </document>
    <document>
    <number>002</number>
    </document>
    <document>
    <number>44</number>
    </document>
    <document>
    <number>333</number>
    </document>
    </documents>



    when I sort on number by doing this sort by (number), output is incorrect because 44 comes after 333 and I think it’s because 4 is after 3, but can I’ve 44 comes before 333?

    thanks in advance

    Nathaire


    #API-Management
    #Tamino
    #webMethods


  • 2.  RE: sort by in xquery : problem with alphanumerical values

    Posted Wed July 07, 2004 12:04 PM

    Hi Nathaire,

    the result is correct, because without any additional type information (e.g. from a schema), XQuery will sort the values as strings (where “333” < “44”). If you want numerical sort, you have to give type information, either in the Tamino schema or in the query, e.g.
    declare namespace xs = “XML Schema
    let $doc:=

    001


    002


    44


    333



    for $i in $doc/document
    sort by (xs:integer(number)) return $i

    Regards

    Harald


    #API-Management
    #Tamino
    #webMethods


  • 3.  RE: sort by in xquery : problem with alphanumerical values

    Posted Wed July 07, 2004 01:04 PM

    Thanks, but I know that.

    The problem is that my field number is and must be of a type string because some contracts (number is for this) can have a number like this : A-1, ZZ-33,…

    Maybe it’s impossible with tamino to sort correctly because I can’t use xs:integer for the field with alphabetical values.

    Am I right?


    #webMethods
    #API-Management
    #Tamino


  • 4.  RE: sort by in xquery : problem with alphanumerical values

    Posted Fri July 09, 2004 12:15 AM

    Maybe it’s impossible with tamino to sort correctly because I can’t use xs:integer for the field with alphabetical values.

    True, you cannot cast a non-numerical contents to a numerical data type. It’s the XQuery spec that does not allow this.

    Regards

    Harald


    #Tamino
    #API-Management
    #webMethods


  • 5.  RE: sort by in xquery : problem with alphanumerical values

    Posted Fri July 09, 2004 11:15 AM

    you can use a different xschema.
    for example yuo can write:


    AA
    333




    AA
    44



    so you can order these documents first with alfapart an than with numerical part

    good job!
    Gibbo


    #API-Management
    #webMethods
    #Tamino