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

How do I display CommercialVehicleFlag?

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

CODE --> xml

/Integration/Case/Charge/Vehicle/VehicleLicensePlateNumber 

and failing this xpath

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

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="67084884" xmlns="">
	<Case Op="E" InternalID="1617090736" ID="12125870" xmlns:user="http://tylertechnologies.com">
		<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

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="67086833" xmlns="">
	<Citation ID="5380737" xmlns:user="http://tylertechnologies.com">
		<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 --> xsl

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> 

RE: How do I display CommercialVehicleFlag?

Well, there is always:

CODE --> XPath

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

RE: How do I display CommercialVehicleFlag?

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

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

<xsl:value-of select="(/Integration/Citation/Vehicle[CommercialVehicleFlag]  | 
                       /Integration/Case/Charge/Vehicle[CommercialVehicleFlag])[1]/CommercialVehicleFlag"/> 
Let's translate this to English.

Select the union of /Integration/Citation/Vehicle, where there exists a CommercialVehicleFlag child, and /Integration/Case/Charge/Vehicle, where there exists a CommercialVehicleFlag child. From this nodeset, select the first node, and use the value of that node's CommercialVehicleFlag child element.

Now, the [1] 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 --> XPath

count(/Integration/Citation/Vehicle[CommercialVehicleFlag] |
      /Integration/Case/Charge/Vehicle[CommercialVehicleFlag]) &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

RE: How do I display CommercialVehicleFlag?

(OP)
Tom after modifying my xsl I am not get the correct VehicleCMVIndicator. My xml document has Vehicle in two Charges. One has

CODE --> xml

<CommercialVehicleFlag>true</CommercialVehicleFlag> 
under one charge and the other Vehicle under the second Charge has

CODE --> xml

<CommercialVehicleFlag>false</CommercialVehicleFlag> 
.
My output is showing

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

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

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="67084403" xmlns="">
	<Case Op="E" InternalID="1617090273" ID="12124494" xmlns:user="http://tylertechnologies.com">
		<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 --> xsl

<nc:VehicleCMVIndicator>
   <xsl:value-of select="(/Integration/Citation/Vehicle[CommercialVehicleFlag]|/Integration/Case/Charge/Vehicle[CommercialVehicleFlag])[1]/CommercialVehicleFlag"/> 
</nc:VehicleCMVIndicator> 

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