2015-06-09 40 views
0

我有一個帶有<VehicleMake Word="MERC">Mercury</VehicleMake>元素的xml文檔。我想將它與<NcicCode>MERC</NcicCode>代碼相匹配。 我的輸出僅顯示匹配<MncisCode>的第一個<NcicCode>。引用文檔中的<MncisCode>與我的xml文檔中的<VehicleMakeCode>代碼相同。如何顯示匹配VehicleMake(MncisCode)的NcicCode?

電流輸出

<ext:Vehicle> <j:VehicleMakeCode>MERB</j:VehicleMakeCode> </ext:Vehicle>

希望的輸出應爲NcicCode = MncisCode

<ext:Vehicle> <j:VehicleMakeCode>MERC</j:VehicleMakeCode> </ext:Vehicle>

我的示例XML文檔

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67092480" xmlns=""> 
    <Case Op="E" InternalID="1617090885" ID="12126951" xmlns:user="http://tylertechnologies.com"> 
     <Charge ID="10906495" PartyID="1466236" InternalChargeID="1616714163" InternalPartyID="704451330" xmlns:reslib="urn:reslib"> 
      <ChargeOffenseDate>06/05/2015</ChargeOffenseDate> 
      <Vehicle> 
       <VehicleMake Word="MERC">Mercury</VehicleMake> 
      </Vehicle> 
     </Charge> 
    </Case> 
    <Citation ID="5385632" xmlns:user="http://tylertechnologies.com"> 
     <CitationNumber>TLA060515C</CitationNumber> 
     <TicketDate>06/05/2015</TicketDate> 
     <Vehicle> 
      <VehicleMake Word="MERC">Mercury</VehicleMake> 
     </Vehicle> 
    </Citation> 
</Integration> 

我的樣品指XML文檔

<?xml version="1.0" encoding="UTF-8"?> 
<VehicleMakeMapping> 
    <Mapping> 
     <NcicCode>MERB</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Mercury Boat Co.</Description> 
    </Mapping> 
    <Mapping> 
     <NcicCode>MERC</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Mercury</Description> 
    </Mapping> 
    <Mapping> 
     <NcicCode>MERH</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Mercury Coach Corp.</Description> 
    </Mapping> 
    <Mapping> 
     <NcicCode>MERR</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Mercury Trailer Industries</Description> 
    </Mapping> 
    <Mapping> 
     <NcicCode>METE</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Meteor (Canadian Mercury)</Description> 
    </Mapping> 
    <Mapping> 
     <NcicCode>MRCU</NcicCode> 
     <MncisCode>MERC</MncisCode> 
     <Description>Mercury (See Mercury Marine)</Description> 
    </Mapping> 
</VehicleMakeMapping> 

我的示例XSLT代碼

<j:VehicleMakeCode> 
     <xsl:variable name="vVehicleMakeCode" select="document(concat($gEnvPath,'\ConfigFiles\VehicleMakeMapping.xml'))/VehicleMakeMapping/Mapping[MncisCode=$vVehicleMake]/NcicCode"/> 
     <xsl:value-of select="$vVehicleMakeCode"/> 
</j:VehicleMakeCode> 
+0

在示例文檔,所有的'Mapping'元素具有相同的'MncisCode',所以怎麼會知道匹配哪一個?謝謝! –

+0

這個問題與以前的問題有何不同:http://stackoverflow.com/questions/30127613/how-do-i-convert-ncic-code-value-to-dccis-code-value-for-vehicle-使? –

+0

業務分析師表示(也使用'VehicleMake'描述)他們想要的。VehicleMake返回值將基於MNCIS代碼。 NCIC代碼沒有與MNCIS中使用的車輛代碼相匹配的代碼。當XML中的結果包括VehicleMake時,請將該值從MNCIS值轉換爲VehicleMake Mapping文檔中的匹配NCIC值。如果爲MNCIS代碼找到多個NCIC代碼,請查找完全匹配並填充,否則請跳過此元素。 如果沒有爲MNCIS代碼找到NCIC代碼,請跳過填充該元素。 – Angela

回答

0

您必須添加Description也比較節點在您的謂語。我猜是這樣的:

<xsl:variable name="vVehicleMakeCode" select="document(concat($gEnvPath,'\ConfigFiles\VehicleMakeMapping.xml'))/VehicleMakeMapping/Mapping[MncisCode=$vVehicleMake and Description=$vVehicleMakeContent]/NcicCode"/> 

你必須映射$vVehicleMakeContent到目標節點的內容。

編輯

試試這個來代替:

<xsl:variable name="vVehicleMakeCode" select="document(concat($gEnvPath,'\ConfigFiles\VehicleMakeMapping.xml'))/VehicleMakeMapping/Mapping[MncisCode=$vVehicleMake and MncisCode=NcicCode]/NcicCode"/> 
+0

商界人士告訴我,要找到'/ Integration/Case/Charge/Vehicle/VehicleMake/@ Word'代碼和'NcicCode'之間的完全匹配。如果找不到匹配,那麼我需要跳過它,即不顯示它。因此,在我的情況下,基於我的xml文件,輸出應該是這樣的' MERC '因爲'MERC'匹配'NcicCode'和'MncisCode' – Angela

+0

喬爾,業務分析師問我在'NcicCode'和'MncisCode'之間找到精確匹配時不要使用描述。所以我不確定要在xsl上改變什麼來循環查找'NcicCode'和'MncisCode'之間的'Mapping'循環。xml文檔具有'/ Integration/Case/Charge/Vehicle/VehicleMake/@ Word' '@ Word'是'MncisCode',我需要在'Mapping'文件中與'NcicCode'匹配。如果'NcicCode'和'MncisCode'之間沒有完全匹配,那麼我不需要顯示代碼。我該怎麼做呢? – Angela