Oracle never ceases to amaze me. I recently saw this question being asked again on stackoverflow.
xdofx:to_check_number.
It is documented over here. The function can print the output text in different locales, and decimal number settings. But the number to be printed has to be in an XML node. It only accepts simple XPATH notations, and the value itself cannot be a result of a sum() function, or the result of any mathematical operation.
Which means, if you have an XML like this:
<root><amt>3243243</amt>
<amt>6436464</amt>
<amt>243</amt>
<amt>445454</amt>
<amt>67676</amt>
</root>
And you want to print the output as the sum of all the 'amt' elements, that cannot be done.
<?xdofx:to_check_number(sum(amt),'EUR')?>
Outputs:
Zero and xx/100
Which leads me to say: WTF Oracle ?
I had solved this problem years ago, but I couldn't remeber how. So I deep dived, again, into the same problem.
Using the RTF template, I exported the XSL-FO stylesheet out:
This extracts the intermediate XSL file BIP uses to generate the final report output.
Search for "to_check_number" in this XSL:
It can be seen that although there is a for-each loop there, the template itself is not called recursively. It access the element 'amt' without a proper XPATH, and then does a stupid (.///)[1] whatever that means.
But if you pass a string with the number into the function to_check_number, this works out perfectly.
For the foe-each loop to sum up all the values, it has to call itself recursively. Obviously, this function is broken.
But is there a way to fix this ?
Turns out, there is. Look two lines lower in the XSL file.
It can be seen that the XSL finally invokes another hidden function xdoxslt:toCheckNumber. This namespace is unique, I am guessing it is shared between the XSL and XDO name spaces.
So I tried using this 'hidden' function directly in the template.
Like this:
<?xdoxslt:toCheckNumber($_XDOLOCALE, sum(amt), ('EUR'))?>
Which produces the output:
Voila !!
So in case you have to convert a dynamically generated number to text, use the toCheckNumber function directly.
Which leads to the question, why have the xdo function in the first place ?
But do bear in mind, that this is an undocumented function, which works for now.
Good blog, thanks for sharing this information.
ReplyDeleteOracle Fusion HCM Online Training
Hi, excellent blog, but I am actually having a problem with this function, since when a value like 1267500000 is passed to the function, it does not return the value in words but the same value.
ReplyDeleteDo you know if this function has some kind of limit in the size of the value that it can take?