[xsl] Convert the sign of a number

Subject: [xsl] Convert the sign of a number
From: "Daniel Newman" <daniel.newman@xxxxxxxxxxx>
Date: Thu, 5 Jul 2001 11:59:19 +0100
I've been doing some research into how to do what I want in ASP, but not
sure if this is possible in XSL.

I'm going to need to have a recursive template, that is passed a
transaction, and the previous balance.

Now lets assume I do this in VBscript, and I'll run through what each thing

sub PrintDetails(transaction, balance)
	'// print some stuff in here
	Response.write transaction	'print out this transaction
	Response.write balance		'print out the balance
	'Move to next Node(), and if it exists, perform recursion.
	Call PrintDetails(nextTransaction, balance + convertSign(balance))
end sub

function convertSign(balance)
	dim sign
	sign = sgn(balance) '1 indicates positive, -1 indicates negative
	if sign = 1 then
		convertSign = "-" & balance	'// make this positive number a negative
	elseif sign = -1 then
		convertSign = Abs(balance)	'// make this negative number a positive
number. Abs removes the - element.
	end if
end function

It's a bit messy, but the idea is sound. Transaction will be a number,
preceded by a - if it's a negative. As I'm starting with the most recent
transaction at the top, I need the balance to be calculated (it's not in the
XML!!!) based on the money in or out.

-57,500	 0
+40,000	 57,500
-14,000	 17,500
-7,500	 31,500
+2,000	 39,000
+25,000	 37,000
+12,000	 12,000

within the XML will be each of the transactions, and also the most recent

	<CurrentBalance>0</CurrentBalance> <-- I'll need to add this, but assume it
will be here!!!
		<Item id="1">
			<Description>CREST STOCK DEPOSIT</Description>

So first off, I know the transaction was to sell 57,500 shares, and my
balance is now nothing. So my previous balance must have been 0 + 57,500. So
I need to turn -57,500 into +57,500. Is this possible using XSL? I hope so,
otherwise I'm going to have to use ASP to create this html code :-(

Thanks if you can help.

Daniel Newman.
Bis-Web Ltd.
Tel: 01993 880614
Fax: 01993 881625

The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the
material from any computer.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread