In a Oracle Service Bus (OSB) environment, a proxy service usually does some XML transformations. So a XML element conversion from business service data to endpoint WSDL structure will be done. In some cases, returning empty elements ( as ) is not allowed. This can only be handled programmatically. All the optional elements have to be checked against null value (NVL in SQL).
Pseudocode: If Element Value is Null, then do not return the complete Element
With XQuery it would look something like this:
(:: if element content is empty, then do not return the element ::)
{
if (data($detailViewCollection1/ns1:detailView[1]/ns1:email1) > "") then
(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:email1) }
)
else()
}
(:: if element content is empty, then do not return the element ::)
{
if (data($detailViewCollection1/ns1:detailView[1]/ns1:email2) > "") then
(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:email2) }
)
else()
}
(:: if element content is empty, then do not return the element ::)
{
if (data($detailViewCollection1/ns1:detailView[1]/ns1:telefon1) > "") then
(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:telefon1) }
)
else()
}
Uuupps, very ugly, isn’t it? No programmer likes to program like this…..
Actually, in XQuery normal user defined functions can be created as like in most other languages:
declare function local:emptyValue($element as element() )
{
if (data($element) > "")
then
(
$element
)
else()
};
With this little function the main XQuery code looks much better. Unfortunatelly, the Oracle Service Bus (OSB) Editor in Eclipse OEPE doesn’t like this very much. The graphical tool shows a warning on each function call … “the content of one of the XML element is not supported by the mapper” ….
OK, let’s just ignore this graphical mapper problem, because we only initially use this mapper, after that all XQuery will be changed/edited in the source code itself.
So now it’s a little more clean XQuery code:
{local:emptyValue(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:email1) }
)}
{local:emptyValue(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:email2) }
)}
{local:emptyValue(
{ data($detailViewCollection1/ns1:detailView[1]/ns1:telefon1) }
)}
Dear , could you please send me full transofmation file