DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12813>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12813

NullPointerException raised in BasisLibrary.formatNumber()

           Summary: NullPointerException raised in
                    BasisLibrary.formatNumber()
           Product: XalanJ2
           Version: 2.4
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Blocker
          Priority: Other
         Component: org.apache.xalan.xsltc
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


When format-number() is used in an xsl template that is in an included xsl 
stylesheet, on running that template a NullPointerException is raised. 
Specifically, the formatter argument in the formatNumber(double, String, 
DecimalFormat) method is null.

Below are the files to reproduce the error: 1 XML file and 2 XSL files 
(resource.xsl and mview_topfx_PDA.xsl) and the stack trace. 

mview_topfx_PDA.xsl includes the resource.xsl stylesheet and it is resource.xsl 
that contains a template that uses format-number(). 

Also, it is the included stylesheet (resource.xsl) that contains the root 
template match (not sure if that has any bearing on the bug)

==================================================================
XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Copyright Reuters Limited 2000 -->
<quotelist name="FXRATES" currency="">
        <ric name="EUR=X" id="1">
                <fid id="DSPLY_NAME"><![CDATA[EUR-USD]]></fid>
                <fid id="BID">0.980100</fid>
                <fid id="HST_CLOSE">0</fid>
        </ric>
        <ric name="EURGBP=X" id="2">
                <fid id="DSPLY_NAME"><![CDATA[EUR-GBP]]></fid>
                <fid id="BID">0.631100</fid>
                <fid id="HST_CLOSE">0</fid>
        </ric>
        <ric name="GBP=X" id="3">
                <fid id="DSPLY_NAME"><![CDATA[GBP-USD]]></fid>
                <fid id="BID">1.552700</fid>
                <fid id="HST_CLOSE">0</fid>
        </ric>
        <ric name="JPY=X" id="4">
                <fid id="DSPLY_NAME"><![CDATA[JPY-USD]]></fid>
                <fid id="BID">121.300000</fid>
                <fid id="HST_CLOSE">0</fid>
        </ric>
        <ric name="CHF=X" id="5">
                <fid id="DSPLY_NAME"><![CDATA[USD-CHF]]></fid>
                <fid id="BID">1.497100</fid>
                <fid id="HST_CLOSE">0</fid>
        </ric>
</quotelist>

=====================================================================

mview_topfx_PDA.xsl: 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:include href="resource.xsl"/>      
        
        <xsl:template name="main">
                <xsl:call-template name="topfx"/>
        </xsl:template>
        <xsl:template name="topfx">
                <table width="100%" border="0" cellspacing="1" cellpadding="2">
                        <xsl:apply-templates select="//quotelist/ric"/>
                </table>
        </xsl:template>
        <xsl:template match="quotelist/ric">
                <xsl:variable name="price">
                        <xsl:value-of select="./fid[@id='BID']"/>
                </xsl:variable>
                <xsl:variable name="close">
                        <xsl:value-of select="./fid[@id='HST_CLOSE']"/>
                </xsl:variable>
                <tr>
                        <td bgcolor="#99CCFF">
                                <font size="2">
                                        <b>
                                                <xsl:value-of select="./fid
[@id='DSPLY_NAME']"/>
                                        </b>
                                </font>
                        </td>
                        <td bgcolor="#99CCFF">
                                <font size="2">
                                        <div align="center">
                                                <xsl:choose>
                                                        <xsl:when test="number
($price) &lt; number($close)">
                                                                <img 
src="images/down_tri_lblbg.gif" width="8" height="6"/>
                                                        </xsl:when>
                                                        <xsl:when test="number
($price) &gt; number($close)">
                                                                <img 
src="images/up_tri_lblbg.gif" width="8" height="6"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>-
</xsl:otherwise>
                                                </xsl:choose>
                                        </div>
                                </font>
                        </td>
                        <td bgcolor="#99CCFF">
                                <font size="2">
                                        <div align="right">
                                                <xsl:call-template 
name="display_5_digits">
                                                        <xsl:with-param 
name="val">
                                                                <xsl:value-of 
select="./fid[@id='BID']"/>
                                                        </xsl:with-param>
                                                </xsl:call-template>
                                                <!--xsl:value-of select="format-
number(string($price), '0.00')"/-->
                                        </div>
                                </font>
                        </td>
                </tr>
        </xsl:template>
</xsl:stylesheet>

=====================================================================

resource.xsl: 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <!-- the root match template -->
        <xsl:template match="/">
                                <xsl:call-template name="main"/>
        </xsl:template>
        <!-- template to display 5 digits of any passed in number-->
        <xsl:template name="display_5_digits">
                <xsl:param name="val">__NO_VAL__</xsl:param>
                <xsl:choose>
                        <xsl:when test="number($val) &lt; 10">
                                <xsl:value-of select="format-number
($val, '0.0000')"/>
                        </xsl:when>
                        <xsl:when test="number($val) &lt; 100">
                                <xsl:value-of select="format-number
($val, '##.000')"/>
                        </xsl:when>
                        <xsl:when test="number($val) &lt; 1000">
                                <xsl:value-of select="format-number
($val, '###.00')"/>
                        </xsl:when>
                        <xsl:when test="number($val) &lt; 10000">
                                <xsl:value-of select="format-number
($val, '####.0')"/>             
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:value-of select="format-number
($val, '0')"/>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template> 
</xsl:stylesheet>
=====================================================================

Exception trace is:
java.lang.NullPointerException
        at org.apache.xalan.xsltc.runtime.BasisLibrary.formatNumber(BasisLibrary
.java:919)
        at mview_topfx_PDA.display_5_digits()
        at mview_topfx_PDA.applyTemplates()
        at mview_topfx_PDA.topfx()
        at mview_topfx_PDA.main()
        at mview_topfx_PDA.applyTemplates()
        at mview_topfx_PDA.transform()
        at org.apache.xalan.xsltc.runtime.AbstractTranslet.transform(AbstractTra
nslet.java:491)

Reply via email to