Neat! Thanks Mike. Okay, so my example is: Suppose someone already created the XML and you want to truncate the name in the XML if the name length exceeds 15 characters. Use this to unparse the XML:
<xs:element name="personName" type="xs:string" dfdl:truncateSpecifiedLengthString="yes" dfdl:textStringJustification="left" dfdl:lengthKind="explicit" dfdl:length="15" dfdl:lengthUnits="characters" /> That works great! The output is: Wolfeschlegelst /Roger From: Beckerle, Mike <mbecke...@tresys.com> Sent: Tuesday, May 26, 2020 2:11 PM To: users@daffodil.apache.org Subject: [EXT] Re: How to use truncateSpecifiedLengthString? Ah, now I get it. The term "specified length" has a specific meaning in DFDL. It means dfdl:lengthKind is explicit, prefixed, or implicit. So, the length will come from the dfdl:length, or from the maxLength facet for an xs:string element. the dfdl:truncateSpecifiedLengthString is just a boolean that says to truncate it if its is too long, instead of erroring. Generally speaking this property is not needed if you are parsing, then unparsing data, because the data will already be of the expected length. The property is going to be needed largely if you are synthesizing data, e.g., converting data from some format A, to some format B, where B has max lengths for strings, but A does not. ________________________________ From: Roger L Costello <coste...@mitre.org<mailto:coste...@mitre.org>> Sent: Tuesday, May 26, 2020 12:59 PM To: users@daffodil.apache.org<mailto:users@daffodil.apache.org> <users@daffodil.apache.org<mailto:users@daffodil.apache.org>> Subject: Re: How to use truncateSpecifiedLengthString? Hi Mike, But, but, but, ... I am trying to illustrate the use of truncateSpecifiedLengthString. Look at what the spec says for truncateSpecifiedLengthString: Used on unparsing only. 'yes' means if the logical type is xs:string and the value (the parsed value?) is longer than the specified length (what specified length?), the string is truncated to this length (truncated on unparsing, right?). I interpreted that to mean the value resulting from parsing (Wolfeschlegelsteinhausenbergerdorff) could be truncated on unparsing. I read the spec and wondered, "Okay, on unparsing I can specify that I want the value truncated, but how do I specify the length at which truncation begins?" /Roger From: Beckerle, Mike <mbecke...@tresys.com<mailto:mbecke...@tresys.com>> Sent: Tuesday, May 26, 2020 12:49 PM To: users@daffodil.apache.org<mailto:users@daffodil.apache.org> Subject: [EXT] Re: How to use truncateSpecifiedLengthString? Typo . Should be "fn:substring(../personName, 1, 15)" ________________________________________ From: Beckerle, Mike <mailto:mbecke...@tresys.com> Sent: Tuesday, May 26, 2020 12:47 PM To: mailto:users@daffodil.apache.org <mailto:users@daffodil.apache.org> Subject: Re: How to use truncateSpecifiedLengthString? Interesting requirement. So you want it to accept when parsing any length but unparsing is not symmetric with that, it wants to truncate. Presumably this is delimited on parsing, so that it can accept all the characters at parse time. Hmmm. I think this is going to require you to use inputValueCalc and outputValueCalc. Something like this: <element name="storedName" type="xs:string" dfdl:outputValueCalc='{ fn:substring(../name, 1, 15) }' ... plus other properties .... /> <element name="personName" type="xs:string" dfdl:inputValueCalc='{ ../storedName }' /> ________________________________________ From: Roger L Costello <mailto:coste...@mitre.org> Sent: Tuesday, May 26, 2020 12:40 PM To: mailto:users@daffodil.apache.org <mailto:users@daffodil.apache.org> Subject: How to use truncateSpecifiedLengthString? Hi Folks, My input contains this person's last name: Wolfeschlegelsteinhausenbergerdorff I want parsing to generate: <personName>Wolfeschlegelsteinhausenbergerdorff</personName> I want unparsing to truncate the name after 15 characters. It would seem that I should use truncateSpecifiedLengthString="yes" to indicate that the name should be truncated. But how to specify that the name should be truncated after 15 characters? I cannot use length="15" because that would cause parsing to fail. /Roger