Hi Folks, I have a one-byte binary input file. If the input is 0 then I want the XML output to be "No Signal". If the input is 1 then I want the output to be "Green". If the input is 2 then I want the output to be "Yellow". If the input if 3 then I want the output to be "Red". For all other inputs, generate an error.
<xs:sequence dfdl:hiddenGroupRef="raw_Signal" /> <xs:element name='Signal' type='xs:string' dfdl:inputValueCalc='{ if (../binary_Signal eq 0) then "No Signal" else if (../binary_Signal eq 1) then "Green" else if (../binary_Signal eq 2) then "Yellow" else if (../binary_Signal eq 3) then "Red" else "Error" }' /> <xs:group name="raw_Signal"> <xs:sequence> <xs:element name="binary_Signal" type="unsignedint2" dfdl:outputValueCalc='{ if (../Signal eq "No Signal") then 0 else if (../Signal eq "Green") then 1 else if (../Signal eq "Yellow") then 2 else if (../Signal eq "Red") then 3 else "daf:error()" }' /> </xs:sequence> </xs:group> That results in Daffodil generating this error message: Error: If-expression branches must have similar types, but were int and string What am I doing wrong? Below is the entire DFDL schema. /Roger <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xs:annotation> <xs:appinfo source="http://www.ogf.org/dfdl/"> <dfdl:format alignment="1" alignmentUnits="bits" binaryFloatRep="ieee" binaryNumberRep="binary" bitOrder="leastSignificantBitFirst" byteOrder="littleEndian" calendarPatternKind="implicit" choiceLengthKind="implicit" documentFinalTerminatorCanBeMissing="yes" emptyValueDelimiterPolicy="none" encoding="ISO-8859-1" encodingErrorPolicy="replace" escapeSchemeRef="" fillByte="f" floating="no" ignoreCase="no" initiatedContent="no" initiator="" leadingSkip="0" lengthKind="implicit" lengthUnits="bits" nilKind="literalValue" nilValueDelimiterPolicy="none" occursCountKind="implicit" outputNewLine="%CR;%LF;" representation="binary" separator="" separatorPosition="infix" separatorSuppressionPolicy="anyEmpty" sequenceKind="ordered" textStandardZeroRep="0" textStandardDecimalSeparator="." textStandardInfinityRep="Inf" textStandardExponentRep="E" textStandardNaNRep="NaN" textNumberPattern="#,##0.###;-#,##0.###" textNumberRounding="explicit" textNumberRoundingMode="roundUnnecessary" textNumberRoundingIncrement="0" textStandardGroupingSeparator="," terminator="" textBidi="no" textNumberCheckPolicy="strict" textNumberRep="standard" textOutputMinLength="0" textPadKind="none" textStandardBase="10" textTrimKind="none" trailingSkip="0" truncateSpecifiedLengthString="no" utf16Width="fixed"/> </xs:appinfo> </xs:annotation> <xs:element name="Test"> <xs:complexType> <xs:sequence> <xs:element name="Segment"> <xs:complexType> <xs:sequence> <xs:sequence dfdl:hiddenGroupRef="raw_Signal" /> <xs:element name='Signal' type='xs:string' dfdl:inputValueCalc='{ if (../binary_Signal eq 0) then "No Signal" else if (../binary_Signal eq 1) then "Green" else if (../binary_Signal eq 2) then "Yellow" else if (../binary_Signal eq 3) then "Red" else "Error" }' /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:group name="raw_Signal"> <xs:sequence> <xs:element name="binary_Signal" type="unsignedint2" dfdl:outputValueCalc='{ if (../Signal eq "No Signal") then 0 else if (../Signal eq "Green") then 1 else if (../Signal eq "Yellow") then 2 else if (../Signal eq "Red") then 3 else "daf:error()" }' /> </xs:sequence> </xs:group> <xs:simpleType name="unsignedint2" dfdl:length="2" dfdl:lengthKind="explicit"> <xs:restriction base="xs:unsignedInt"/> </xs:simpleType> </xs:schema>