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