Hi Folks,
Per Brandon's (excellent) suggestion, I added an assertion on each record
element to test that it contains the same number of field elements as the first
record. See below. Notice that I have a choice to deal with the case where the
CSV file does and doesn't have a header. Notice in the second branch of the
choice I have two assertions - is it legal to have multiple assertions? When I
run my schema I get this error message:
[warning] Schema Definition Warning: Statically ambiguous or query-style paths
not supported in step path: '{}record'.
What does that mean? How to fix it? /Roger
<xs:element name="csv">
<xs:complexType>
<xs:sequence>
<xs:choice dfdl:choiceDispatchKey="{$header}">
<xs:sequence dfdl:choiceBranchKey="present">
<xs:sequence dfdl:separator="%NL;"
dfdl:separatorPosition="infix">
<xs:element name="header" type="headerType" />
<xs:element name="record" type="recordType"
maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:assert test="{ fn:count(field) eq
fn:count(../header/title) }"
message="{'Each record should contain
the same number of fields as the header.'}" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:sequence>
<xs:sequence dfdl:choiceBranchKey="absent">
<xs:sequence dfdl:separator="%NL;"
dfdl:separatorPosition="infix">
<xs:element name="record" type="recordType"
maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:assert test="{ fn:count(field) eq
fn:count(../record[1]/field) }"
message="{'Each record should contain
the same number of fields.'}" />
<dfdl:assert testKind="pattern"
testPattern="."
message="{'If the last record is empty,
then no fields should be generated'}" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:choice>
<xs:sequence dfdl:hiddenGroupRef="hidden-newline" />
</xs:sequence>
</xs:complexType>
</xs:element>