0
    var epcSum = 0;
    var labourSum = 0;
    var bvatSum = 0;
    var avatSum = 0;
    var vatSum = 0;
    var discount = 0;
    
    function addToSum(type, amount) {
        try {
            if(type=='A') epcSum += new Number(amount);
            if(type=='B') labourSum += new Number(amount);
            if(type=='C') vatSum += new Number(amount);
            if(type=='D') discount += new Number(amount);
        } catch (e) {}
        
        return '';
    }

I am not finding the way how to implement "+=" operator and using the global variable inside function . Please anybody help me to convert this javascript function to XSLT template or function.

1 Answers1

0

We need to understand the problem you are trying to solve at a higher level. You've shown us some very procedural code that relies on a function having side-effects by updating global variables. That's simply not the way a declarative, functional language like XSLT works. The XSLT code for this problem is probably easier to derive from a high-level requirements statement that from an existing low-level implementation.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164