循环在 XSLT 中创建 N 个等额付款
我对这门语言还很陌生,需要在 xslt 中创建循环来获得帮助。我有一个包含以下信息的 XML:
<Number_of_Payments>12</Number_of_Payments>
<First_Payment_Date>28-10-2020</First_Payment_Date>
<Monthly_Payment>760,00</Monthly_Payment>
我需要将其转换为定期每月付款(12 次付款,金额为 760)。到目前为止,我在 xslt 中进行了第一笔付款:
<paymentplan>
<loanpaymentplantype>Flat</loanpaymentplantype>
<intervaltype>StartOfMonth</intervaltype>
<interval>1</interval>
<startdate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/First_Payment_Date"/>
</xsl:call-template>
</startdate>
<maturitydate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/Last_Payment_Date"/>
</xsl:call-template>
</maturitydate>
<numpayments>
<xsl:value-of select="Account/Number_of_Payments"/>
</numpayments>
<payments>
<payment>
<paymentdate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/First_Payment_Date"/>
</xsl:call-template>
<!--<xsl:value-of select="concat(substring(First_Payment_Date, 7, 4),'-',substring(First_Payment_Date, 4, 2),'-',substring(First_Payment_Date, 1, 2))"/>-->
</paymentdate>
<amount>
<xsl:value-of select="translate(Account/Monthly_Payment, ',', '.')"/>
</amount>
<principalamount>
<xsl:value-of select="translate(Account/Monthly_Payment, ',', '.')"/>
</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
</payments>
这是我得到的输出:
<paymentplan>
<loanpaymentplantype>Flat</loanpaymentplantype>
<intervaltype>StartOfMonth</intervaltype>
<interval>1</interval>
<startdate>2020-11-01</startdate>
<maturitydate>2021-10-01</maturitydate>
<numpayments>12</numpayments>
<payments>
<payment>
<paymentdate>2020-11-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
</payments>
</paymentplan>
我需要的是付款计划中的 12 笔付款:
<payment>
<paymentdate>2020-11-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2020-12-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-01-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-02-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-03-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-04-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
等等...
I am pretty new in this language and need help by creating a loop in xslt. I have an XML with info below:
<Number_of_Payments>12</Number_of_Payments>
<First_Payment_Date>28-10-2020</First_Payment_Date>
<Monthly_Payment>760,00</Monthly_Payment>
And I need to transform this to a recurrent monthly payment (12 payments of 760). So far I have the first payment in xslt:
<paymentplan>
<loanpaymentplantype>Flat</loanpaymentplantype>
<intervaltype>StartOfMonth</intervaltype>
<interval>1</interval>
<startdate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/First_Payment_Date"/>
</xsl:call-template>
</startdate>
<maturitydate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/Last_Payment_Date"/>
</xsl:call-template>
</maturitydate>
<numpayments>
<xsl:value-of select="Account/Number_of_Payments"/>
</numpayments>
<payments>
<payment>
<paymentdate>
<xsl:call-template name="formatdate">
<xsl:with-param name="DateTimeStr" select="Account/First_Payment_Date"/>
</xsl:call-template>
<!--<xsl:value-of select="concat(substring(First_Payment_Date, 7, 4),'-',substring(First_Payment_Date, 4, 2),'-',substring(First_Payment_Date, 1, 2))"/>-->
</paymentdate>
<amount>
<xsl:value-of select="translate(Account/Monthly_Payment, ',', '.')"/>
</amount>
<principalamount>
<xsl:value-of select="translate(Account/Monthly_Payment, ',', '.')"/>
</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
</payments>
This is the Output that I get:
<paymentplan>
<loanpaymentplantype>Flat</loanpaymentplantype>
<intervaltype>StartOfMonth</intervaltype>
<interval>1</interval>
<startdate>2020-11-01</startdate>
<maturitydate>2021-10-01</maturitydate>
<numpayments>12</numpayments>
<payments>
<payment>
<paymentdate>2020-11-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
</payments>
</paymentplan>
What I would need is 12 payments on the paymentplan:
<payment>
<paymentdate>2020-11-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2020-12-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-01-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-02-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-03-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
<payment>
<paymentdate>2021-04-01</paymentdate>
<amount>760.00</amount>
<principalamount>760.00</principalamount>
<fixedinterest>0</fixedinterest>
</payment>
And so on...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下内容作为起点:
XSLT 1.0
结果
Here is something you could use as your starting point:
XSLT 1.0
Result