0
我有個問題想辦法分組金額。我需要做兩種方法。基於變量信息在XSLT中對節點進行分組
-I-。第一種方法是指當我沒有多個費用時的情況。 (完成後)。輸入xml信息。
<ListOfAFGFINSApplicationIncomeandExpensesFormFill>
<AFGFINSApplicationIncomeandExpenses>
<AFGSubCategory>Rental Expense</AFGSubCategory>
<Amount>2000</Amount>
<Frequency>Quarterly</Frequency>
</AFGFINSApplicationIncomeandExpenses>
<AFGFINSApplicationIncomeandExpenses>
<AFGSubCategory>Child Maintenance Paid</AFGSubCategory>
<Amount>1000</Amount>
<Frequency>4 Weekly</Frequency>
</AFGFINSApplicationIncomeandExpenses>
</ListOfAFGFINSApplicationIncomeandExpensesFormFill>
我使用這個XSLT代碼:
<xsl:template match="ListOfAFGFINSApplicationIncomeandExpensesFormFill/AFGFINSApplicationIncomeandExpenses
[AFGSubCategory = ('Child Maintenance Paid', 'Rental Expense')]" mode="OtherCommitment">
<OtherCommitment
UniqueID="{fn:UniqueID(Id)}">
<xsl:attribute name="Amount">
<xsl:apply-templates select="." mode="Amount"/>
</xsl:attribute>
<xsl:attribute name="Frequency" select="fn:IncomeFrequency(Frequency)"/>
<xsl:attribute name="Category">
<xsl:choose>
<xsl:when test="AFGSubCategory = 'Child Maintenance Paid'">Child Maintenance</xsl:when>
<xsl:when test="AFGSubCategory = 'Rental Expense'">Rent</xsl:when>
</xsl:choose>
</xsl:attribute>
</OtherCommitment>
要計算的金額我用下面的模板:
<xsl:template match="node()" mode="Amount">
<xsl:choose>
<xsl:when test="Frequency = '4 Weekly'">
<xsl:value-of select="(Amount * 13) div 12"/>
</xsl:when>
<xsl:when test="Frequency = 'Quarterly'">
<xsl:value-of select="Amount * 4"/>
</xsl:when>
<xsl:when test="Frequency != ''">
<xsl:value-of select="Amount"/>
</xsl:when>
</xsl:choose>
</xsl:template>
對於我使用的頻率:
<xsl:function name="fn:IncomeFrequency">
<xsl:param name="Frequency"/>
<xsl:choose>
<xsl:when test="$Frequency = '4 Weekly'">Monthly</xsl:when>
<xsl:when test="$Frequency = 'Annually'">Yearly</xsl:when>
<xsl:when test="$Frequency = 'Quarterly'">Yearly</xsl:when>
<xsl:when test="$Frequency != ''">
<xsl:value-of select="$Frequency"/>
</xsl:when>
<xsl:when test="$Frequency/../AFGAnnualAmount != ''">Yearly</xsl:when>
</xsl:choose>
</xsl:function>
這是對於這種情況的輸出重刑是正確的:
<OtherCommitment Amount="8000" Frequency="Yearly"
Category="Rent">
</OtherCommitment>
<OtherCommitment Amount="1083.3333333333333"
Frequency="Monthly"
Category="Child Maintenance">
</OtherCommitment>
-II-第二種情況是,當我有更多然後一個子類別使用相同的名稱,我需要變換分析在「每月」值的頻率。輸入的
示例:
<ListOfAFGFINSApplicationIncomeandExpensesFormFill>
<AFGFINSApplicationIncomeandExpenses>
<AFGSubCategory>Rental Expense</AFGSubCategory>
<Amount>2000</Amount>
<Frequency>Quarterly</Frequency>
</AFGFINSApplicationIncomeandExpenses>
<AFGFINSApplicationIncomeandExpenses>
<AFGSubCategory>Rental Expense</AFGSubCategory>
<Amount>1000</Amount>
<Frequency>Mounthly</Frequency>
</AFGFINSApplicationIncomeandExpenses>
<AFGFINSApplicationIncomeandExpenses>
<AFGSubCategory>Child Maintenance Paid</AFGSubCategory>
<Amount>1000</Amount>
<Frequency>4 Weekly</Frequency>
</AFGFINSApplicationIncomeandExpenses>
</ListOfAFGFINSApplicationIncomeandExpensesFormFill>
輸出需要變得。
<OtherCommitment Amount="1666.6666666666667" Frequency="Monthly"
Category="Rent">
</OtherCommitment>
<!-- This will keep the first approach because is only one 'Child Maintenance'-->
<OtherCommitment Amount="1083.3333333333333"
Frequency="Monthly"
Category="Child Maintenance">
</OtherCommitment>
爲了計算金額,我需要在這種情況下可能是使用:
<xsl:template match="node()" mode="AmountMonthly">
<xsl:choose>
<xsl:when test="Frequency = 'Weekly'">
<xsl:value-of select="fn:remove-scientific-notation((Amount * 52) div 12)"/>
</xsl:when>
<xsl:when test="Frequency = 'Fortnightly'">
<xsl:value-of select="fn:remove-scientific-notation((Amount * 26) div 12)"/>
</xsl:when>
<xsl:when test="Frequency = '4 Weekly'">
<xsl:value-of select="fn:remove-scientific-notation((Amount * 13) div 12)"/>
</xsl:when>
<xsl:when test="Frequency = 'Monthly'">
<xsl:value-of select="Amount"/>
</xsl:when>
<xsl:when test="Frequency = 'Quarterly'">
<xsl:value-of select="fn:remove-scientific-notation((Amount * 4) div 12)"/>
</xsl:when>
<xsl:when test="Frequency = 'Annually'">
<xsl:value-of select="fn:remove-scientific-notation(Amount div 12)"/>
</xsl:when>
</xsl:choose>
</xsl:template>
但我不能搞清楚,如何總結的費用。
我已經解決了這個問題,就像你說的xsl:for-each-group group-by一樣。謝謝您的回覆。 – DanielCSD