Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added xslt selector logic of what I am trying to do and need help with.
Kindly help me.

Here is what I am trying to add to the selector (xslt)
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
XML
<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>
[/code]

What I have tried:

Here is xslt selector logic where I need to add logic
XML
<?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>
Posted
Updated 27-Jul-18 11:08am
v2
Comments
[no name] 27-Jul-18 17:45pm    
Did you have any particular "programming language(s)" in mind for your solution?
RedDk 27-Jul-18 17:59pm    
Please refrain from removing content of questions when editing posts. This question is completely different now, since the "update". And that's not ok with regards to posted Solutions ... users come upon pages through various means ... seeing answers in sets of returns from a search that have no connection to original posts ... can seem senseless without context (nubes arriving this way have no idea where to look for revision information).

So, next time use [EDIT] ... [END EDIT] ... and make it easier on the Solution posting community.

1 solution

I'm going to condense an answer to this question down to a bunch of steps that if you follow them will make doing what you want to do really easy. We'll be using Visual Studio to examine an XML file. I see in you current postings here on CP that "XML" is really throwing a wrench into the works .. which is no surprise ... especially when TSQL comes into the picture (lately, right?).

So. Steps to the attainment of complete satisfaction in all matters XML.

1. Open Visual Studio.
2. Browse to the work directory where your .xml file is located and open it as a file.
3. With the contents displayed in the workspace of VS, find the XML item on the main toolbar and select "Create Schema".
4. Save this xml schema (.xsd) to the work folder.
5. It should be open now; so look around the interface and find the window named "XML Schema Explorer". The "View" through that window might be concealed by the configuration's draperies (go to main menu "View" and activate it there).
6. Under "Schema Set" and "Empty Namespace" beneath that, see the XSD schema's name displayed then see a tree branch (edge) of the various ELEMENT and ATTRIBUTE leaves (node) hangin off of it. There are a few ways to make the xsd show up in VS and XML Schema Explorer is only one of them (Design view will allow you to choose which one is most useful to you). This one's the one that did it for me.
7. THAT nice hierarchy of xml elements and attributes is PRECISELY how the SQL Server table structure is going look in datatype, except you'll have to do the translating because TSQL has a slightly different name for each. I suggest using the Book-on-Line help to be more exacting.

More to the point:

From here, it looks as though you'll be creating two tables [Case] and [Citation]. As a general rule, when a field is ambiguous enough to appear to be an ATTRIBUTE, make it a table ELEMENT instead. In fact, it's probably easiest to make all potential ATTRIBUTE fields ELEMENT fields.

And finally, I see that this SCHEMA is, well, exceedingly complex ... if you are having more problems defining the structure and sorting the ATTRIBUTES and the ELEMENTS, perhaps find some unsophisticated .xml input that will boil down to a few or no ambiguities at all. And then compare the two.

Hope this helps get you started.
 
Share this answer
 
v3
Comments
Member 11403304 29-Jul-18 19:21pm    
I am only required to edit/update the xslt stylesheet. There is no visual studio code that needs to be edited.
So editing the stylesheet I should run the xml through the stylesheet and do the following.
1. Check each Charge with ChargeHistory with Op="A" and Stage="Disposition Event"
2. Find if the vehicle type is one of the following ATV, SNOWMO OR BOAT and offenseType = 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.(Integration/Citation/Vehicle/VehicleType/@Word =ATV or BOAT or SNOWMO)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900