1

この19778.40のような入力 xml ファイルに 1 つの番号がありますが、xslt を介して出力 xml ファイルで19778,40 (ドットではなくカンマ) に変更したいと考えています。

この数値をフォーマットするにはどうすればよいですか? テンプレートを使用したくありません。

4

1 に答える 1

5

translate() 関数を使用できます。例として、この XSLT 1.0 スタイルシート...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="/">
<xsl:variable name="the-number" select="*/text()" />  
The input number with European formatting is <xsl:value-of select="translate($the-number,'.',',')" />
</xsl:template>

</xsl:stylesheet>

...この入力を変換します...

<t>19778.40</t>

...これに...

The input number with European formatting is 19778,40

また

format-number() 関数を次のように使用します...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="." />

<xsl:template match="/">
<xsl:variable name="the-number" select="*/text()" />  
The input number with European formatting is <xsl:value-of select="format-number($the-number,'#,00','euro')" />
</xsl:template>

</xsl:stylesheet>
于 2012-07-30T07:40:57.327 に答える