Please help in summation logic where I am getting an error while adding the variable value.
XML below
<OutboundPaymentInstruction>
<OutboundPayment>
<DocumentPayable>
<DocumentPayableLine>
<LineNumber>2</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>TAX</Code>
<Meaning/>
</LineType>
<LineDescription>Utilities; Justification: W-IN-18-6402-1237845 </LineDescription>
<LineGrossAmount>
<Value>7912.5</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>3</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>AWT</Code>
<Meaning/>
</LineType>
<LineDescription>Utilities; Justification: W-IN-18-6402-1237845 </LineDescription>
<LineGrossAmount>
<Value>-3391.07</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>2.999999</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>1</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>ITEM</Code>
<Meaning/>
</LineType>
<LineDescription>Utilities;Justification: W-IN-18-6402-1237845 </LineDescription>
<LineGrossAmount>
<Value>113035.71</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode/>
<TaxRate>0</TaxRate>
<TaxRateCode/>
</Tax>
</DocumentPayableLine>
</DocumentPayable>
</OutboundPayment>
<OutboundPayment>
<DocumentPayable>
<DocumentPayableLine>
<LineNumber>2</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>TAX</Code>
<Meaning/>
</LineType>
<LineDescription>The Garbage Service Fee For 02/64</LineDescription>
<LineGrossAmount>
<Value>6730.5</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>3</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>AWT</Code>
<Meaning/>
</LineType>
<LineDescription>The Garbage Service Fee For 02/64</LineDescription>
<LineGrossAmount>
<Value>-2884.5</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>1</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>ITEM</Code>
<Meaning/>
</LineType>
<LineDescription>The Garbage Service Fee For 02/64</LineDescription>
<LineGrossAmount>
<Value>96150</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode/>
<TaxRate>0</TaxRate>
<TaxRateCode/>
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineNumber>2</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>TAX</Code>
<Meaning/>
</LineType>
<LineDescription> Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>28276.42</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>3</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>AWT</Code>
<Meaning/>
</LineType>
<LineDescription> Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>-12118.46</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>2.999999</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>1</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>ITEM</Code>
<Meaning/>
</LineType>
<LineDescription> Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>403948.8</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode/>
<TaxRate>0</TaxRate>
<TaxRateCode/>
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineNumber>2</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>TAX</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>13296.15</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>7</TaxRate>
<TaxRateCode>TH AP STD SVC 7</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>3</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>AWT</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>-5698.35</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>3</TaxRate>
<TaxRateCode>TH WHT SVCS 03</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>1</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>ITEM</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Waste Water )</LineDescription>
<LineGrossAmount>
<Value>189945</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode/>
<TaxRate>0</TaxRate>
<TaxRateCode/>
</Tax>
</DocumentPayableLine>
</DocumentPayable>
<DocumentPayable>
<DocumentPayableLine>
<LineNumber>2</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>TAX</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Rental Car parking ) Cloud GL : 630086 Cloud CC : 50020 Invoice = VAT 0%</LineDescription>
<LineGrossAmount>
<Value>0</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH VAT</TaxCode>
<TaxRate>0</TaxRate>
<TaxRateCode>TH AP ZERO 0</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>3</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>AWT</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Rental Car parking ) Cloud GL : 630086 Cloud CC : 50020 Invoice = VAT 0%</LineDescription>
<LineGrossAmount>
<Value>-13763.2</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode>TH WHT</TaxCode>
<TaxRate>5</TaxRate>
<TaxRateCode>TH WHT RENT 05</TaxRateCode>
</Tax>
</DocumentPayableLine>
<DocumentPayableLine>
<LineNumber>1</LineNumber>
<PONumber/>
<ConsumptionAdviceNumber/>
<LineType>
<Code>ITEM</Code>
<Meaning/>
</LineType>
<LineDescription>Monthly billing on Feb'21 of supplier 304 INDUSTRIAL PARK.( Rental Car parking )Cloud GL : 630086 Cloud CC : 50020 Invoice = VAT 0%</LineDescription>
<LineGrossAmount>
<Value>275264</Value>
<Currency>
<Code>THB</Code>
<NumericCode>764</NumericCode>
</Currency>
</LineGrossAmount>
<UnitPrice>0</UnitPrice>
<Quantity/>
<UnitOfMeasure>
<Code/>
<Meaning/>
</UnitOfMeasure>
<Tax>
<TaxCode/>
<TaxRate>0</TaxRate>
<TaxRateCode/>
</Tax>
</DocumentPayableLine>
</DocumentPayable>
</OutboundPayment>
</OutboundPaymentInstruction>
Please help as I am trying to do the below logic for individual "AWT" scenario and finally summing up the total by grouping by TaxRateCode for its own OutboundPayment tag.
Forumla trying to implement = (100 div (Tax/TaxRate)) * LineGrossAmount/Value
Example - ((100 div 3) * -5698.35) = -189945
((100 div 2.999999) * -12118.46) = -403948.8013
((100 div 3) * -2884.5) = -96150
<calc>690043.80</calc>
Expected Output
<Result>
<Rcrd>
<TaxAmt>
<Rate>3</Rate>
<calc>690043.80</calc>
</TaxAmt>
</Rcrd>
<Rcrd>
<TaxAmt>
<Rate>5</Rate>
<calc>275264.00</calc>
</TaxAmt>
</Rcrd>
</Result>
<Result>
<Rcrd>
<TaxAmt>
<Rate>3</Rate>
<calc>113035.7043</calc>
</TaxAmt>
</Rcrd>
</Result>
Code Tried
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="k" match="DocumentPayableLine[LineType/Code='AWT']" use="concat(generate-id(../..), Tax/TaxRateCode)" />
<xsl:template match="/OutboundPaymentInstruction">
<xsl:for-each select="OutboundPayment">
<Result>
<xsl:for-each select="DocumentPayable/DocumentPayableLine[LineType/Code='AWT'][count(. | key('k', concat(generate-id(../..), Tax/TaxRateCode))[1]) = 1]">
<Rcrd>
<xsl:variable name="TX1"><xsl:value-of select="Tax/TaxRate"/></xsl:variable>
<xsl:variable name="GrossAmount"><xsl:value-of select="LineGrossAmount/Value"/></xsl:variable>
<TaxAmt>
<Rate>
<xsl:value-of select="round(Tax/TaxRate)"/>
</Rate>
<xsl:variable name="IndividualCalc"><xsl:value-of select="((100 div $TX1) * $GrossAmount)"/></xsl:variable>
<calc>
<xsl:value-of select="-sum(key('k', concat(generate-id(../..), Tax/TaxRateCode))$IndividualCalc)"/>
</calc>
</TaxAmt>
</Rcrd>
</xsl:for-each>
</Result>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Please help.