Welcome to WebmasterWorld Guest from 54.167.213.22

Forum Moderators: open

Message Too Old, No Replies

XML issue - can it be solved with JavaScript?

     
5:01 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



I posted my issue in the XML programming forum but I haven't received an answer. I don't do much in JavaScript but I have experience with other languages. I have an issue where I am inserting values from an XML doc using XSL/Xpath, etc and I want to avoid issues where in some cases a divide by zero occurs. I would like to be able to trap those errors and instead of dividing simply display a result of zero.

Can this be done with JavaScript? Anyone with XML/XSLT and/or JavaScript experience is welcome.

Thanks
Dan

8:50 pm on Sep 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In JS, there are 'class' properties:

Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY

How you get these numbers into Javascript via XPath is another matter.


var n=3, k=0, q;

for(;k<4;k++){
q=3/(n-k);
if(q==Number.POSITIVE_INFINITY)
alert("division by zero")
else
alert(q)
}

10:29 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



I have included snippet of code to see if someone can explain how I can use a JavaScript If statement.

In psuedocode:
If XMLValueA/XMLValueB = DivideByZero
Then Display '0'
Else Display XMLValueA/XMLValueB

Here is a snippet from my xsl doc:


<td style="text-align:right;">
<xsl:value-of select="format-number(Form101_A_Value div Form101_A_Number,'$#,###,###,##0')" />
</td>

Thanks
Dan

 

Featured Threads

Hot Threads This Week

Hot Threads This Month