Since I’m on a roll with Xquery functions let’s add an addition. Especially since the earlier example is a bit large for people looking for a simple example.
So maybe this helps better to get an understanding. After working with Tibco BusinessWorks for some years I used a lot off the internal tib:functions supplied out-of-the-box and always found it a disappointment that Oracle (read BEA here) didn’t offer such a nice catalog to help you out. So over time I added a lot off these functions to my own library.
For example the function if-absent helps me to prevent all these “is-value1-there-then-use-it-and-if-not-i-want-you-to-use-value2” checks.
declare function funcRBX:if-absent($arg as item()* , $value as item()* ) as item()* { if (exists($arg)) then $arg else $value };
Works like a charm … ;-)