I've hacked my way around this issue, but I'd like to implement a better code. I'm trying to determine the last date where a non-zero financial event occurs. Note that this is a stripped and altered XML for brevity so excuse any formatting oddities. The actual XML I'm using has Change amounts from 1/1/2018 through 12/31/2029 with everything from 4/1/2018 to 12/31/2029 totaling to 0.
<Products>
<Cost>
<Company name="A"/>
<Financials>
<Change amount="-10000">
<Date date="1/1/2018" dateindays="42734">
<Type name="open">
<Change>
<Change amount="4500">
<Date date="2/1/2018" dateindays="42765">
<Type name="debit">
</Change>
<Change amount="4500">
<Date date="3/1/2018" dateindays="42793">
<Type name="debit">
</Change>
<Change amount="4500">
<Date date="4/1/2018" dateindays="42824">
<Type name="debit">
</Change>
<Change amount="-2000">
<Date date="4/1/2018" dateindays="42824">
<Type name="debit">
<Change>
<Change amount="-2500">
<Date date="4/1/2018" dateindays="42824">
<Type name="debit">
</Financials>
</Cost>
</Products>
In the above snippet I'd want the 3/1/2018 date, since the 4/1/2018 date totals to a 0 debit.
Using XSLT 2.0, I've used the following code to exclude the date of 4/1/2018, but I haven't figured a way to only return the 3/1/2018 date. Every thing I've tried has returned the 4/1/2018 as the last date in the series.
<xsl:for-each-group select="Products/Cost[Company/@name =
$Company]/Financials/Change[Type/@name = 'Debit']/Date" group-
by="@dateindays">
<xsl:sort select="@dateindays" data-type="number" order="descending"/>
<xsl:variable name="actDate" select="@dateindays"/>
<xsl:if test="sum(/Products/Cost[Company/@name =
$Company]/Financials/Change[Type/@name = 'Debit' and Date/@dateindays =
$actDate]/@amount) != 0">
<xsl:value-of select="@date"/>
</xsl:if>
</xsl:for-each-group>
As I said, I did some hacking (hidden cells in Excel), but I really want to handle it all in code as it appears this date might become required as part of later filtering within code.