Monday, March 16, 2015

Creating an attribute within an element using OSB XQuery 11g


For example we have an xml document as follow.

<root>
<invoiceNumber></invoiceNumber>
</root>

Based on above input I want to create one attribute in side an element say,  <testelemnet>.

Following is the code snippet to achieve the required output.

<testelemnet>
{
if (data($getTaxData/invoiceNumber) = '')
then attribute documentNumber {"SALES"}
else
attribute documentNumber {data($getTaxData/invoiceNumber)}
}
</testelemnet>

 Output is as follow.

<testelement documentNumber ="SALES"/>

 Note : If there is an attribute documentNumber  within <testelemnet> an error will be raised due to the duplication of the attribute names.

No comments:

Post a Comment