INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I display NcicCode matching VehicleMake (MncisCode)?

How do I display NcicCode matching VehicleMake (MncisCode)?

How do I display NcicCode matching VehicleMake (MncisCode)?

(OP)
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

CODE --> xml

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

sample xml document

CODE --> 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> 

Sample referring xml document with the Mapping elements.

CODE --> 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 --> xsl

<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> 

RE: How do I display NcicCode matching VehicleMake (MncisCode)?

Dear momo2000,

(Surely you must have a name!)

Quote:

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 --> XSLT

<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

Quote:

@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 vVehicleMake.

CODE --> XSLT

<xsl:for-each select="document($vehicleMappingDocument)/VehicleMakeMapping/Mapping[NcicCode=$vVehicleMake]">
<!-- we have now shifted context to the matching Mapping node --> <ext:Vehicle> <j:VehicleMakeCode><xsl:value-of select="MncisCode"/></j:VehicleMakeCode> </ext:Vehicle>
</xsl:for-each> <!-- back in the original context -->

Tom Morrison
Hill Country Software

RE: How do I display NcicCode matching VehicleMake (MncisCode)?

(OP)
Thanks Tom... this is now working. I will do more testing.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close