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
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