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.  Xquery with text-contains

    Posted Wed September 27, 2006 09:40 PM

    Hello,

    I’m about to learn using Xquery with Tamino. Everything was going well so far but now I got stuck (although trying to get a solution for several hours…) Hope you can help me out, please.

    I have XML-data containing some newspaper articles which has some text-elements. Now, I want to find the article(s) whose text-element contains the word “politics” and get as a result the text and the id-attribute of its article-element.

    <issue>
    <article id="1">
    <text>xxx xxx politics xxx xxx xxx</text>
    </article> 
    <article id="2">
    <text>xxx xxx xxx xxx xxx xxx</text>
    </article>
    </issue>

    What I already have is an Xquery that gets all the text-elements which contain “politics” but not the id-attributes of their article-elements. How do I have to extend my xquery? Or is it a totally wrong way?

    declare namespace ft="http://www.w3.org/2002/04/xquery-operators-text"
    for $q in input()/issue/article//text
    where ft:text-contains($q, "politics")
    return $q

    Thanks a lot in advance!


    #webMethods
    #API-Management
    #Tamino


  • 2.  RE: Xquery with text-contains

    Posted Thu September 28, 2006 10:24 AM

    Hi,

    first of all: please do not use ft: functions, they are deprecated. Please use functions from the tf: namespace, in this case tf:containsText.

    Concerning your question:

    I changed the namespace, but in Tamino 4.4. this namespace is pre-declared, so you can also leave out the “declare namespace” line.

    Your query is almost what you want to do, just iterate on the article level in acddition to the text node level, please see below:

    
    declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
    
    for $article in input()/issue/article
    for $text in $article//text
    where tf:containsText($text, "politics")
    return <Textfragment>{$article/@id,$text}</Textfragment>

    Regards

    Harald


    #Tamino
    #webMethods
    #API-Management


  • 3.  RE: Xquery with text-contains

    Posted Thu September 28, 2006 08:43 PM

    Harald, thanks a lot for your answer. It works fine! I am using Tamino 4.2, so the ft:functions worked well but thanks for the hint.

    Is the xpath following/preceding-axis already implemented in version 4.2? Imagine above xml-document having more text-elements inside an article-element and i want not only to get the text-element with the searched keyword but also one text-element before and one behind it to have some context. Can I use preceding/following-axis or is there another way to do it? How do I have to extend the last xquery.

    Thanks in advance!

    Max


    #Tamino
    #API-Management
    #webMethods


  • 4.  RE: Xquery with text-contains

    Posted Mon October 02, 2006 07:23 PM

    From the Tamino XQuery reference manual (xqueryref/ref-Axis.htm), the only axis specifications supported are child, descendant, parent, ancestor, attribute, self, and descendant-or-self.


    #API-Management
    #webMethods
    #Tamino