|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Data Map (or Mapping Node) and fractional digits |
« View previous topic :: View next topic » |
Author |
Message
|
Gideon |
Posted: Wed Jan 21, 2015 11:54 am Post subject: Data Map (or Mapping Node) and fractional digits |
|
|
Chevalier
Joined: 18 Aug 2009 Posts: 403
|
I am using IIB 9.0.0.2
I am using the Data Map (similar to Mapping node) to convert two different structures
I am using XQuery generation, and my output format is as follows:
Code: |
<xs:simpleType name="Money">
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType> |
I perform a summation in XQuery, but I get the following output:
How can I tell the tool to only give me two fractional digits ? |
|
Back to top |
|
 |
martinb |
Posted: Wed Jan 21, 2015 11:52 pm Post subject: |
|
|
Master
Joined: 09 Nov 2006 Posts: 210 Location: UK
|
What you really want is for the Mapping node / Data Map to provide the XQuery/XPath 3.0 functions, that you could simply use "format-number".
Although you've only said you are using the Data Map to generate the XQuery from the Graphical Map, not where you are executing, so if you have a runtime that supports XQuery/XPath 3.0, go that way.
Otherwise if you execution runtime is XQuery 2.0, your options are to either call out to say Java and do the formatting there, or the following is one way to achieve this using XQuery/XPath 2.0 functions
Code: |
let $sum := xs:string(fn:sum($nums)) return
let $whole := fn:substring-before( $sum, '.') return
let $fac := fn:substring-after( $sum, '.') return
fn:concat( $whole, '.', fn:substring($fac,1,2) )
|
The above can be used in a Custom XPath transform in a Graphical Data Map, assuming "$nums" is the variable name given by content assist for a repeating set of decimal numbers |
|
Back to top |
|
 |
martinb |
Posted: Thu Jan 22, 2015 8:37 am Post subject: |
|
|
Master
Joined: 09 Nov 2006 Posts: 210 Location: UK
|
A far simpler solution, and more robust to my first response, is to use an XQuery 2 function I'd initially forgotten allows a precision parameter
fn:round-half-to-even( fn:sum($nums), 2) |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|