I'm very new to XSLT, and have inherited what is to me a difficult problem. We recieve XML output from a third-party application that is transformed so that it can be used in a COBOL copybook.
It contains a translate function to reduce the size of the input to one character. The translation needs a 'when' so that if <coverage-type> = 'COVA' and <loss-type> = 'Flood' then it is translated to 'F', but if <coverage-type> = 'COVA' and <loss-type> is anything else it translates to 'A'.
I've looked all over the net and in several XSLT books and I can't find anything on a translate function in this format. I've made a try to insert a 'when', but it isn't working.
Error: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 247, position 24.
Saxon
Windows XP
Here's the original code snippet:
Code:
<CopyBookField>
<CopyBookName type="String">CWS-MAJOR-PERIL</CopyBookName>
<FieldValue type="String" />
<FieldType type="String">String</FieldType>
<FieldSize type="int">1</FieldSize>
<CopyBookPosition type="int">7</CopyBookPosition>
<NeedsTransformation type="boolean">true</NeedsTransformation>
<TransformationRule type="com.stoneriver.extract.entity.TranslationRule[]" Function="Translate">
<Rule From="COVA" To="A"/>
<Rule From="COVB" To="B"/>
<Rule From="COVC" To="C"/>
<Rule From="COVD" To="D"/>
<Rule From="COVE" To="E"/>
<Rule From="COVF" To="F"/>
</TransformationRule>
<Delegator type="String">XPATH</Delegator>
<XpathField type="String">sr:Coverage-Type</XpathField>
</CopyBookField>
Here's my attempt to add the needed 'when':
Code:
<CopyBookField>
<CopyBookName type="String">CWS-MAJOR-PERIL</CopyBookName>
<FieldValue type="String" />
<FieldType type="String">String</FieldType>
<FieldSize type="int">1</FieldSize>
<CopyBookPosition type="int">7</CopyBookPosition>
<NeedsTransformation type="boolean">true</NeedsTransformation>
<TransformationRule type="com.stoneriver.extract.entity.TranslationRule[]" Function="Translate">
<Rule From="COVA" To="
<xsl:choose>
<xsl:when test="@Coverage-Type='COVA'" and="@Loss-Type='Terrorism'">
"T"
</xsl:when>
<xsl:otherwise>
"A"
</xsl:otherwise>
</xsl:choose>"/>
<Rule From="COVB" To="B"/>
<Rule From="COVC" To="C"/>
<Rule From="COVD" To="D"/>
<Rule From="COVE" To="E"/>
<Rule From="COVF" To="F"/>
</TransformationRule>
<Delegator type="String">XPATH</Delegator>
<XpathField type="String">sr:Coverage-Type</XpathField>
</CopyBookField>
I appreciate any help.
Thanks,
JR