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
Expand all | Collapse all

How to conditional output xml tag using xquery

webMethods Community Member

webMethods Community MemberWed February 22, 2006 05:03 PM

  • 1.  How to conditional output xml tag using xquery

    Posted Tue February 21, 2006 02:18 AM

    I want to use xquery to transform an xml document to another one. Some of the tags in the output xml are conditional based on the value of the input xml document. How to write this in xquery? I used following xquery statement:
    if (fn:not(fn:empty($s))) then fn:concat(“”, $var1, “</BOOK”) else “”
    But the output from the xquery replaced ‘<’ with &lt and ‘>’ with &gt. Is this the correct way of implementing this? How to avoid such replacement?

    thanks!


    #webMethods
    #Tamino
    #API-Management


  • 2.  RE: How to conditional output xml tag using xquery

    Posted Tue February 21, 2006 09:32 AM

    very simple:

    
    if (fn:not(fn:empty($s))) then <BOOK>{$var1}</BOOK> else ()

    or better

    
    if ($s) then <BOOK>{$var1}</BOOK> else ()

    The following also works:

    
    (<BOOK>{$var1}</BOOK>)[$s]

    #API-Management
    #webMethods
    #Tamino


  • 3.  RE: How to conditional output xml tag using xquery

    Posted Wed February 22, 2006 05:03 PM

    Thank you, it worked.


    #API-Management
    #webMethods
    #Tamino