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 CommercialVehicleFlag? 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
0
0
US
I have modified this question by adding a more detailed xsl code showing two templates that I am using. CommercialVehicleFlag can be under Charge which is under Case or under Citation which is under Case.
I want to check for CommercialVehicleFlag in both places that is under /Integration/Case/Charge/Vehicle/VehicleLicensePlateNumber and /Integration/Citation/Vehicle/CommercialVehicleFlag in xml document.
Do I use for each statement if a if statement to check before selecting the value of?

My xsl is only working for VehicleLicensePlateNumber in this xpath
XML:
/Integration/Case/Charge/Vehicle/VehicleLicensePlateNumber

and failing this xpath
XML:
/Integration/Citation/Vehicle/CommercialVehicleFlag

In my xsl I need to check for both paths. How do I do this?

xml document with CommercialVehicleFlag under Charge

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="67084884" xmlns="">
	<Case Op="E" InternalID="1617090736" ID="12125870" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
		<CaseNumber>55</CaseNumber>
		<Charge ID="10906336" PartyID="16770378" InternalChargeID="1616713996" InternalPartyID="1614673416" xmlns:reslib="urn:reslib">
			<ChargeOffenseDate>05/28/2015</ChargeOffenseDate>
			<Vehicle>
				<VehicleLicensePlateState>MM</VehicleLicensePlateState>
				<VehicleLicensePlateNumber>ASD123</VehicleLicensePlateNumber>
				<VehicleMake Word="JEEP">Jeep</VehicleMake>
				<CommercialVehicleFlag>false</CommercialVehicleFlag>
				<HazardousVehicleFlag>false</HazardousVehicleFlag>
			</Vehicle>
		</Charge>
	</Case>
</Integration>


xml document with CommercialVehicleFlag under Citation

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="67086833" xmlns="">
	<Citation ID="5380737" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
		<CitationNumber>33</CitationNumber>
		<TicketDate>12/25/2014</TicketDate>
		<Vehicle>
			<CommercialVehicleFlag>false</CommercialVehicleFlag>
			<HazardousVehicleFlag>false</HazardousVehicleFlag>
		</Vehicle>
	</Citation>
</Integration>

My xsl code which is only displaying CommercialVehicleFlag under Charge and not under Citation

Code:
My xsl code which is only displaying CommercialVehicleFlag under Charge and not under Citation
<!--Template for ext:Charge-->
    <xsl:template name="Charge">
        <ext:Charge>
            <xsl:choose>
                <xsl:when test="(count(ChargeHistory[@Stage='Disposition Event']))>0">
                    <xsl:for-each select="ChargeHistory[@Stage='Disposition Event']">
                        <xsl:sort select="@DispositionEventSequence" data-type="number" order="descending"/>
                        <xsl:if test="position()=1">
                            <xsl:call-template name="ChargeDetails"/>
                        </xsl:if>
                    </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:for-each select="ChargeHistory[@Stage='Case Filing']">
                        <xsl:sort select="@FilingSequence" data-type="number" order="descending"/>
                        <xsl:if test="position()=1">
                            <xsl:call-template name="ChargeDetails"/>
                        </xsl:if>
                    </xsl:for-each>
                </xsl:otherwise>
            </xsl:choose>
        </ext:Charge>
    </xsl:template>



    <!--Charge Details Template-->
<xsl:template name="ChargeDetails">
    <j:ChargeSequenceID>
        <xsl:value-of select="ChargeNumber"/>
    </j:ChargeSequenceID>
    <j:ChargeStatute>
        <j:StatuteDescriptionText>
            <xsl:value-of select="Statute/StatuteCode"/>
        </j:StatuteDescriptionText>
        <j:StatuteText>
            <xsl:value-of select="Statute/StatuteCode/@Word"/>
        </j:StatuteText>
    </j:ChargeStatute>
    <j:ChargeSeverityDescriptionText>
        <xsl:value-of select="Statute/Degree"/>
    </j:ChargeSeverityDescriptionText>
        <ext:Citation>
            <nc:ActivityDate>
                <xsl:for-each select="/Integration/Citation/CitationCharge[ChargeID=current()/../@ID]">
                    <nc:Date>
                        <xsl:value-of select="mscef:formatDate(string(../TicketDate))"/>
                    </nc:Date>
                </xsl:for-each>
            </nc:ActivityDate>
            <nc:Identification>
                <nc:IdentificationID>
                    <xsl:value-of select="/Integration/Citation/CitationNumber"/>
                </nc:IdentificationID>
                <nc:IdentificationJurisdiction>
                    <nc:JurisdictionText>
                        <xsl:value-of select="/Integration/Citation/Agency/@Word"/>
                    </nc:JurisdictionText>
                </nc:IdentificationJurisdiction>
            </nc:Identification>
        </ext:Citation>
        <ext:Vehicle>
            <nc:VehicleCMVIndicator>
            <xsl:for-each select="/Integration/Citation/Vehicle[CommercialVehicleFlag]">
                <xsl:for-each select="//Case/Charge/Vehicle[CommercialVehicleFlag]">
                <xsl:value-of select="../Vehicle/CommercialVehicleFlag"/>
                </xsl:for-each>
            </xsl:for-each>
            </nc:VehicleCMVIndicator>
        </ext:Vehicle>
</xsl:template>
 
Well, there is always:
Code:
//CommercialVehicleFlag
Of course, that would harvest all such fields in the document. Probably not what you want, but if it is...

Making an XPath expression that will work in either case is fairly simple, but in order to do so, one needs to know what the context node would be. Your example xsl:template is a called template (it has a name, not a match). From the xsl:value-of contained in the template, it appears that you are calling this template with the context node being a node within <Vehicle>.

So, a better explanation is in order on this one.

Tom Morrison
Hill Country Software
 
The provided XSL does not seem to match the XML you have as an input document. Perhaps this is because your <Integration> contains a lot more stuff and you are showing just an excerpt to represent the place where you are finding the commercial vehicle indicator.

So I am going to focus on this:
Code:
            <xsl:for-each select="/Integration/Citation/Vehicle[CommercialVehicleFlag]">
                <xsl:for-each select="//Case/Charge/Vehicle[CommercialVehicleFlag]">
                <xsl:value-of select="../Vehicle/CommercialVehicleFlag"/>
                </xsl:for-each>
            </xsl:for-each>

The effect of the first for-each changes the context node to the Vehicle node which is a child node of Citation.

Then immediately you switch the context node in the second for-each to the Vehicle node that is a child node of Case/Charge. It is from this context that you then reference the CommercialVehicleFlag. If there is no Case/Charge/Vehicle, the value-of is never invoked.

So, how do you work yourself out of this confusion?

I am presuming from what your original post said (prior to your edit) that, in the real world, only one of the Vehicle nodes exists.

Consider the following to replace the entirety of the code quoted above:
Code:
<xsl:value-of select="(/Integration/Citation/Vehicle[CommercialVehicleFlag] [highlight #729FCF] | [/highlight]
                       /Integration/Case/Charge/Vehicle[CommercialVehicleFlag])[highlight #8AE234][1][/highlight]/CommercialVehicleFlag"/>
Let's translate this to English.

Select the [highlight #729FCF]union[/highlight] of /Integration/Citation/Vehicle, where there exists a CommercialVehicleFlag child, and /Integration/Case/Charge/Vehicle, where there exists a CommercialVehicleFlag child. From this nodeset, [highlight #8AE234]select the first node[/highlight], and use the value of that node's CommercialVehicleFlag child element.

Now, the [highlight #8AE234][1][/highlight] to select the first node is real a 'belt and suspenders' approach, since you claim that only one such element will exist.

If you need an XPath expression to determine if any CommercialVehicleFlag exist:
Code:
count(/Integration/Citation/Vehicle[CommercialVehicleFlag] |
      /Integration/Case/Charge/Vehicle[CommercialVehicleFlag]) &amp;gt; 0

A Final Note
While I appreciate the effort you made to edit the original post to give me the information I need, the edit has the effect of making my first response look a bit nonsensical. It also failed to flag the edited post or thread as new, or to email me that the thread has been updated. (These latter two issues have been raised with Tek-Tips management.) Probably in this case, simply adding another post onto the thread would have been a bit better. But, not to worry, I think we are on the way to an answer.

Tom Morrison
Hill Country Software
 
Tom after modifying my xsl I am not get the correct VehicleCMVIndicator. My xml document has Vehicle in two Charges. One has
XML:
<CommercialVehicleFlag>true</CommercialVehicleFlag>
under one charge and the other Vehicle under the second Charge has
XML:
<CommercialVehicleFlag>false</CommercialVehicleFlag>
.
My output is showing
XML:
<nc:VehicleCMVIndicator>true</nc:VehicleCMVIndicator>
for both Vehicles while it should say true for one and false for the other.

Here is the wrong output
XML:
<ext:Charge>
		<j:ChargeSequenceID>1</j:ChargeSequenceID>
		<ext:Vehicle>
			<nc:ItemStyleText/>
			<nc:VehicleCMVIndicator>true</nc:VehicleCMVIndicator>
		</ext:Vehicle>
	</ext:Charge>
	<ext:Charge>
		<j:ChargeSequenceID>2</j:ChargeSequenceID>
		<ext:Vehicle>
			<nc:ItemStyleText/>
			<nc:VehicleCMVIndicator>true</nc:VehicleCMVIndicator>
		</ext:Vehicle>
	</ext:Charge>

Here is my 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="67084403" xmlns="">
	<Case Op="E" InternalID="1617090273" ID="12124494" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
		<Charge ID="10905889" PartyID="14743901" InternalChargeID="1616713556" InternalPartyID="1612636670" xmlns:reslib="urn:reslib">
			<ChargeOffenseDate>04/28/2015</ChargeOffenseDate>
			<Vehicle>
				<CommercialVehicleFlag>true</CommercialVehicleFlag>
			</Vehicle>
		</Charge>
		<Charge ID="10905890" PartyID="14743901" InternalChargeID="1616713557" InternalPartyID="1612636670" xmlns:reslib="urn:reslib">
			<ChargeOffenseDate>04/28/2015</ChargeOffenseDate>
			<Vehicle>
				<CommercialVehicleFlag>false</CommercialVehicleFlag>
			</Vehicle>
		</Charge>
	</Case>
</Integration>

xsl code
Code:
<nc:VehicleCMVIndicator>
   <xsl:value-of select="(/Integration/Citation/Vehicle[CommercialVehicleFlag]|/Integration/Case/Charge/Vehicle[CommercialVehicleFlag])[1]/CommercialVehicleFlag"/> 
</nc:VehicleCMVIndicator>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top