number format for .csv using xslt1.0

2020-05-09 09:16发布

I have tag in xml which value sometimes -ve number and sometimes +ve number and I want to show the -ve(e.g -10) number as (10) I mean with bracket using xslt1.0.

Could you please help me?

I am using below template but it is not working.

  <xsl:call-template name="fmtNumber">
           <xsl:with-param name="amt" select="retailer:Amount" />
  </xsl:call-template>
  <xsl:template name="fmtNumber">
        <xsl:param name="amt" />
        <xsl:value-of
        select="format-number($amt, ' $###,##0 ;($###,##0)')" />
  </xsl:template>

it is showing the result in csv file as $(10) but, I want (10), I mean without dollar sumbol.

标签: xslt
2条回答
孤傲高冷的网名
2楼-- · 2020-05-09 09:39

do:

<xsl:value-of select="format-number($amt, '###,##0;(###,##0)')"/>
查看更多
做个烂人
3楼-- · 2020-05-09 09:45

Please run the following stylesheet (with any XML source) on your processor and post the resulting code.

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="num" select="-123" />

<xsl:template match="/">
    <result>
        <version><xsl:value-of select="system-property('xsl:version')"/></version> 
        <vendor><xsl:value-of select="system-property('xsl:vendor')"/></vendor> 
        <test><xsl:value-of select="format-number($num, '#,##0;(#,##0)')"/></test>
    </result>
</xsl:template>

</xsl:stylesheet>
查看更多
登录 后发表回答