0
我需要在xslt格式化小數值。該模板應該刪除小數。並顯示指定的數字後跟指定的小數位數。圓形模板圍繞小數點。當我嘗試使用我當前的模板時,我得到了NaN。xslt格式編號
模板應該轉變992.45到000000992如果digitCount = 9
<xsl:template name="RoundedDecimalFormat">
<xsl:param name="num"></xsl:param>
<xsl:param name="digitCount"></xsl:param>
<xsl:variable name="value" select="format-number(round($num), '#########')"></xsl:variable>
<xsl:call-template name="format-batchnum">
<xsl:with-param name="batchnum" select="$value"></xsl:with-param>
<xsl:with-param name="numbatchdigit" select="$digitCount"></xsl:with-param>
</xsl:call-template>
</xsl:template>
下面模板應轉換1323.91至00000132391,如果manyDigits = 9
<xsl:template name="UnRoundedDecimalFormat">
<xsl:param name="time"></xsl:param>
<xsl:param name="manyDigits"></xsl:param>
<xsl:variable name="value" select="format-number($time, '#########')"></xsl:variable>
<xsl:call-template name="format-batchnum">
<xsl:with-param name="batchnum" select="$value"></xsl:with-param>
<xsl:with-param name="numbatchdigit" select="$manyDigits"></xsl:with-param>
</xsl:call-template>
</xsl:template>
這部分工作正常,我在其他地方使用
<xsl:template name="format-batchnum">
<xsl:param name="batchnum"/>
<xsl:param name="numbatchdigit"/>
<xsl:value-of select="concat(substring(substring($vZeroes,1,$numbatchdigit), string-length($batchnum) +1), $batchnum)"/>
</xsl:template>
修訂版 *
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions "
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:call-template name="UnRoundedDecimalFormat">
<xsl:with-param name="salary" select="$annualSalary"></xsl:with-param>
</xsl:call-template>
<xsl:template name="RoundedDecimalFormat">
<xsl:param name="num"></xsl:param>
<xsl:param name="digitCount" select ="9"></xsl:param>
<xsl:variable name="value" select="format-number(round($num), '#########')"></xsl:variable>
<xsl:call-template name="format-batchnum">
<xsl:with-param name="batchnum" select="$value"></xsl:with-param>
<xsl:with-param name="numbatchdigit" select="$digitCount"></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="UnRoundedDecimalFormat">
<xsl:param name="time"></xsl:param>
<xsl:param name="manyDigits" select ="9"></xsl:param>
<xsl:variable name="vTime" select="translate(string($time), '.', '')"/>
<xsl:variable name="value" select="format-number(number(xs:string($vTime)), '#########')"></xsl:variable>
<xsl:call-template name="format-batchnum">
<xsl:with-param name="batchnum" select="$value"></xsl:with-param>
<xsl:with-param name="numbatchdigit" select="$manyDigits"></xsl:with-param>
</xsl:call-template>
</xsl:template>
function roundedDecimalFormat(number){
try{
var n = Math.round(number);
return n;}
catch(err){return '';}
}
function removeDecimal(number){
try{
var n = number.replace('.','');
return n;}
catch(err){
return '';
}
};
謝謝我會給我一個鏡頭,當我得到t o辦公室明天! –
@Rufio,不客氣。 –
嘗試調試時出現此錯誤。無法找到與命名空間「http://www.w3.org/2001/XMLSchema」相關聯的腳本或擴展對象。它來自 xsl:variable >,任何想法爲什麼?謝謝 –