I have the following xml file:
<Contract>
<TotalCosts>31003</TotalCosts>
<PaymentSchedules>
<PaymentSchedule>
<Amount>516.7</Amount>
<NumberOfPayments>3</NumberOfPayments>
</PaymentSchedule>
<PaymentSchedule>
<Amount>529.7</Amount>
<NumberOfPayments>1</NumberOfPayments>
</PaymentSchedule>
<PaymentSchedule>
<Amount>516.7</Amount>
<NumberOfPayments>55</NumberOfPayments>
</PaymentSchedule>
<PaymentSchedule>
<Amount>504.70</Amount>
<NumberOfPayments>1</NumberOfPayments>
</PaymentSchedule>
</PaymentSchedules>
</Contract>
In my schematron file, I would like to make a TotalCosts are the same as the amount in the paymentSchedule.
For that, I need to do the following for each PaymentSchedule:
Amount * NumberOfPayments
After that, I need to take the sum of all PaymentSchedules, and that number should be exactly the same. If you try this for the given example, you will see that the amounts are exactly the same.
To validate this in schematron, I created this schematron file:
<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" queryBinding="xslt2">
<iso:ns uri="http://www.someurl.com" prefix="func"/>
<xsl:function name="func:getPaymentScheduleTotal">
<xsl:param name="contract" as="element()"/>
<xsl:value-of
select="sum($contract/PaymentSchedules/PaymentSchedule/(NumberOfPayments * Amount))"/>
</xsl:function>
<iso:pattern id="Contract">
<iso:rule context="Contract">
<iso:assert test="func:getPaymentScheduleTotal(.) = number(TotalCosts)">amount in paymentschedule(<iso:value-of select="func:getPaymentScheduleTotal(.)"/>) doesn't match total amount(<iso:value-of select="TotalCosts"/>)</iso:assert>
</iso:rule>
</iso:pattern>
</iso:schema>
But this is where I'm running into a problem. I get the following validation result:
amount in paymentschedule(31003.000000000004) doesn't match total amount(31003) (func:getPaymentScheduleTotal(.) = number(TotalCosts)) [assert]
I can't figure out where the .000000000004 is coming from. I can of course use something like floor to round the number, but I believe the .000000000004 shouldn't be there in the first place.
Any ideas?