【发布时间】:2020-06-09 09:21:13
【问题描述】:
我正在尝试使用 xslt 从 rest 响应中生成一个 pdf 文件。它一切正常,但在负值中,它在金额值周围添加括号。就像金额 = 500$ 它的工作正常,但金额 = -600$ 它正在提供 (600$)。
<fo:table-cell>
<fo:block>
<xsl:value-of select="currency:getFormattedCurrency(amount/currency/text(), amount/amount/text())" />
</fo:block>
</fo:table-cell>
这是我的 getFormattedCurrency()
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currencyLocale);
currencyFormatter.setCurrency(currency);
return currencyFormatter.format(amount);
我还尝试了使用 xslt 的 contain() 的其他方式,以便我可以识别它是否具有负号字符串,并且我可以不同地对待这些负值和正值。像这样——
<fo:table-cell>
<fo:block>
<xsl:choose>
<xsl:when test="contains(string(availableAmount), '-')">
<xsl:value-of select="-1*(currency:getFormattedCurrency(availableAmount/currency/text(), availableAmount/amount/text()))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="currency:getFormattedCurrency(availableAmount/currency/text(), availableAmount/amount/text())" />
</xsl:otherwise>
</xsl:choose>
</fo:block>
</fo:table-cell>
通过修改 xsl 文件来寻找建议/解决方案以达到目标结果。attached is the image of what i am getting for negative values with bracket and positive values correctly 这是实际想要的图片。
很高兴接受解决此问题的其他方式。 :)
【问题讨论】:
-
xsl 文件
currency:getFormattedCurrency中该函数的定义函数在哪里,可能会声明检查值是否为负并包围在()中。 -
您是否考虑过改用 format-number XSLT 指令?它应该做你想做的事。
-
@amrendra 函数定义已经在上面提供了,但我无法更改函数定义,因为它来自我公司的框架,无法更改。
-
@bluewood66 我无法更改我的 Java 类中的任何内容,因为它是我公司框架的一部分。如果您的答案仅涉及 xsl 更改。请为此提供任何示例,以便我可以开始探索。
标签: xml xslt xslt-1.0 xsl-fo apache-fop