首页 > 解决方案 > 如何在 XSL 中将 .00 转换为 0.00

问题描述

我有一个 XSL,它将一个 XML 作为输入,并将返回另一个所需格式的 XML。我面临的问题是有一个数值字段,当它具有 4.00..5.00 等值时很好,但是当它为 0 时,输入为 .00 而不是 0.00。有什么办法可以将 .00 更改为 0.00?这就是我当前 XSL 的样子:变量“Amount_57LV_ID2”是我想在下面更改的变量。如果是 .00 应该显示 0.00

<?xml version="1.0" encoding="WINDOWS-1252"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
-<xsl:template match="/">
<!-- Root template -->
-<Declaration language="FR" type="TVA_DECM" model="1">
-<Year>
<xsl:value-of select="/R570018A/Report_Header_S5/Year_PO_ID11"/>
</Year>
-<Period>
<xsl:value-of select="/R570018A/Report_Header_S5/Period_Number_PO_ID13"/>
</Period>
-<FormData>
-<xsl:for-each select="R570018A/UDC___Full_View_of_F0005_for_Transfer_57_LV_Driver_S1/Vat_Cross_Ref_57_LV_Print_S3/Print_F570018A_S6">
-<NumericField id="{AccountNumber_ID1}">
<xsl:value-of select="Amount_57LV_ID2"/>
</NumericField>
</xsl:for-each>
</FormData>
</Declaration>
</Declarer>
</Declarations>
</eCDFDeclarations>
</xsl:template>
</xsl:stylesheet>

标签: xmlxslt

解决方案


代替:

<xsl:value-of select="Amount_57LV_ID2"/>

尝试:

<xsl:value-of select="format-number(Amount_57LV_ID2, '0.00')"/>

这是假设数据始终需要精确到小数点后 2 位的精度。


推荐阅读