webMethods

webMethods

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.  Simple Where clause in Xquery

    Posted Thu April 01, 2004 07:00 AM

    I am using the following Xquery:
    for $b in input()/WineMaking/Vintage
    where $b/ProductionYear > 1800
    return $b/Quality

    ProductionYear and Quality are elements (not attributes.
    This query is not returning any result. Could anyone please help me out of this.


    #API-Management
    #webMethods
    #Tamino


  • 2.  RE: Simple Where clause in Xquery

    Posted Thu April 01, 2004 12:08 PM

    Hi,

    could you please post sample data and the schema? Otherwise this is hard to answer

    regards

    Harald


    #webMethods
    #Tamino
    #API-Management


  • 3.  RE: Simple Where clause in Xquery

    Posted Fri April 02, 2004 07:01 AM

    Hi Harald,
    Here the sample data:

    <?xml version="1.0" encoding="UTF-8"?>

    Chablis
    Chardonnay
    Medoc 1855

    U.S
    North
    CA


    1855
    3.0

    Sweet
    Medoc

    5 Years
    Oak Barrel



    Bordeaux
    Columbard
    Medoc 1855

    U.S
    Bordeaux
    CA


    1910
    9.0

    Semi-dry
    Chateaux

    5 Years
    Barrel




    Sample Schema:

    <?xml version = "1.0" encoding = "UTF-8"?>
    <xs:schema xmlns:tsd = “http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition” xmlns:xs = “XML Schema”>
    xs:annotation
    xs:appinfo
    <tsd:schemaInfo name = “WineSchema”>
    <tsd:collection name = “Wine”></tsd:collection>
    <tsd:doctype name = “WineMaking”>
    tsd:logical
    tsd:contentclosed</tsd:content>
    </tsd:logical>
    </tsd:doctype>
    </tsd:schemaInfo>
    </xs:appinfo>
    </xs:annotation>
    <xs:element name = “WineMaking”>
    xs:complexType
    xs:sequence
    <xs:element name = “WineName” type = “xs:string”></xs:element>
    <xs:element name = “GrapeType” type = “xs:string”></xs:element>
    <xs:element name = “WineLabel” type = “xs:string”></xs:element>
    <xs:element name = “ProductionArea”>
    xs:complexType
    xs:sequence
    <xs:element name = “Country” type = “xs:string”></xs:element>
    <xs:element name = “Region” type = “xs:string”></xs:element>
    <xs:element name = “Town” type = “xs:string”></xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name = “Vintage”>
    xs:complexType
    xs:sequence
    <xs:element name = “ProductionYear” type = “xs:gYear”></xs:element>
    <xs:element name = “Quality” type = “xs:string”></xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name = “Taste” type = “xs:string”></xs:element>
    <xs:element name = “WineProducer” type = “xs:string”></xs:element>
    <xs:element name = “ProductionProcess”>
    xs:complexType
    xs:sequence
    <xs:element name = “AgingPeriod” type = “xs:string”></xs:element>
    <xs:element name = “StorageMedium” type = “xs:string”></xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Thanks,
    -Lak


    #Tamino
    #API-Management
    #webMethods


  • 4.  RE: Simple Where clause in Xquery

    Posted Mon April 05, 2004 12:00 PM

    Hi Lak,

    ProductionYear is of type xs:gYear. For this reason, you cannot simply compare it to an integer. XQuery offers two choices to resolve the situation: either construct a comparison value of type xs:gYear (using xs:gYear(1800)) or cast the ProductionYear to integer. Unfortunately, the casting function xs:gYear will be available in Tamino V4.2 only, thus, only the second choice remains for you. The following query should do the job:

    declare namespace xs=“XML Schema
    for $b in input()/WineMaking/Vintage
    where xs:integer(string($b/ProductionYear)) > 1900
    return $b/Quality

    Note that XQuery does not support a direct cast from xs:gYear to xs:integer. This is why the string function has to be applied first.

    Regards

    Harald


    #Tamino
    #API-Management
    #webMethods