I personally love this concept when applied to XQuery. This just gives you the power to write a function that can accept any argument or write functionality irrespective or independent of the input. The buzz word is “typeswitch”. This is the most important function that is used now-a-days for XML transformation for system integration keeping the core functionality outside of the transformation.
Let’s have a look at simple transformation.
In the above example, I can just keep on adding any handlers to the transformation main function as per by input structure irrespective of the data type and maintain the mapping of the attributes separately. This is very efficient when the same number of attributes are required by different target modules/system in different format.
If we run the above example, the first (input) gets transformed to (second) output.
You can download the complete XQuery main module to test from here.