How do I convert NCIC code value to DCCIS code value for vehicle make?

前端 未结 2 906
日久生厌
日久生厌 2021-01-26 12:09

The business analyst told business rule for this has changed. Now they want me to first check (count) to see if there are more than one NcicCode (in the VehicleMakeMapping looku

相关标签:
2条回答
  • 2021-01-26 12:17

    If there are more than one NcicCode in the VehicleMakeMapping lookup document, then just use the first NcicCode as the output.

    To simplify the question, let us have:

    XML

    <root>
        <Vehicle>
            <VehicleMake Word="ABC">not important</VehicleMake>
        </Vehicle>
        <Vehicle>
            <VehicleMake Word="XYZ">not important</VehicleMake>
        </Vehicle>
    </root>
    

    VehicleMakeMapping.xml

    <VehicleMakeMapping>
        <Mapping>
            <NcicCode>ABCA</NcicCode>
            <MncisCode>ABC</MncisCode>
            <Description>abc</Description>
        </Mapping>
        <Mapping>
            <NcicCode>ABCB</NcicCode>
            <MncisCode>ABC</MncisCode>
            <Description>abc abc</Description>
        </Mapping>
        <Mapping>
            <NcicCode>ABCC</NcicCode>
            <MncisCode>ABC</MncisCode>
            <Description>abc abc abc</Description>
        </Mapping>  
    </VehicleMakeMapping>
    

    XSLT 2.0

    <xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:param name="map-doc" select="'path/to/VehicleMakeMapping.xml'"/>
    
    <xsl:key name="mapping" match="Mapping" use="MncisCode" />
    
    <xsl:template match="/root">
        <xsl:copy>
            <xsl:apply-templates select="Vehicle"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="Vehicle">
        <Vehicle>
            <VehicleMakeCode>
                <xsl:value-of select="key('mapping', VehicleMake/@Word, document($map-doc))[1]/NcicCode"/>                     
            </VehicleMakeCode>
        </Vehicle>
    </xsl:template>
    
    </xsl:stylesheet>
    

    Result

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <Vehicle>
          <VehicleMakeCode>ABCA</VehicleMakeCode>
       </Vehicle>
       <Vehicle>
          <VehicleMakeCode/>
       </Vehicle>
    </root>
    
    0 讨论(0)
  • 2021-01-26 12:40

    Here is the solution for my question.

    <j:VehicleMakeCode>
                <xsl:variable name="vVehicleMake">
                    <xsl:value-of select="../Vehicle/VehicleMake/@Word"/>
                </xsl:variable>
                <xsl:variable name="vVehicleMakeCode" select="document(concat($gEnvPath,'\ConfigFiles\VehicleMakeMapping.xml'))/VehicleMakeMapping/Mapping[MncisCode=$vVehicleMake]/NcicCode"/>
                <xsl:value-of select="$vVehicleMakeCode"/>
            </j:VehicleMakeCode>
    
    0 讨论(0)
提交回复
热议问题