My xslt is not working as I expect it to. I expect to get <flag>true</flag> but my output is displaying <flag>false</flag>
The result I want should look like this.
However, this is what I am getting.
My xml input
My xslt stylesheet
The result I want should look like this.
Code:
<?xml version="1.0" encoding="UTF-16"?>
<EditReport>
<EditResult>
<EditNumber>4</EditNumber>
<ItemIdentification>Charge:</ItemIdentification>
<flag>true</flag>
</EditResult>
</EditReport>
However, this is what I am getting.
Code:
<?xml version="1.0" encoding="UTF-16"?>
<EditReport>
<EditResult>
<EditNumber>4</EditNumber>
<ItemIdentification>Charge:</ItemIdentification>
<flag>false</flag>
</EditResult>
</EditReport>
My xml input
XML:
<Pipeline>
<SourceXML>
<Integration>
<Case>
<Charge Op="E" ID="13661210" >
<ChargeHistory ChargeHistoryID="53438802" Stage="Case Filing" FilingSequence="1" InternalOffenseHistoryID="1661667423">
<ChargeNumber>1</ChargeNumber>
<Statute>
<Degree Word="MSD">Misdemeanor</Degree>
</Statute>
<Deleted>false</Deleted>
</ChargeHistory>
<ChargeHistory Op="A" ChargeHistoryID="53438803" Stage="Disposition Event" DispositionEventSequence="1" CurrentCharge="true" InternalOffenseHistoryID="1661667424">
<ChargeNumber Op="A">1</ChargeNumber>
<Statute>
<Degree Op="A" Word="MSD">Misdemeanor</Degree>
</Statute>
<Additional/>
<Deleted Op="A">false</Deleted>
</ChargeHistory>
<Deleted>false</Deleted>
</Charge>
</Case>
</Integration>
</SourceXML>
</Pipeline>
My xslt stylesheet
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
<xsl:output method="xml"/>
<xsl:variable name="editPass">Pass</xsl:variable>
<xsl:variable name="editWarn">Warn</xsl:variable>
<xsl:variable name="messageIdentification">Case:<xsl:value-of select="Pipeline/SourceXML/Integration/Case/CaseNumber"/>
</xsl:variable>
<xsl:template match="/">
<EditReport>
<xsl:call-template name="EditChargeControlNumber"/>
</EditReport>
</xsl:template>
<xsl:template name="EditChargeControlNumber">
<!--Missing Control Number-->
<xsl:for-each select="Pipeline/SourceXML/Integration/Case/Charge[(Deleted!='true') or (string-length(Deleted)=0)]">
<xsl:variable name="vFilChrgHistID">
<xsl:for-each select="Pipeline/SourceXML/Integration/Case/Charge/ChargeHistory[(Deleted!='true') or (string-length(Deleted)=0)][(@Stage='Case Filing')]">
<xsl:sort select="@FilingSequence"/>
<xsl:if test="position()=last()">
<xsl:value-of select="@ChargeHistoryID"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="vPettyOrNonTargMsd">
<xsl:choose>
<xsl:when test="ChargeHistory[@ChargeHistoryID=$vFilChrgHistID]/Statute/Degree/@Word='PMD'">true</xsl:when>
<xsl:when test="(ChargeHistory[@ChargeHistoryID=$vFilChrgHistID]/Statute/Degree/@Word='MSD') and (ChargeHistory[@ChargeHistoryID=$vFilChrgHistID]/Additional/TargetedMisdemeanor='false')">true</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<EditResult>
<EditNumber>4</EditNumber>
<ItemIdentification>Charge:<xsl:value-of select='Pipeline/SourceXML/Integration/Case/Charge/ChargeHistory[(Deleted!="true") or (string-length(Deleted)=0)][@CurrentCharge="true"]/ChargeNumber'/>
</ItemIdentification>
<flag>
<xsl:value-of select="$vPettyOrNonTargMsd"/>
</flag>
</EditResult>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>