Mark, I agree with Steve there must be a bug here.
Closest thing I can find to what you are trying to do does compute terminators, but the bug appears to be related to fn:exists and unparsing, which is a very subtle thing. fn:exists can't proceed and answer true/false until it can be shown not only that the element is or is not (at that time) present in the infoset, but must wait until it knows whether or not it will ever be added to the infoset. So the fn:exists has to wait until the element of interest gets attached to the infoset, or it has to wait for the following end-element event. Pretty tricky stuff, the way this suspend/resume stuff works in the unparser. That said. No excuses. It should work. Here's the closest similar thing I could find, which like your example, computes optional terminators. This is from mil-std-2045 schema, which is on github. It's used for a specific string type, where if the string is of max length (32), then there is no terminator. The terminator is only present if the string is shorter than its max length. Doesn't use fn:exists() though. But notice that the terminator is on a subsequent sequence which carries nothing but the terminator. It is not on the 'value' element itself. That feels like it may have been a workaround, though it may no longer be needed. (This is from a pretty old schema, still in heavy use, but dates from back in Daffodil v1.0.0 days.) <xs:group name="tString32"> <xs:sequence> <xs:element name="value" type="xs:string" dfdl:lengthKind="pattern" dfdl:lengthPattern="[^\x7F]{0,31}(?=\x7F)|.{32}" /> <xs:sequence dfdl:terminator="{if (fn:string-length(./value) eq 32) then '%ES;' else '%DEL;'}" /> </xs:sequence> </xs:group> On Mon, Feb 7, 2022 at 9:57 AM Steve Lawrence <slawre...@apache.org> wrote: > I think this is a bug in Daffodil. I think what you have should work. > I've created DAFFODIL-2648 to track this issue and provide a more > minimal example that reproduces the issue. > > https://issues.apache.org/jira/browse/DAFFODIL-2648 > > Unfortunately, I can't come up with a workaround, without perhaps > changing how terminators are described in your schema. We'd probably > need more information about your format to know what might work. > > > On 2/4/22 7:15 PM, Thompson, Mark M [US] (DS) wrote: > > Newby alert: > > > > I am attempting to define a terminator string for one element based on > the > > existence/non--existence of a prior element. > > > > - When the element exists, I get what I want. > > > > - When the element does not exist, I get the following from Daffodil > during unparse: > > > > [error] Unparse Error: Expression Evaluation Error: Child element > > legacy:FmtLine12-BodyLineNoEOL does not exist. > > > > Prior element example (with BodyLineNoEOLelement): > > > > <legacy:FmtLine7-12> > > > > <legacy:FL11_BT>BT</legacy:FL11_BT> > > > > <legacy:FmtLine12-ClassLine>C O N F I D E N T I A > > L</legacy:FmtLine12-ClassLine> > > > > <legacy:FmtLine12-DelimiterLine> > > > > <legacy:FL12SubjLine>SUBJ: TEST MSG - FL11/FL13 > > BT</legacy:FL12SubjLine> > > > > </legacy:FmtLine12-DelimiterLine> > > > > <legacy:FmtLine12-BodyLine>Just some random > > junk.</legacy:FmtLine12-BodyLine> > > > > <legacy:FmtLine12-BodyLine>More > stuff.</legacy:FmtLine12-BodyLine> > > > > <legacy:FmtLine12-BodyLine>That's all > > folks.</legacy:FmtLine12-BodyLine> > > > > <legacy:FmtLine12-BodyLineNoEOL > xsi:nil="true"></legacy:FmtLine12-BodyLineNoEOL> > > > > </legacy:FmtLine7-12> > > > > <legacy:FL12_LastEOL></legacy:FL12_LastEOL> > > > > Schema definition for FL12_LastEOL > > > > <xs:elementname="FL12_LastEOL"type="xs:string"minOccurs="0"maxOccurs="1" > > > > dfdl:terminator="{if > > (fn:exists(../legacy:FmtLine7-12/legacy:FmtLine12-BodyLineNoEOL)) then > '%ES;' > > else '%LF; %CR;%CR;%LF; %CR;%LF; %ES;'}" > > > > dfdl:lengthKind="pattern"dfdl:lengthPattern="(\n);"/> > > > > My expectation is that when BodyLineNoEOL does not > exist, the > > terminator will use the else string. > > > > What am I missing? > > > > Thank you for your time, > > > > Mark T > > > > -----Original Message----- > > From: Roger L Costello <coste...@mitre.org> > > Sent: Thursday, February 3, 2022 4:46 AM > > To: users@daffodil.apache.org > > Subject: EXT :Writing DFDL schemas for processing data from Europe? > Better know > > how to express monetary values > > > > USA uses the $ symbol. Finland uses EUR. > > > > USA places the $ symbol before the number. Finland places EUR after the > number. > > > > USA doesn't use a space between the $ symbol and the number. Finland > uses a > > space between the number and EUR. > > > > USA uses the decimal point symbol. Finland uses the comma symbol. > > > > USA separates groups of three digits using a comma. Finland uses a space. > > > > Example: > > > > USA Finland > > > > $7,593.86 7 593,86 EUR > > > > For negative quantities, USA puts a dash symbol immediately before the $ > symbol. > > Finland uses a dash then space. > > > > Example: > > > > USA Finland > > > > -$7,593.86 - 7 593,86 > > > > For international monetary values, USA precedes the number with USD and > space > > (omits the $ symbol). Finland makes no change. > > > > Example: > > > > USA Finland > > > > USD 7,593.86 7 593,86 EUR > > > > For negative international monetary values, USA precedes USA with a dash > symbol > > (no space after the dash symbol). Finland makes no change. > > > > Example: > > > > USA Finland > > > > -USD 7,593.86 - 7 593,86 EUR > > > >