none
How do I get the correct output in xslt? RRS feed

  • Question

  • I would like to get the following output from my xml document. When the dateofbirth is present in the input document (xml doc) I want the result to show pass. Expected <?xml version="1.0" encoding="UTF-16"?> <EditReport xmlns="http://www.courts.state.mn.us/02/MW"> <EditResult> <EditNumber>5</EditNumber> <ItemIdentification>Defendant Date of Birth</ItemIdentification> <Result>Pass</Result> </EditResult> </EditReport> My output which is wrong <?xml version="1.0" encoding="UTF-16"?> <EditReport xmlns="http://www.courts.state.mn.us/02/MW"> <EditResult> <EditNumber>5</EditNumber> <ItemIdentification>Defendant Date of Birth</ItemIdentification> <Result/> </EditResult> </EditReport> Xml document <Pipeline> <SourceXML> <Integration> <ControlPoint>SAVE-CR-SENTENCE</ControlPoint> <Case> <CaseCategory>CR</CaseCategory> <CaseType Word="CRM">Crim/Traf Mandatory</CaseType> <BaseCaseType>Adult</BaseCaseType> <Expunged>false</Expunged> <DispositionEvent Op="A"/> <CaseParty ID="17321520" InternalCasePartyID="1648995659" InternalPartyID="1615875612"> <Connection Word="DFD" BaseConnection="DF"/> </CaseParty> <Charge Op="E" ID="13562795" PartyID="17321520"> <ChargeHistory ChargeHistoryID="53109803" Stage="Case Filing" FilingSequence="1" InternalOffenseHistoryID="1661499994"> <ChargeNumber>1</ChargeNumber> <Statute> <LegacyReferenceID>12891</LegacyReferenceID> <Degree Word="MSD">Gross Misdemeanor</Degree> </Statute> <Additional> <TargetedMisdemeanor>false</TargetedMisdemeanor> </Additional> <Deleted>false</Deleted> </ChargeHistory> <ChargeHistory Op="A" ChargeHistoryID="55339617" Stage="Disposition Event" DispositionEventSequence="1" CurrentCharge="true"> <ChargeNumber Op="A">1</ChargeNumber> <Statute> <LegacyReferenceID Op="A">12173</LegacyReferenceID> <Degree Op="A" Word="MSD">Gross Misdemeanor</Degree> </Statute> <Additional> <TargetedMisdemeanor Op="A">false</TargetedMisdemeanor> </Additional> <Deleted Op="A">false</Deleted> </ChargeHistory> <Deleted>false</Deleted> </Charge> </Case> <Party ID="17321520" InternalPartyID="1615875612"> <DateOfBirth Current="true">04/15/1968</DateOfBirth> <PartyName ID="12071722" InternalNameID="1618898170"> <NameType>Standard</NameType> </PartyName> </Party> </Integration> </SourceXML> </Pipeline>

    Updated stylesheet

    <xsl:stylesheet xmlns="http://www.courts.state.mn.us/02/MW" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<xsl:output method="xml"/>
    	<xsl:variable name="editPass">Pass</xsl:variable>
    	<xsl:variable name="editWarn">Warn</xsl:variable>
    	<xsl:template match="/">
    		<EditReport>
    			<xsl:if test="Pipeline/SourceXML/Integration[(ControlPoint='SAVE-CR-DISPOSITION') or (ControlPoint='SAVE-CR-SENTENCE') or (ControlPoint='SAVE-CR-PLEA')]/Case[Expunged!='true']/CaseType[(substring(@Word, 1, 3)!='CNV')][(@Word!='OUT')]">
    				<xsl:call-template name="EditDefDOB"/>
    			</xsl:if>
    		</EditReport>
    	</xsl:template>
    	<xsl:template name="EditDefDOB">
    		<!--Missing Birth Date for Defendant-->
    		<xsl:for-each select="Pipeline/SourceXML/Integration/Case/Charge[(@Op='E') and (((Deleted!='true') or (string-length(Deleted)=0)) and ((string-length(Deleted/@Op)=0) or (Deleted/@Op!='D')))]">
    			<xsl:variable name="vChargeID">
    				<xsl:value-of select="@ID"/>
    			</xsl:variable>
    			<xsl:if test="//DispositionEvent[(@Op!='D') or  (string-length(@Op)=0)]/Disposition[((@Op!='D') or (string-length(@Op)=0)) and ($vChargeID=@ChargeID)]">
    				<!--Check if Charge is disposed-->
    				<xsl:if test="((../BaseCaseType!='Juvenile') and (count(ChargeHistory[(((Deleted!='true') or (string-length(Deleted)=0)) and ((Deleted/@Op!='D') or (string-length(Deleted/@Op)=0))) and ((Statute/Degree/@Word='FEL') or (Statute/Degree/@Word='GMD') or (Additional/TargetedMisdemeanor ='true'))])>0) ) or ((../BaseCaseType='Juvenile') and (count(ChargeHistory[(((Deleted!='true') or (string-length(Deleted)=0)) and ((Deleted/@Op!='D') or (string-length(Deleted/@Op)=0))) and  ((Statute/Degree/@Word='FEL') or (Statute/Degree/@Word='GMD'))])>0) )">
    					<xsl:if test="(ChargeHistory[@CurrentCharge='true']/Statute[LegacyReferenceID!='12112' and LegacyReferenceID!='12113'])">
    						<xsl:for-each select='//CaseParty[(Connection/@BaseConnection="DF") and (string-length(Connection/RemovedReason/@Word)=0)]'>
    							<xsl:variable name="vPartyID">
    								<xsl:value-of select="@ID"/>
    							</xsl:variable>
    							<EditResult>
    								<EditNumber>5</EditNumber>
    								<ItemIdentification>Defendant Date of Birth</ItemIdentification>
    								<Result>
    									<xsl:for-each select="//Party[@ID = $vPartyID]">
    										<xsl:choose>
    											<xsl:when test="PartyName[@Current='true']/NameType = 'Business'">
    												<xsl:value-of select="$editPass"/>
    											</xsl:when>
    											<xsl:when test="string-length(DateOfBirth) !=0">
    												<xsl:value-of select="$editPass"/>
    											</xsl:when>
    											<xsl:otherwise>
    												<xsl:value-of select="$editWarn"/>
    											</xsl:otherwise>
    										</xsl:choose>
    									</xsl:for-each>
    								</Result>
    							</EditResult>
    						</xsl:for-each>
    					</xsl:if>
    				</xsl:if>
    			</xsl:if>
    			<!--</xsl:if>-->
    		</xsl:for-each>
    	</xsl:template>


    • Edited by winkimjr2 Tuesday, February 27, 2018 9:27 PM I have updated my style sheet
    Tuesday, February 27, 2018 6:38 PM

Answers

All replies

  • Hello,

    Please change your vPartyID variable to the following (@ID to @PartyID):

    <xsl:variable name="vPartyID">
      <xsl:value-of select="@PartyID"/>
    </xsl:variable>

    Output:

    <?xml version='1.0' ?>
    <EditReport xmlns="http://www.courts.state.mn.us/02/MW">
      <EditResult>
        <EditNumber>5</EditNumber>
        <ItemIdentification>Defendant Date of Birth</ItemIdentification>
        <Result>Pass</Result>
      </EditResult>
    </EditReport>



    Tuesday, February 27, 2018 8:43 PM
  • Thanks for your input. I forgot to mention that, there can be more than one Charge in the document. In that case I have to only output the result based on the last Charge. Right now. My output is showing two edit results. I need to show only one

    Here is my output

    <?xml version="1.0" encoding="UTF-16"?>
    <EditReport xmlns="http://www.courts.state.mn.us/02/MW">
    <EditResult>
    	<EditNumber>5</EditNumber>
    	<ItemIdentification>Defendant Date of Birth</ItemIdentification>
    	<Result>Pass</Result>
    </EditResult>
    <EditResult>
    	<EditNumber>5</EditNumber>
    	<ItemIdentification>Defendant Date of Birth</ItemIdentification>
    	<Result>Pass</Result>
    </EditResult>
    </EditReport>

    Correct output should be

    <?xml version="1.0" encoding="UTF-16"?>
    <EditReport xmlns="http://www.courts.state.mn.us/02/MW">
    <EditResult>
    	<EditNumber>5</EditNumber>
    	<ItemIdentification>Defendant Date of Birth</ItemIdentification>
    	<Result>Pass</Result>
    </EditResult>
    </EditReport>

    Tuesday, February 27, 2018 9:03 PM
  • Hello,

    Please try to use last() function.

    You can see how it works here:

    last Function (XPath)

    • Marked as answer by winkimjr2 Wednesday, February 28, 2018 4:01 PM
    Tuesday, February 27, 2018 9:21 PM