非常好的问题!这通常意味着,我不知道答案,但我希望其他人知道,因为这对我来说也很痛苦。
无论如何,我做了一些搜索,我认为该 round-half-to-even
功能可能会成功(http://www.xqueryfunctions.com/xq/fn_round-half-to-even.html)
您的代码将变为:
<xsl:value-of
select="
round-half-to-even(
myNode/DecimalValue
, myNode/DecimalPlaces
)
"
/>
现在有点切线:对于使用 XSLT 1.1 或更低版本和 XPath 1 的人,您可以使用这个:
<xsl:value-of
select="
concat(
substring-before(DecimalValue, '.')
, '.'
, substring(substring-after(DecimalValue, '.'), 1, DecimalPlaces -1)
, round(
concat(
substring(substring-after(DecimalValue, '.'), DecimalPlaces, 1)
, '.'
, substring(substring-after(DecimalValue, '.'), DecimalPlaces+1)
)
)
)
"
/>
当然,这段代码比原来的要差,但是如果有人知道如何解决 XPath 1 的原始问题并且有比这更好的主意,我很乐意听到。(越来越多的时候,我希望世界完全跳过 XML 并立即转向 JSON)