2016-11-09 16 views
1

格式負值我試圖讓顯示正確的負值格式:在XSLT

現在它顯示(19%),當我想它顯示爲-19%。

我有與

<PerChg>-0.190</PerChg>

一個XML文件中的XSL格式化它不工作:

<xsl:value-of select="format-number(PerChg, '#0%')"/> 
<xsl:value-of select="format-number(PerChg, '#0%;-#0%')"/> 

偶試過:

<xsl:decimal-format name="decimalChangePercent" minus-sign="-" /> 
<xsl:value-of select="format-number(PerChg, '#0%;-#0%', 'decimalChangePercent')"/> 

任何想法?在.NET世界中,使用XslCompiledTransform/XSLT 1.0。

謝謝!

回答

3

沒有看到問題...

此輸入XML文件,

<PerChg>-0.190</PerChg> 
提供給該XSLT

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

    <xsl:template match="/"> 
    <xsl:value-of select="format-number(PerChg, '#0%')"/> 
    </xsl:template> 

</xsl:stylesheet> 

產生這個輸出,

-19% 

如預期的那樣。

1

賓果,找到了罪魁禍首!

有一個JavaScript函數可將所有負值轉換爲括號。

function MakeNegative() { 
       TDs = document.getElementsByTagName('td'); 
       for (var i = 0; i < TDs.length; i++) { 
        var temp = TDs[i]; 
        if (temp.firstChild && temp.firstChild.nodeValue) { // if not null 
         if (temp.firstChild.nodeValue.indexOf('-') == 0) { 
          temp.className += " negative"; 
          temp.firstChild.nodeValue = '(' + temp.firstChild.nodeValue.replace('-', '') + ')'; 
         } 
        } 
       } 
      }; 

感謝您的確認@ kjhughes讓我看起來更難!