I recently started in a project working with the Oracle Service Bus (release 10gR3) and stumbled upon some issues regarding XQuery transformations.
I should note I did not work previously with XQuery, so it is all new to me.
But when trying to use some builtin functions I noticed that some that not work or did not work as expected, so I created some functions on my own and searched on the internet for some solutions.
One site which was useful for me was the FunctX XQuery Function Library (http://www.xqueryfunctions.com/xq/).
I should note I did not work previously with XQuery, so it is all new to me.
But when trying to use some builtin functions I noticed that some that not work or did not work as expected, so I created some functions on my own and searched on the internet for some solutions.
One site which was useful for me was the FunctX XQuery Function Library (http://www.xqueryfunctions.com/xq/).
Nilled elements
One issue was how do you check if an element is nilled (“xsi:nil=true”). There is a builtin function avaible: fn:nilled. But I appeared that this function did not work (at least not within the Oracle Service Bus). So I needed to look for a solution. The following XQuery function will provide you with the expected result:
One issue was how do you check if an element is nilled (“xsi:nil=true”). There is a builtin function avaible: fn:nilled. But I appeared that this function did not work (at least not within the Oracle Service Bus). So I needed to look for a solution. The following XQuery function will provide you with the expected result:
Note: xf is the alias for the local used main namespace; xsi is the alias for the XML Schema Instance namespace.
Empty elements
Another issue was how to check for empty elements. For this there are several solutions, but the builtin function fn:empty does not work.
One solution is to use a function from the FunctX XQuery Function Library:
Another issue was how to check for empty elements. For this there are several solutions, but the builtin function fn:empty does not work.
One solution is to use a function from the FunctX XQuery Function Library:
And of course you can also check manually:
If both nilled and empty elements are allowed, you can combine both XQuery functions into a new single function:
Type casts
When a type cast must be performed with the XQuery transformation you should always check for empty element. Because if you don’t, the transformation will return an error stating the type cast can not be made.
For example when transforming from datetime to date:
When a type cast must be performed with the XQuery transformation you should always check for empty element. Because if you don’t, the transformation will return an error stating the type cast can not be made.
For example when transforming from datetime to date:
Note that when nil values are allowed within the source element the above statement will not work. In that case you should check explicitly for nil values (using either the xf:is_nilled or xf:isEmptyOrNilled function):
Note: in the above example we assume that the element may be nilled. If not you should replace by (). This will result in no element tag being added.
No comments:
Post a Comment