XSLT中德语的格式编号 [英] Format Number for german-speaking in XSLT

查看:116
本文介绍了XSLT中德语的格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试格式化一个接受金额的报告,以下工作正常:

Hi all,

I''m trying to format a report which accepts amounts, the following works just fine:

<xsl:value-of select="format-number(@Amount, " xmlns:xsl="#unknown"></xsl:value-of>



但是,如何像在瑞士一样,如何显示千位分隔符的撇号呢?

使用



But how do I get it to display an apostrophe for a thousand separator, as they like it here in Switzeerland?

Using

<xsl:value-of select="format-number(@Amount, "###" hold=" /><br mode=" xmlns:xsl="#unknown"></xsl:value-of>

推荐答案



使用xsl:decimal-format,在MSDN上有一篇有关xsl:decimal-format的文章.

http://msdn.microsoft.com/en-us/library/ms256225.aspx [ ^ ]

例如,这是德语格式:

Hi,

Use xsl:decimal-format, there is an article about that on MSDN.

http://msdn.microsoft.com/en-us/library/ms256225.aspx[^]

For example this is the german format:

<xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />
<xsl:value-of select="format-number(24535.2, '###.###,00', 'european')"/>



您只需要对此稍作修改即可使其对瑞士人友好.

Valery.



You just need to re-work this a bit to make it swiss friendly.

Valery.


发现这一点很困难-不支持撇号字符.

最终用SQL代码进行了格式化,以将格式化的装载与原始数量一起输出,然后是XSL变量来选择跨度的类.凌乱.

如果有人对此感兴趣的是SQL格式功能,可能会很有用.如您所见,这是一种非常特定的格式....

Found difficulty with this - the apostrophe character is not supported.

Ended up doing a format in SQL code to output the formatted mount alongside the raw amount, then an XSL variable to select the class of the span. Messy.

If anyone is interested here is the SQL format function, could be useful. As you can see, it''s quite a specific format....

****** Object:  UserDefinedFunction [Intern].[fFormatNumberAsString]    Script Date: 07/14/2011 10:31:29 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[Intern].[fFormatNumberAsString]'') AND type in (N''FN'', N''IF'', N''TF'', N''FS'', N''FT''))
DROP FUNCTION [Intern].[fFormatNumberAsString]
GO
/*
	Author	:	Mel Padden	
	Purpose :	Formatting of floats as strings without scientific notation for XML resultsets

*/
CREATE FUNCTION [Intern].[fFormatNumberAsString](
	@RawNumber			FLOAT		= 0
,	@NumberOfDecimals	INT			= 2
,	@ThousandDelim		NVARCHAR(1) = ''''''''
,	@DecimalDelim		NVARCHAR(1) = ''.''
)
RETURNS NVARCHAR(MAX) AS
BEGIN
    DECLARE @FormattedNumber	AS VARCHAR(100);
    DECLARE @AfterDecimal		AS VARCHAR(100);
    DECLARE @Negative			AS BIT;
	IF		@RawNumber < 0 SET @Negative = 1;
	ELSE	SET @Negative = 0;
    SET @FormattedNumber = CONVERT(BIGINT, ABS(@RawNumber));
	
	IF @NumberOfDecimals = 0 BEGIN
		SET @AfterDecimal = '''';
	END ELSE BEGIN
		/*	Subtract the integer part from the float to get the decimal remainder */
		SET @AfterDecimal = ROUND((FLOOR(@RawNumber) - @RawNumber), @NumberOfDecimals);
		IF CHARINDEX(''.'', @AfterDecimal) <> 0 BEGIN
			SET @AfterDecimal = @DecimalDelim + RIGHT(@AfterDecimal, LEN(@AfterDecimal) - CHARINDEX(''.'',	@AfterDecimal));
		END ELSE BEGIN
			SET @AfterDecimal = '''';
		END
	END
	    
	DECLARE @i AS INT;
    DECLARE @j AS INT;
    SET @i = 0;
    SET @j = 0;
    WHILE @i <> LEN(@FormattedNumber) BEGIN
        IF @j = 3 BEGIN
            SET @j = - 1;
            SET @FormattedNumber = LEFT(@FormattedNumber, LEN(@FormattedNumber) - @i) + @ThousandDelim + RIGHT(@FormattedNumber, @i);
        END
        SET @j = @j + 1;
        SET @i = @i + 1;
    END
    SET @FormattedNumber =  @FormattedNumber + @AfterDecimal;
	IF @Negative = 1 SET @FormattedNumber = ''('' + @FormattedNumber + '')-'';
    RETURN @FormattedNumber
END
GO


这篇关于XSLT中德语的格式编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆