xml - 如何在 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>
解决方案
代替:
<xsl:value-of select="Amount_57LV_ID2"/>
尝试:
<xsl:value-of select="format-number(Amount_57LV_ID2, '0.00')"/>
这是假设数据始终需要精确到小数点后 2 位的精度。
推荐阅读
- r - 使用 tidyr 转换为在变量中生成子变量的长表
- javascript - 使用 Websockets 在 Python 中连续流式输出程序
- c# - 根据字符串参数从实体框架返回一个列表
- c# - 我有一个 asp 文本框,表示为 ASP 文字的文本属性。如何获取 TextBox 的 Text 值?
- java - 是否可以在 AspectJ 中排除字段集
- java - 排序 ArrayList 的麻烦
- javascript - 在潜水中打印段落时出现jquery问题
- swift - 使用 SwiftUI TextEditor 撤消/重做文本输入
- scala - Spark 任务无法将行写入 ORC 表
- javascript - 如何从 API json 文件中获取数组对象