Thank you Mike! It worked and explanation is very clear.

Can dfdl:discriminator be used as an attribute of a xs:element or only as a 
xs:annotation?

> On Jun 18, 2020, at 4:11 PM, Beckerle, Mike <mbecke...@tresys.com> wrote:
> 
> To use a pattern to discriminate a choice, you would use a dfdl:discriminator 
> statement with testKind='pattern' on each branch of the choice. That 
> assertion is using a regex to look at the data stream, and fails if the data 
> stream at the current position doesn't start with a non-zero-length match of 
> the pattern.
> 
> E.g., something like:
> 
> <xs:choice>
>    <xs:sequence>
>       <xs:annotation><xs:appinfo ...>
>           <!-- Must begin with from 1 to 10 'a' characters -->
>           <dfdl:discriminator testKind="pattern">a{1,10}</dfdl:discriminator>
>       </xs:appinfo></xs:annotation>
>       ... rest of 'a's branch...
>    </xs:sequence>
>    <xs:sequence> 
>       <xs:annotation><xs:appinfo ...>
>           <!-- Must begin with from 1 to 10 'b' characters -->
>           <dfdl:discriminator testKind="pattern">b{1,10}</dfdl:discriminator>
>       </xs:appinfo></xs:annotation>
>       ... rest of 'b's branch...
>    </xs:sequence>
>    ... other branches ...
> </xs:choice>
> 
> Did that address your need? 
> 
> One detail is that the matching of the discriminator pattern isn't consuming 
> any data. When the branch is selected and parsing starts, you are still 
> looking at the start of the data, not after the pattern matched. An element 
> has to absorb these characters and then go on to parse the remainder of the 
> branch. Sometimes that's easy, sometimes a slightly different idea makes more 
> sense:
> 
> <xs:choice>
>    <xs:sequence>
>       <!-- 
>        element that matches the pattern. If there is no match this will be 
> zero-length string
>         --> 
>       <xs:element name="aaBranchTag" type="xs:string"
>             dfdl:lengthKind="pattern" dfdl:lengthPattern="a{1,10}"/>
>       <xs:annotation><xs:appinfo ...>
>           <!-- 
>              if the match contains 1 or more characters, this is the right 
> branch 
>            -->
>           <dfdl:discriminator>{ fn:string-length(./aaBranchTag) gt 0 
> }</dfdl:discriminator>
>       </xs:appinfo></xs:annotation>
>       ... rest of 'a's branch...starting from after the run of 'a's. 
>    </xs:sequence>
>    .... other branches work similarly ....
> </xs:choice>
>   
> 
> 
> 
>       
> From: Patrick Grandjean <p.r.grandj...@gmail.com 
> <mailto:p.r.grandj...@gmail.com>>
> Sent: Thursday, June 18, 2020 3:28 PM
> To: users@daffodil.apache.org <mailto:users@daffodil.apache.org> 
> <users@daffodil.apache.org <mailto:users@daffodil.apache.org>>
> Subject: dfdl:choiceDispatchKey
>  
> Hi!
> 
> I recently started using dfdl:choiceDispatchKey. According to the 
> documentation, it only accepts DFDL expressions. Is it possible to use DFDL 
> regular expressions instead? Or is there an alternative that would accept 
> regexes?
> 
> Patrick.

Reply via email to