Hi Steve, Is this the rule: To indicate a _string_ value in an XPath expression, wrap the value within quotes (either single quotes or double quotes). If the value is not within an XPath expression, then do not wrap the value within quotes.
Is that correct? /Roger -----Original Message----- From: Steve Lawrence <[email protected]> Sent: Friday, June 7, 2019 11:49 AM To: [email protected] Subject: [EXT] Re: A choiceBranchKey that specifies multiple value? The choiceDirectDispatchKey is a DFDL expression. In order to return a string value from an expression, you need to wrap it in quotes, otherwise it looks like a path. For example, in this expression: { rounded } There are no quotes, so it looks like a path, and so will return the value of the infoset element with name "rounded". On the otherhand, when there are quotes like this expression: { 'rounded' } That will returns the literal string "rounded", but without the quotes. So when we compare the value against choice branch key, were compare against the string value without quotes. On 6/7/19 11:35 AM, Costello, Roger L. wrote: > Steve wrote: > > 2) Have a more complex dispatch expression, something like: > > dfdl:choiceDispatchKey="{ > > if (./num eq 1) then 'rounded' > > else if (./num eq 2) then 'square' > > else 'none' }" > > And change your choiceBranchKeys to "rounded", "square", and "none". > > Wow! > > I really like that solution. > > I implemented it and it works great. But it raises a question. Here is > the DFDL > schema: > > <xs:elementname="input"> > <xs:complexType> > <xs:sequencedfdl:separator="%NL;"dfdl:separatorPosition="infix"> > <xs:elementname="num"type="xs:integer"/> > <xs:choicedfdl:choiceDispatchKey="{ if (./num eq 1) then 'rounded' > else if (./num eq 2) then 'square' else 'none' }"> > <xs:elementname="A"type="xs:string" > dfdl:initiator="("dfdl:terminator=")" > dfdl:choiceBranchKey="rounded"/> > <xs:elementname="B"type="xs:string" > dfdl:initiator="["dfdl:terminator="]" > dfdl:choiceBranchKey="square"/> > <xs:elementname="C"type="xs:string" > dfdl:initiator="%WSP*;"dfdl:terminator="%NL;" > dfdl:choiceBranchKey="none"/> </xs:choice> > </xs:sequence> </xs:complexType> </xs:element> > > Notice that there are quotes around round, square, and none in the > expression for dfdl:choiceDispatchKey but there are no quotes around > them in dfdl:choiceBranchKey. I initially did this: > > dfdl:choiceBranchKey=" 'rounded' " > > Notice the single quotes within the double quotes. That resulted in an error. > > Why don't I need those single quotes to indicate that we are matching > to a _/string/_? > > /Roger > > -----Original Message----- > From: Steve Lawrence <[email protected]> > Sent: Friday, June 7, 2019 10:47 AM > To: [email protected] > Subject: [EXT] Re: A choiceBranchKey that specifies multiple value? > > A few ways to handle this: > > 1) Daffodil has an extension to allow a space separated list of > choiceBranchKeys, so if you know all the keys for the third branch you can do > this: > > dfdl:choiceBranchKey="3 4 5 6" > > But if you need it to be portable to other DFDL implementations (e.g. > > IBM), or if you need something more generic (e.g. all nums greater > than > > 3 should have no parents) then you need to go a different route. > > 2) Have a more complex dispatch expression, something like: > > dfdl:choiceDispatchKey="{ > > if (./num eq 1) then 'rounded' > > else if (./num eq 2) then 'square' > > else 'none' }" > > And change your choiceBranchKeys to "rounded", "square", and "none". > > This works well if there aren't too many different keys/branches, but > if there are, then the if else expression can get pretty complicated, > so we sometimes use the next alternative. > > 3) Nested choices act sort of like a default if the dispatch doesn't match > anything: > > <xs:choice> > > <xs:choice dfdl:choiceDispatchKey="{ ./num }"> > > <xs:element name="A" dfdl:choiceBranchKey="1" ... /> > > <xs:element name="B" dfdl:choiceBranchKey="2" ... /> > > </xs:choice> > > <xs:element name="C" ... /> > > </xs:choice> > > So we first try the first branch of the outer choice, which is a > choice dispatch. If the dispatch key doesn't match any of the branch > keys, then we try the second branch of the outer choice. Which in this > case is our element C with no parens. > > On 6/7/19 10:28 AM, Costello, Roger L. wrote: > > > Hello DFDL community, > > > > > > My input file has a number (num), followed by a comma-separated > pair > > > of values, enclosed within either round parentheses, square > parentheses, or no parentheses. > > > > > > * If num=1 then the initiator and terminator are rounded parentheses. > > > * If num=2 then the initiator and terminator are square parentheses. > > > * If num=3, 4, 5, ... then there is no parentheses. > > > > > > The below DFDL schema works for num=1, num=2, and num=3. But it is > > > silent on other values of num (4, 5, ...). Is there a way to have a > > > choiceBranchKey for multiple values, e.g., > > > > > > dfdl:choiceBranchKey="3...infinity" > > > > > > <xs:element name="input"> > > > <xs:complexType> > > > <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix"> > > > <xs:element name="num" type="xs:integer" /> > > > <xs:choice dfdl:choiceDispatchKey="{ ./num }"> > > > <xs:element name="A" type="xs:string" > > > dfdl:initiator="(" dfdl:terminator=")" > > > dfdl:choiceBranchKey="1" /> > > > <xs:element name="B" type="xs:string" > > > dfdl:initiator="[" dfdl:terminator="]" > > > dfdl:choiceBranchKey="2" /> > > > <xs:element name="C" type="xs:string" > > > dfdl:initiator="%WSP*;" > dfdl:terminator="%NL;" > > > dfdl:choiceBranchKey="3" /> > > > </xs:choice> > > > </xs:sequence> > > > </xs:complexType> > > > </xs:element> > > > >
