How to perform conditional operations in XQuery ?

 Posted by Bharathi Cherukuri on 5/11/2012 | Category: Web Services, Remoting Interview questions | Views: 1592 | Points: 40
Answer:

Here is a way to perform conditional operations in XQuery.

Example:


for $a in doc("bookmart.xml")/bookstore/book
return if ($a/@category="ADVENTURE")
then <child>{data($a/title)}</child>
else <adult>{data($a/title)}</adult>

Output:

<adult>Jungle Book</adult>
<child>The Book of the Thousand Nights and a Night </child>
<adult>XML Programing</adult>
<adult>XPath and XPointer</adult>


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response