I'm trying to add a right parenthesis to a number when it is negative upon returning from a Java function and so far am unable to do it. I can add the left parenthesis no problem but can't find a way to add the right parenthesis. It is much appreciated if anyone can help?
This is the line I'm using to try and include the right parenthesis. I'm thinking the code would interpret the end of the number as a space and translate it to a ')'. I've tried both " " and "" but neither works. An example of the result I currently get is this: (250.00
<xsl:value-of select='translate(translate(format-number(nws:FormatNoDollar4(nws:ReturnTotalUndesignated()),"0.00"),"-","(")," ",")")'/>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:nws="urn:ns"
<xsl:value-of select="nws:ResetCount()"/>
<xsl:apply-templates select="Details/CurrentAct" mode="totalundesigamt"/> 
<table-row font-size='9' font-weight='500'> 
<table-cell><block><xsl:value-of select="Details/CurrentAct/Date"/></block></table-cell> 
<table-cell><block>Credit Applied</block></table-cell>
<table-cell><block text-align='far'>
<xsl:value-of select='translate(translate(format-number(ns:FormatNoDollar4(ns:ReturnTotalUndesignated()),"0.00"),"-","(")," ",")")'/> 
<!--Undesignated Template for Balance Processing for payments and adjustments -->
<xsl:template match="Details/CurrentAct" mode="totalundesigamt">
<xsl:if test="substring(CAType,2,11) = 'ndesignated'">
<table-row font-size='9' font-weight='500'>
<xsl:value-of select='ns:AddUndesignated(number(translate(translate(Amount,"(","-"),")","")))'/>
<!--********************Java Script*************************************** -->
<msxsl:script language="javascript" implements-prefix="nws">
var TotalUndesignated=0;
/*For the Undesignated billing data, this function takes the input xml field Amount and totals it. 
If the amount = 0.00 the payment amount is used in the returned amount */ 
function AddUndesignated(inVal) 
var num = new Number(TotalUndesignated);
if(String(num) == '0.00' || num == 0.00)
TotalUndesignated = num+inVal; 
function ReturnTotalUndesignated()
return TotalUndesignated;
function ResetCount()
function FormatNoDollar4(inNumber) {
var NumDigitsAfterDecimal = 2;
var UseParensForNegativeNumbers = true;
var GroupDigits = true; 
var num = new Number(inNumber);
if(String(num) == "NaN" || num == 0)
return '0.00';
return num;

I would personally think that the end of the number wouldnt be assumed as a space.

Perhaps you could store the value of

<xsl:value-of select='translate(translate(format-number(ns:FormatNoDollar4(ns:ReturnTotalUndesignated()),"0.00"),"-","(")," ",")")'/>

into a local variable instead and then use a concatenation of the variable and ")" to put the final bracket on?

Its a bit messy but:


      <block text-align='far'>
        <xsl:variable name ='tempConcat'>(250.00</xsl:variable>
        <xsl:variable name='tempParanthesis'>)</xsl:variable>

        <xsl:value-of select ='concat($tempConcat, $tempParanthesis)' />



Used a second variable to store the closing parenthesis as it causes havok within the stylesheet and it also didnt like the HTML code for it. Obviously replace my temporary (250.00 (as provided in your example) with the code that generates it :)

Hi all. I applied this code format-number($x, '0.0;(0.0)') in place of the double translate code and it worked. Thanks for the reply Mikey.

Ah good to hear, mark the thread as solved if no further help is required :)