You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@daffodil.apache.org by Nestor Fernandez <ne...@chakray.co.uk> on 2022/03/04 09:25:42 UTC

parsing decimal fields from EDI file

Hi team,

We have a field in EDI which is decimal type, using "," as decimal
separator. Here are some examples this value can take:

18933
56,03
4500
10249
46,923
50
166116
264,187
72,2

Ideally, when parsing this field to xml, we would need to get these values
with a "." separator (and the other way round from xml to edi, if possible,
too):

18933
56.03
4500
10249
46.923
50
166116
264.187
72.2

Before considering XSLT for this specific task (a simple character
replacement would work for us), we are trying to achieve this with the same
dfdl file we use to parse the edi file.

According to some references on the internet, there would be some specific
ways to achieve this. One I tried and failed (throws errors) is:

<xsd:element name="MeasurementValue" minOccurs="0" type="xsd:decimal"
dfdl:textStandardDecimalSeparator="," />

Also we tried fiddling with some other params such as these and it didn't
work either.

dfdl:representation="text"
dfdl:encoding="UTF-8"
dfdl:textNumberRep ="standard"
dfdl:textStandardBase="10"
dfdl:textNumberPattern="#"
dfdl:textStandardDecimalSeparator=","
dfdl:lengthKind="delimited"

I specially tried to figure out and experiment with the textNumberPattern
from the documentation, as I don't see there is a clear pattern (something
like digit digit separator digit digit).

Could you please tell us if this is actually possible using only dfdl
schema attributes? And what would be the right approach? We are using
version 3.0.0.

Thank you in advance.

Re: parsing decimal fields from EDI file

Posted by Steve Lawrence <sl...@apache.org>.
Setting textStandardDecimalSeparator to a comma is the correct approach.

You may need to also set textStandardGroupingSeparator if you are using 
an older version of Daffodil. If that value is a comma (a common default 
value in schemas) then we may parse the commas as grouping separators 
instead of decimals since there is ambiguity if the comma should be a 
grouping or decimal separator. Newer versions of Daffodil detect when 
these properties are the same and error, but I think older versions did not.

If you set textStandardGroupingSeparator to something else (a common 
alternative is a period when the decimal separator is a comma), it may 
parse and unparse as expected.

- Steve


On 3/4/22 4:25 AM, Nestor Fernandez wrote:
> Hi team,
> 
> We have a field in EDI which is decimal type, using "," as decimal separator.
> Here are some examples this value can take:
> 
> 18933
> 56,03
> 4500
> 10249
> 46,923
> 50
> 166116
> 264,187
> 72,2
> 
> Ideally, when parsing this field to xml, we would need to get these values with
> a "." separator (and the other way round from xml to edi, if possible, too):
> 
> 18933
> 56.03
> 4500
> 10249
> 46.923
> 50
> 166116
> 264.187
> 72.2
> 
> Before considering XSLT for this specific task (a simple character replacement
> would work for us), we are trying to achieve this with the same dfdl file we use
> to parse the edi file.
> 
> According to some references on the internet, there would be some specific ways
> to achieve this. One I tried and failed (throws errors) is:
> 
> <xsd:element name="MeasurementValue" minOccurs="0" type="xsd:decimal"
> dfdl:textStandardDecimalSeparator="," />
> 
> Also we tried fiddling with some other params such as these and it didn't work
> either.
> 
> dfdl:representation="text"
> dfdl:encoding="UTF-8"
> dfdl:textNumberRep ="standard"
> dfdl:textStandardBase="10"
> dfdl:textNumberPattern="#"
> dfdl:textStandardDecimalSeparator=","
> dfdl:lengthKind="delimited"
> 
> I specially tried to figure out and experiment with the textNumberPattern from
> the documentation, as I don't see there is a clear pattern (something like digit
> digit separator digit digit).
> 
> Could you please tell us if this is actually possible using only dfdl schema
> attributes? And what would be the right approach? We are using version 3.0.0.
> 
> Thank you in advance.