Hello DFDL community,
My input file contains an unsigned integer that represents the name of a
machine (CPU). I want to output that raw integer plus the name of the machine
that it corresponds to plus a description, e.g.,
<machine>
<raw_value>3</raw_value>
<constant>IMAGE_FILE_MACHINE_ARM</constant>
<description>ARM</description>
</machine>
I know how to implement this using inputValueCalc. See below. Is there is
another way to implement it, using xs:enumeration? Somehow, it would be really
neat if the element declaration for the <constant> element could use
xs:enumeration to enumerate its allowable values:
<xs:element name="constant">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="IMAGE_FILE_MACHINE_UNKNOWN" />
<xs:enumeration value="IMAGE_FILE_MACHINE_AM33" />
<xs:enumeration value="IMAGE_FILE_MACHINE_AMD64" />
<xs:enumeration value="IMAGE_FILE_MACHINE_ARM" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Somehow, each enumeration value would then be correlated to a specific value of
the <raw_value> element.
Is there a way to express this? That is, is there some way to leverage the XML
Scheme enumeration facet to enumerate the list of allowable values of the
<constant> element (as opposed to, essentially, using XPath the list the
allowable values)? /Roger
<xs:element name="machine">
<xs:complexType>
<xs:sequence>
<xs:element name="raw_value" type="xs:integer" />
<xs:element name="constant" type="xs:string" dfdl:inputValueCalc="{
if (../raw_value eq 0) then 'IMAGE_FILE_MACHINE_UNKNOWN'
else if (../raw_value eq 1) then 'IMAGE_FILE_MACHINE_AM33'
else if (../raw_value eq 2) then 'IMAGE_FILE_MACHINE_AMD64'
else if (../raw_value eq 3) then 'IMAGE_FILE_MACHINE_ARM'
else fn:error()
}"/>
<xs:element name="description" type="xs:string"
dfdl:inputValueCalc="{
if (../raw_value eq 0) then 'The contents of this field are
assumed to be applicable to any machine type'
else if (../raw_value eq 1) then 'Matsushita AM33'
else if (../raw_value eq 2) then 'x64'
else if (../raw_value eq 3) then 'ARM'
else fn:error()
}"/>
</xs:sequence>
</xs:complexType>
</xs:element>