Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2012, 01:42 PM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How To Add Parenthesis To End of Negative Number Using Translate

Hi,
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:ReturnTotalUndesign ated()),"0.00"),"-","(")," ",")")'/>



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:nws="urn:ns"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:nwsexport="urn:nsexport">
.
.
.
<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>Payment</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:ReturnTotalUndesignat ed()),"0.00"),"-","(")," ",")")'/>
</block></table-cell>
</table-row>




<!--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(transl ate(Amount,"(","-"),")","")))'/>
</table-row>
</xsl:if>
</xsl:template>





<!--********************Java Script*************************************** -->
<msxsl:script language="javascript" implements-prefix="nws">
<![CDATA[

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)
{
TotalUndesignated=TotalUndesignated+inVal;

var num = new Number(TotalUndesignated);

if(String(num) == '0.00' || num == 0.00)
TotalUndesignated = num+inVal;
}



function ReturnTotalUndesignated()
{
return TotalUndesignated;
}



function ResetCount()
{
TotalUndesignated=0;
}




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';
else
return num;
}


]]>
</msxsl:script>
</xsl:stylesheet>
 
Old August 3rd, 2012, 05:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Have you tried

Code:
format-number($x, '0.0;(0.0)')
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 8th, 2012, 04:27 PM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael - thank you so much! It is working with your suggestion and is quite a relief after spending much time on this dilema.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a line number/Row number- need to use it for page breaks naijacoder XSLT 7 September 27th, 2009 09:42 PM
Making a number negative Corey Access 1 February 2nd, 2007 11:48 AM
negative number returned when subtracting gavmc Classic ASP Basics 2 November 29th, 2005 06:34 AM
SUM operator returns a negative number cdias XSLT 7 December 31st, 2004 05:08 PM
Parenthesis - question RobMeade BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 4 August 17th, 2004 08:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.