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.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  return all based on a condition.

    Posted 07/02/03 08:49 AM

    Hi I am new to XQuery and want to know whether I can return all the nodes in the xml file based on a condition.
    For eg:

    {
    FOR $b IN document(“bib.xml”)/bib/book
    WHERE $b/publisher = “Addison-Wesley”
    RETURN

    { $b/title }

    }


    This XQuery returns only the book node and its child node. What I need is that it should return all the nodes in bib.xml based on the condition.

    Thank You
    Kulkarni


    #Tamino
    #webMethods
    #API-Management


  • 2.  RE: return all based on a condition.

    Posted 07/02/03 10:13 AM

    I missed a thing, what I am expecting from the return statement is all the node/text pair values.
    For eg: JK Rowling
    then XQuery should return author and JK Rowling
    Is it possible to get the node/text values of the childnodes of each node if it has any?

    Thank You
    Kulkarni


    #Tamino
    #API-Management
    #webMethods


  • 3.  RE: return all based on a condition.

    Posted 07/02/03 11:15 AM

    I’m not 100% sure what your expecting to be returned. If you just want all the elements which match your criteria - plus the full tree structure below them, then you can just do:-


    {
    FOR $b IN document(“bib.xml”)/bib/book
    WHERE $b/publisher = “Addison-Wesley”
    RETURN
    $b


    Hope that helps

    Mike Ball


    #Tamino
    #webMethods
    #API-Management


  • 4.  RE: return all based on a condition.

    Posted 07/02/03 12:57 PM

    Hi Thanx for the reply, thats the part of the answer I required, Thanx. But can I just the get the element name and the text for each node/child node in the document?

    JK Rowling

    author = JK Rowling


    #Tamino
    #API-Management
    #webMethods


  • 5.  RE: return all based on a condition.

    Posted 07/02/03 03:27 PM

    If you want to return all the books that satisfy the condition, write:


    {
    for $b in document(“bib.xml”)/bib/book
    where $b/publisher = “Addison-Wesley”
    return $b
    }


    I hope I’ve interpreted your requirements correctly, if not, it helps if you explain what you want the output to be.

    Michael Kay


    #Tamino
    #API-Management
    #webMethods


  • 6.  RE: return all based on a condition.

    Posted 07/02/03 03:32 PM

    Actually there’s a simpler way of writing this:


    {
    document(“bib.xml”)/bib/book
    [publisher = “Addison-Wesley”]
    }


    #API-Management
    #webMethods
    #Tamino


  • 7.  RE: return all based on a condition.

    Posted 07/02/03 07:22 PM

    Hello there,

    to get a result like “author = JK Rowling” you could use something like this in the query:

       ...
    return 
    <book>
    {local-name($b/author)} = {$b/author/text()}
    </book>
    ...


    I hope that helps (rather than confuses matters!),
    Trevor.


    #Tamino
    #API-Management
    #webMethods


  • 8.  RE: return all based on a condition.

    Posted 07/03/03 08:47 AM

    Thanx Trevor,
    I used your code snippet and I was able to see
    author = JK Rowling
    as the output.
    The snippet displays only the author element, Can you please tell me how I can get all the elements in a document including the child elements along with the text?
    And without the tag. Thanx again for ur solution.
    for eg:

    TCP/IP Illustrated

    Stevens
    W.

    Addison-Wesley
    65.95


    Result
    Year=1994
    title = TCP/IP Illus…
    Author =
    last = Stevens
    first W.


    #Tamino
    #API-Management
    #webMethods


  • 9.  RE: return all based on a condition.

    Posted 07/04/03 05:47 PM

    If you want to do this completely generically, you need to write a recursive function. That’s beyond the subset Tamino currently offers. The function would look something like this:

    define function show($e as element()) as xs:string {
    string-join (
    (name($e), “=”,
    if ($e/)
    then for $c in $e/
    show($c)
    else string($e)
    ), “”)
    }

    You would need some refinement on that to get all the spacing and indentation right.

    XQuery isn’t really designed for presentation tasks such as this, it’s more of a job for XSLT really. Use XQuery to get the data you want from the XML database, use XSLT to format it for display.

    Michael Kay


    #webMethods
    #API-Management
    #Tamino