SOA Top Tips #1 – Using a common XQuery Function Library

Robert van Molken

In this series I will tell you about my favorite tips I give to colleagues and other integration developers during my daily work.
My first tip is about the usage of a common XQuery Function Library.

During my daily work I come across easy transformations, but some can get quite complex. In XQuery for instance you have a lot of power in your hands by using complex FLOWR expressions, but usually the most common mappings include checking an element for existence and performing an if/else construction.

{
  if ($aisOutputVariable.OutputParameters/haa:P_AIS_OUTPUT/haa:MESSAGE_NUMBER)
  then 
    
      {fn:data($aisOutputVariable.OutputParameters/haa:P_AIS_OUTPUT/haa:MESSAGE_NUMBER)}
    
  else ()
}

 
In my current project we use SOA Suite 12c and XQuery for mappings. A typical SOA Composite consist of a select on database tables using PL/SQL package/procedure and returning the data in PL/SQL types with a layered construction. When we produce an instance of the return type in the PL/SQL the data is inserted into the type. When a column is nillable and has a NULL value the field within the type is still instantiated and the field is returned by the database adapter, but it is empty / without a value. We ran into problems with our mappings because we checked if the element existed, instead of checking the actual content of the field, and mappings were not valid when validating based on the XSD, because some values of elements did not contain the right datatype/format.

Because this needed to be done in more than just one transformation we decided to invest in creating common XQuery functions. For example checking the values like zero-string length and non-valid integers.

declare function all-whitespace
  ( $arg as xs:string? )  as xs:boolean {

    normalize-space($arg) = ''
  } ;
declare function is-a-number
  ( $value as xs:anyAtomicType? )  as xs:boolean {

    string(number($value)) != 'NaN'
  } ;

 
But before you invest in creating your own library take a look into the library made by xqueryfunctions.com (FunctX). It contains a lot of function that can help you in your daily work. Just put the library, which you can download here, into a shared repository like the MDS and import it as a library into your existing XQuery transformation.

Import as XQuery Library

The FunctX library consists of 151 extra functions besides the 111 built-in XQuery functions. These functions are sorted in 10 different catagories like Strings, Numbers, Atomic Values of All Types, Sequences, XML Elements & Attributes and even a category for XML Namespaces. The most functions I use are for checking missing values, Trimming and Padding and Constructing and Converting dates.

Next Post

Book Review: Design Principles for Process-driven Architectures Using Oracle BPM and SOA Suite 12c (Packt, June 2015)

Facebook0TwitterLinkedinI recently came across an unexpected gem: this book titled “Design Principles for Process-driven Architectures Using Oracle BPM and SOA Suite 12c” by a collective of authors I know well and happily collaborate with: Torsten Winterberg, Mark Simpson, Guido Schmutz, Danilo Schmiedel, Hajo Normann, Sven Bernhardt, Matjaz B. Juric. The […]