使用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Number">
<Result>
<Total amount="{round(format-number(Value, '#.00')*100)}"/>
</Result>
</xsl:template>
</xsl:stylesheet>
この変換が提供された XML ドキュメントに適用されると、次のようになります。
<Number>
<Value>529.82</Value>
</Number>
必要な正しい結果が生成されます。
<Result>
<Total amount="52982"/>
</Result>
説明:
XSLT 1.0 には数値型が 1 つだけあり、それはdouble型です。
他の浮動小数点型と同様に、精度エラーがあります。
XPath 2.0 / XSLT 2.0 では、xs:decimal型を使用できるため、精度エラーがなくなります。もちろん、xs:decimal型には最大桁数が定義されています。
参考までに、 を使用した対応する XSLT 2.0 変換を次に示しますxs:decimal。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Number">
<Result>
<Total amount="{xs:decimal(format-number(Value, '#.00'))*100}"/>
</Result>
</xsl:template>
</xsl:stylesheet>
結果:
<Result>
<Total amount="52982"/>
</Result>
またはさらに単純です(なしformat-number()):
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Number">
<Result>
<Total amount="{xs:decimal(Value)*100}"/>
</Result>
</xsl:template>
</xsl:stylesheet>