Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I display NcicCode matching VehicleMake (MncisCode)? 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
0
0
US
My xml document has /Integration/Case/Charge/Vehicle/VehicleMake/@Word where the @Word is the MncisCode that is found in the Mapping of the referring document and it should be matched to NcicCode in the Mapping.
I am not sure what to change on my xsl to loop through the Mapping looking for exact match between NcicCode and MncisCode.
If there is not an exact match between NcicCode and MncisCode then I need not display any code.
How do I do this?

Desired output
XML:
<ext:Vehicle>
	<j:VehicleMakeCode>MERC</j:VehicleMakeCode>
</ext:Vehicle>

sample xml document
XML:
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:IXML="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67092480" xmlns="">
	<Case Op="E" InternalID="1617090885" ID="12126951" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
		<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="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
		<CitationNumber>TLA060515C</CitationNumber>
		<TicketDate>06/05/2015</TicketDate>
		<Vehicle>
			<VehicleMake Word="MERC">Mercury</VehicleMake>
		</Vehicle>
	</Citation>
</Integration>

Sample referring xml document with the Mapping elements.
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>

My sample xslt code 1.0
Code:
<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>
 
Dear momo2000,

(Surely you must have a name!)

loop through the Mapping looking for exact match

This exhibits the procedural mindset that virtually every programmer has (including me). You must force yourself outside the box and think in declarative programming terms.

So, in this situation, don't think in terms of looping. Rather, think in terms of what matches the output I want.

As a housekeeping issue, I would declare global variables, suitably named, at the top of my stylesheet that 'compute' (declare?) the names for all my supporting documents (configuration files). So:
Code:
<xsl:stylesheet ...>
<xsl:output ...>
<xsl:variable name="vehicleMappingDocument" 
              select="concat($gEnvPath,'\ConfigFiles\VehicleMakeMapping.xml')"/>

I notice that Mncis is not unique, so I have restated the problem below. If this is wrong, please correct me. But if you are matching the Mncis code, how do you determine which NcicCode to output?

Now let's write
@Word is the MncisCode that is found in the Mapping of the referring document and it should be matched to NcicCode in the Mapping
in XPath, and let's do it in a manner that allows us to output a node containing MncisCode if, but only if, there is a match. I am assuming, based on your post, that the value of @Word is in the variable [tt]vVehicleMake[/tt].
Code:
<xsl:for-each select="document($vehicleMappingDocument)/VehicleMakeMapping/Mapping[NcicCode=$vVehicleMake]">
[indent]&lt;!-- we have now shifted context to the matching Mapping node -->
<ext:Vehicle>
	<j:VehicleMakeCode><xsl:value-of select="MncisCode"/></j:VehicleMakeCode>
</ext:Vehicle>[/indent]
</xsl:for-each> 
&lt;!-- back in the original context -->

Tom Morrison
Hill Country Software
 
Thanks Tom... this is now working. I will do more testing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top