Remove Empty Attributes in XQuery

Here is how you can remove empty attributes while xQuery mapping.

Consider the following input xml:

Input:
Case 1:

<product>
<code>MAX</code>
</product>

Expected Result:
<FinalProduct ProductCode="MAX" >
</FinalProduct>

Case2:

<product>
<code/>
</product>

Expected Result:
<FinalProduct>
</FinalProduct>


Thus, we don't want the attribute to be present if the mapped element is null.

Please find the below snippet for the above problem:

<FinalProduct>

               { 
                      if((fn:boolean(data($product/code)))) 
                         then attribute ProductCode 
                         { 
                            data($product/code)
                         } 
                         else () 
               }
</FinalProduct>

Thanks,
Rohan Lopes


Popular posts from this blog

JAVA embedding in Oracle SOA 12c

Passing/Receiving HTTP header in SOA BPEL

Integrating Weblogic with IBM MQ over JMS