11 Replies - 498 Views - Last Post: 30 July 2018 - 05:37 AM Rate Topic: -----

#1 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

How do I get correct results from xml?

Posted 27 July 2018 - 09:18 AM

I have added xslt selector logic here. Kindly help me add logic to do the following
For each Charge with ChargeHistory Op="A" and Stage="Disposition Event", find if the vehicle type based on Integration/Citation/Vehicle/VehicleType/@Word =ATV or BOAT or SNOWMO AND the OffenseType @ Word = ST AND the OffenseStatute is not equal to a StatuteCode with first 3 characters of 169 OR the 4 characters of 8491 OR the first 6 characters of 86B331.
Could someone help me with this? Thanks in advance.

Here is the xml document
<Integration>
	<Case>
		<Charge Op="E" ID="13689714" InternalChargeID="1623159393" InternalPartyID="1617894767">
			<Vehicle>
				<VehicleType Word="BOAT">Motorboat</VehicleType>
			</Vehicle>
			<ChargeHistory Op="A" ChargeHistoryID="53525890" Stage="Disposition Event" CurrentCharge="true">
				<ChargeNumber Op="A">1</ChargeNumber>
				<Statute>
					<StatuteNumber Op="A">97C.401.2</StatuteNumber>
					<StatuteCode Op="A" Word="97C4012" InternalCodeID="110850">Fish and Game<CodeMapping>
						</CodeMapping>
					</StatuteCode>
					<OffenseType Word="ST">Statute</OffenseType>
				</Statute>
			</ChargeHistory>
		</Charge>
		<Charge Op="E" ID="13689715" InternalChargeID="1623159394" InternalPartyID="1617894767">
			<Vehicle>
				<VehicleType Word="BOAT">Motorboat</VehicleType>
			</Vehicle>
			<ChargeHistory Op="A" ChargeHistoryID="53525891" Stage="Disposition Event" CurrentCharge="true">
				<ChargeNumber Op="A">2</ChargeNumber>
				<Statute>
					<StatuteNumber Op="A">169.14.2(a)(4)</StatuteNumber>
					<StatuteCode Op="A" Word="169142a4">Traffic-speeding</StatuteCode>
					<OffenseType Word="ST">Statute</OffenseType>
				</Statute>
			</ChargeHistory>
		</Charge>
	</Case>
	<Citation>
		<Vehicle>
			<VehicleType Word="PASSVEH">Passenger Vehicle</VehicleType>
		</Vehicle>
		<CitationCharge>
			<ChargeID>13689714</ChargeID>
			<ChargeHistoryID>53525886</ChargeHistoryID>
			<ChargeNumber>1</ChargeNumber>
			<SequenceNumber>1</SequenceNumber>
			<OffenseStatute>97C.401.2</OffenseStatute>
		</CitationCharge>
		<CitationCharge>
			<ChargeID>13689715</ChargeID>
			<ChargeHistoryID>53525887</ChargeHistoryID>
			<ChargeNumber>2</ChargeNumber>
			<SequenceNumber>1</SequenceNumber>
			<OffenseStatute>169.14.2(a)(4)</OffenseStatute>
		</CitationCharge>
	</Citation>
</Integration>


Here is xslt selector logic
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
	<xsl:template match="/">
		<xsl:apply-templates select="Integration/Case"/>
	</xsl:template>
	<xsl:template match="Case">
		<!-- -->
		<!-- Check for repass events -->
		<!-- -->
		<xsl:if test="count(CaseEvent[(@Op='A') and (count(EventGroups/EventGroup[@Word='DVSSPECIAL'])!=0)])!=0">
			<NotificationEvent notificationType="DVSDisposition">
				<xsl:attribute name="elementState">Existing</xsl:attribute>
				<xsl:attribute name="elementName">CaseEvent</xsl:attribute>
				<xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
				<xsl:text>REPASSEVENT</xsl:text>
			</NotificationEvent>
		</xsl:if>
		<!-- Check for charge certifications	 -->
		<xsl:if test="../ControlPoint!='SAVE-CR-EVENT'">
			<xsl:for-each select="Charge">
				<xsl:variable name="vChargeID">
					<xsl:value-of select="@ID"/>
				</xsl:variable>
				<xsl:variable name="vDispEventID">
					<xsl:call-template name="GetCurrentDispositionEventIDForCharge">
						<xsl:with-param name="pChargeID">
							<xsl:value-of select="$vChargeID"/>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:variable>
				<xsl:for-each select="ancestor::Case//DispositionEvent[@ID = $vDispEventID]/Disposition[@ChargeID = $vChargeID]">
					<xsl:variable name="vDispChargeID">
						<xsl:value-of select="@ChargeID"/>
					</xsl:variable>
					<xsl:variable name="vDispChargeHistID">
						<xsl:value-of select="@ChargeHistoryID"/>
					</xsl:variable>
					<!-- was something updated for this dispo ? -->
					<xsl:if test="(string-length(@Op) != 0)  or (string-length(//ChargeHistory[@ChargeHistoryID=$vDispChargeHistID]/@Op) != 0) or (count(ancestor::Case/CaseEvent[(@Op='A') and (count(EventGroups/EventGroup[@Word='DVSSPECIAL'])!=0)])!=0)">
						<xsl:choose>
							<xsl:when test='@Op = "D"'>
							</xsl:when>
							<xsl:otherwise>
								<xsl:variable name="vIsTriggeringDisposition">
									<xsl:call-template name="IsTriggeringDisposition"/>
								</xsl:variable>
								<xsl:variable name="vWasTriggered">
									<xsl:choose>
										<!-- check triggered by case event -->
										<xsl:when test="(count(ancestor::Case/CaseEvent[(@Op='A') and (count(EventGroups/EventGroup[@Word='DVSSPECIAL'])!=0)])!=0) and ($vIsTriggeringDisposition = 'true')">
											<xsl:value-of select="true()"/>
										</xsl:when>
										<!-- check triggered by new disposition -->
										<xsl:when test="(@Op='A') and (count(../DispositionAmendmentReason)=0) and ($vIsTriggeringDisposition = 'true')">
											<xsl:value-of select='true()'/>
										</xsl:when>
										<!-- check triggered by amended disposition when earlier disposition didn't pass -->
										<xsl:when test="(@Op='A') and ($vIsTriggeringDisposition = 'true')">
											<xsl:variable name="vIsPriorDispositionTriggering">
												<xsl:for-each select="../DispositionEvent[count(Disposition[@ChargeID = $vChargeID])!=0][1]/Disposition[@ChargeID = $vChargeID]">
													<xsl:call-template name="IsTriggeringDisposition"/>
												</xsl:for-each>
											</xsl:variable>
											<xsl:choose>
												<xsl:when test="contains($vIsPriorDispositionTriggering,'false')">
													<xsl:value-of select="true()"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select="false()"/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select='false()'/>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:choose>
									<xsl:when test="$vWasTriggered='true'">
										<!-- determine vehicle type -->
										<xsl:variable name="vDWIVehicle">
											<xsl:call-template name="IsDwiVehicle"/>
										</xsl:variable>
										<xsl:variable name="vDvsCharge">
											<xsl:choose>
												<xsl:when test='(//ChargeHistory[@ChargeHistoryID=$vDispChargeHistID]/Additional/CertifyToDPS) and ($vDWIVehicle="false" or substring(//ChargeHistory[@ChargeHistoryID=$vDispChargeHistID]/Statute/StatuteNumber,1,4)="169A")'>
													<xsl:value-of select="true()"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select="false()"/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:variable>
										<xsl:choose>
											<!-- was there a conviction, that is certified, and with correct vehicle/statute combo ? -->
											<xsl:when test='$vDvsCharge="true"'>
												<xsl:variable name="vUpdate">
													<xsl:choose>
														<xsl:when test="(count(ancestor::Case/CaseEvent[(@Op='A') and (count(EventGroups/EventGroup[@Word='DVSSPECIAL'])!=0)])!=0)">resend</xsl:when>
														<xsl:when test='(count(//CaseEvent[EventType/@Word="IBDVSCONV"]/ChargeID[.=$vDispChargeID]) != 0) or (count(//CaseEvent[EventType/@Word="IBUPDDPS"]/ChargeID[.=$vDispChargeID]) != 0)'>update</xsl:when>
														<xsl:otherwise>initial</xsl:otherwise>
													</xsl:choose>
												</xsl:variable>
												<xsl:if test="$vUpdate != 'update'">
													<NotificationEvent notificationType="DVSDisposition">
														<xsl:attribute name="elementState"><xsl:value-of select="$vUpdate"/></xsl:attribute>
														<xsl:attribute name="elementName">DispositionEvent</xsl:attribute>
														<xsl:attribute name="elementKey"><xsl:value-of select="../@ID"/></xsl:attribute>
														<xsl:attribute name="chargeElementKey"><xsl:value-of select="$vDispChargeID"/></xsl:attribute>
														<xsl:attribute name="chargeHistoryElementKey"><xsl:value-of select="$vDispChargeHistID"/></xsl:attribute>
														<xsl:choose>
															<xsl:when test="$vUpdate = 'initial'">DispositionAdded</xsl:when>
															<xsl:when test="$vUpdate = 'resend2011'">DispositionRepass2011</xsl:when>
															<xsl:when test="$vUpdate = 'resend'">DispositionRepass</xsl:when>
															<xsl:otherwise>DispositionUpdated</xsl:otherwise>
														</xsl:choose>
													</NotificationEvent>
												</xsl:if>
											</xsl:when>
										</xsl:choose>
									</xsl:when>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:if>
				</xsl:for-each>
			</xsl:for-each>
		</xsl:if>
		<!-- Check for charge Re-Certifications -->
		<xsl:for-each select="CaseEvent[string-length(@Op)!=0 and EventType/@Word='RECERTDPS']/ChargeID">
			<xsl:variable name="vChrgID">
				<xsl:value-of select="."/>
			</xsl:variable>
			<xsl:variable name="vUpdate">
				<xsl:choose>
					<xsl:when test='count(//CaseEvent[EventType/@Word="IBUPDDPS"]/ChargeID[.=$vChrgID]) != 0'>update</xsl:when>
					<xsl:otherwise>initial</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<NotificationEvent notificationType="DVSDisposition">
				<xsl:attribute name="elementState"><xsl:value-of select="$vUpdate"/></xsl:attribute>
				<xsl:attribute name="elementName">Charge</xsl:attribute>
				<xsl:attribute name="elementKey"><xsl:value-of select="."/></xsl:attribute>
				<xsl:attribute name="chargeElementKey"><xsl:value-of select="."/></xsl:attribute>
				<xsl:text>ChargeRecertified</xsl:text>
			</NotificationEvent>
		</xsl:for-each>
	</xsl:template>
	<!--  -->
	<xsl:template name="IsDwiVehicle">
		<xsl:choose>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="ATV"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="BIKE"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="BOAT"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="CONSTEQUIP"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="ORMOTORCY"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="ORRV"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="SNOWMO"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="false()"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!--  -->
	<xsl:template name="IsTriggeringDisposition">
		<xsl:choose>
			<xsl:when test='DispositionType/@Word="CONV"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='DispositionType/@Word="ADJDEL"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='DispositionType/@Word="ADJTO"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='DispositionType/@Word="ADJPO"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="false()"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- Get the event id for the disposition associated with the provided charge id -->
	<!-- -->
	<xsl:template name="GetCurrentDispositionEventIDForCharge">
		<xsl:param name="pChargeID"/>
		<xsl:variable name="vDisps">
			<xsl:for-each select="//DispositionEvent[(@Op !='D' or string-length(@Op)=0)][count(Disposition[@ChargeID = $pChargeID])!=0][1]">
				<xsl:sort select="count(ancestor::DispositionEvent)" order="ascending"/>
				<xsl:for-each select="Disposition[@ChargeID = $pChargeID]">
					<xsl:value-of select="../@ID"/>;
				</xsl:for-each>
			</xsl:for-each>
		</xsl:variable>
		<xsl:value-of select="substring-before($vDisps,';')"/>
	</xsl:template>
</xsl:stylesheet>


This post has been edited by winkimjr2: 27 July 2018 - 02:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do I get correct results from xml?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14862
  • View blog
  • Posts: 59,302
  • Joined: 12-June 08

Re: How do I get correct results from xml?

Posted 27 July 2018 - 09:20 AM

What have you tried?

Are you required to keep this all in XML or convert it to, say, tables?
Was This Post Helpful? 0
  • +
  • -

#3 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I get correct results from xml?

Posted 27 July 2018 - 09:52 AM

View Postmodi123_1, on 27 July 2018 - 09:20 AM, said:

What have you tried?

Are you required to keep this all in XML or convert it to, say, tables?

Just xml using if statement inside for loop.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14862
  • View blog
  • Posts: 59,302
  • Joined: 12-June 08

Re: How do I get correct results from xml?

Posted 27 July 2018 - 09:54 AM

... so the XMLDocument object, or what.. ?

https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2769
  • View blog
  • Posts: 10,963
  • Joined: 03-December 12

Re: How do I get correct results from xml?

Posted 27 July 2018 - 11:43 AM

View Postwinkimjr2, on 27 July 2018 - 11:52 AM, said:

Just xml using if statement inside for loop.


Let me understand this, you are *required* to just use if statements and for loops?
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2769
  • View blog
  • Posts: 10,963
  • Joined: 03-December 12

Re: How do I get correct results from xml?

Posted 27 July 2018 - 01:31 PM

How I would do it... https://msdn.microso...y/gg509017.aspx
Was This Post Helpful? 0
  • +
  • -

#7 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I get correct results from xml?

Posted 27 July 2018 - 01:57 PM

View Postmodi123_1, on 27 July 2018 - 09:54 AM, said:

... so the XMLDocument object, or what.. ?

https://msdn.microso...(v=vs.110).aspx

I am going to use xsd selector logic which I have added to the question above.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14862
  • View blog
  • Posts: 59,302
  • Joined: 12-June 08

Re: How do I get correct results from xml?

Posted 27 July 2018 - 03:44 PM

Please don't whole sale edit your post after folks have responded to it. It breaks continuity and future readability..

Just add a new one to the thread.

So.. you are not doing this in a VB.NET project?
Was This Post Helpful? 0
  • +
  • -

#9 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I get correct results from xml?

Posted 29 July 2018 - 04:05 PM

No I am just using xslt stylesheet. I am sorry for editing the question. Now I know that is not a good idea.
Was This Post Helpful? 0
  • +
  • -

#10 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I get correct results from xml?

Posted 29 July 2018 - 05:27 PM

I would like to edit the stylesheet below, so that when I assign sample xml file (here below) the returned value is either true or false.
Return true when the following conditions are met in the xml sample file
Return true when ChargeHistory (in a Charge) has Op="A" AND Stage="Disposition Event" AND VehicleType="ATV OR SNOWMO OR BOAT AND OffenseType="ST" AND OffenseStatute is not equal to
a StatutueCode with first 3 characters are 169 OR first 4 characters are 8491 OR first 6 characters are 86B331.
Otherwise return false ()
How do I edit this stylesheet?

Stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:array="http://www.w3.org/2005/xpath-functions/array" xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:err="http://www.w3.org/2005/xqt-errors" exclude-result-prefixes="array fn map math xhtml xs err" version="3.0">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template name="IsDwiVehicle">
		<xsl:choose>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="ATV"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="BOAT"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:when test='//Citation/Vehicle/VehicleType/@Word="SNOWMO"'>
				<xsl:value-of select="true()"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="false()"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>


Use this sample xml file

<Integration>
	<Case>
		<Charge Op="E" ID="13689714" InternalChargeID="1623159393" InternalPartyID="1617894767">
			<Vehicle>
				<VehicleType Word="BOAT">Motorboat</VehicleType>
			</Vehicle>
			<ChargeHistory Op="A" ChargeHistoryID="53525890" Stage="Disposition Event" CurrentCharge="true">
				<ChargeNumber Op="A">1</ChargeNumber>
				<Statute>
					<StatuteNumber Op="A">97C.401.2</StatuteNumber>
					<StatuteCode Op="A" Word="97C4012" InternalCodeID="110850">Fish and Game<CodeMapping>
						</CodeMapping>
					</StatuteCode>
					<OffenseType Word="ST">Statute</OffenseType>
				</Statute>
			</ChargeHistory>
		</Charge>
		<Charge Op="E" ID="13689715" InternalChargeID="1623159394" InternalPartyID="1617894767">
			<Vehicle>
				<VehicleType Word="BOAT">Motorboat</VehicleType>
			</Vehicle>
			<ChargeHistory Op="A" ChargeHistoryID="53525891" Stage="Disposition Event" CurrentCharge="true">
				<ChargeNumber Op="A">2</ChargeNumber>
				<Statute>
					<StatuteNumber Op="A">169.14.2(a)(4)</StatuteNumber>
					<StatuteCode Op="A" Word="169142a4">Traffic-speeding</StatuteCode>
					<OffenseType Word="ST">Statute</OffenseType>
				</Statute>
			</ChargeHistory>
		</Charge>
	</Case>
	<Citation>
		<Vehicle>
			<VehicleType Word="PASSVEH">Passenger Vehicle</VehicleType>
		</Vehicle>
		<CitationCharge>
			<ChargeID>13689714</ChargeID>
			<ChargeHistoryID>53525886</ChargeHistoryID>
			<ChargeNumber>1</ChargeNumber>
			<SequenceNumber>1</SequenceNumber>
			<OffenseStatute>97C.401.2</OffenseStatute>
		</CitationCharge>
		<CitationCharge>
			<ChargeID>13689715</ChargeID>
			<ChargeHistoryID>53525887</ChargeHistoryID>
			<ChargeNumber>2</ChargeNumber>
			<SequenceNumber>1</SequenceNumber>
			<OffenseStatute>169.14.2(a)(4)</OffenseStatute>
		</CitationCharge>
	</Citation>
</Integration>

Was This Post Helpful? 0
  • +
  • -

#11 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,776
  • Joined: 12-December 12

Re: How do I get correct results from xml?

Posted 30 July 2018 - 12:39 AM

What have you thought about or attempted?

Edited: Actually, you already have a starting point in the stylesheet, with logic statements evaluating to true/false.
Was This Post Helpful? 0
  • +
  • -

#12 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I get correct results from xml?

Posted 30 July 2018 - 05:37 AM

View Postandrewsw, on 30 July 2018 - 12:39 AM, said:

What have you thought about or attempted?

Edited: Actually, you already have a starting point in the stylesheet, with logic statements evaluating to true/false.

What I have thought and attempted was creating the stylesheet. I am seeking help to add some logic to do the evaluation based on the conditions I have stated above.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1