473,466 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSL recursion problem

All

Hope you can help with the following..

I am using recursion to calculate the sum of
DEBT_INPUT_VALUE_BEFORE_SPLIT * CTXR_TAX_RATE elements, along the lines
of sum(a*b)

ie

xml fragment (the source doc have multiple EXPENSE segments) is as
follows

<EXPENSE>
<TABLE>TCO</TABLE>
<KEY>15000023955114</KEY>
<PROCCESSE_DATE>20060328</PROCCESSE_DATE>
<ITEM_DATE>20060209</ITEM_DATE>
<SYSTEM_DATE>20060328</SYSTEM_DATE>
<REFERENCE>L</REFERENCE>
<SUPPLIER_REFERENCE/>
<PURCHASE_ORDER_NO/>
<FILENOTE>67</FILENOTE>
<UNIT_QUANTITY/>
<UNIT_VALUE/>
<FUNCTION_TEXT/>
<PTK_TASK/>
<TRX_TYPE>CSEXP</TRX_TYPE>
<ICC_ICC>PRINT</ICC_ICC>
<ECODE>E102</ECODE>
<DEBT_INPUT_VALUE>2.81</DEBT_INPUT_VALUE>
<DEBT_INPUT_VALUE_BEFORE_SPLIT>6.7</DEBT_INPUT_VALUE_BEFORE_SPLIT>
<DEBT_OVERRIDE_VALUE>2.81</DEBT_OVERRIDE_VALUE>
<DEBT_DISCOUNT_VALUE>0.00</DEBT_DISCOUNT_VALUE>
<ACC_ACTIVITY_CATGRY/>
<CTXR_TAX_RATE>.175</CTXR_TAX_RATE>
</EXPENSE>
xsl i'm using is a single call to
<xsl:variable name="v_split_expense_tax_total">
<!-- Call to sumItems to sum (EXPENSE/DEBT_INPUT_VALUE_BEFORE_SPLIT
* EXPENSE/CTXR_TAX_RATE )-->
<xsl:call-template name="sumExpItems">
<xsl:with-param name="p_index" select=" '1' "/>
<xsl:with-param name="p_items" select="//INVOICE"/>
<xsl:with-param name="p_runningTotal" select=" '0' "/>
</xsl:call-template>
</xsl:variable>
<xsl:template name="sumExpItems">
<!--Recursive template to sum (EXPENSE/DEBT_INPUT_VALUE_BEFORE_SPLIT
* EXPENSE/CTXR_TAX_RATE )-->
<xsl:param name="p_index" select=" '1' "/>
<xsl:param name="p_items"/>
<xsl:param name="p_runningTotal" select=" '0' "/>
<xsl:variable name="v_current_item"
select="$p_items/EXPENSE[$p_index]/DEBT_INPUT_VALUE_BEFORE_SPLIT *
$p_items/EXPENSE[$p_index]/CTXR_TAX_RATE"/>
<xsl:variable name="v_remainingItems">
<xsl:choose>
<!--xsl:when test="$p_index = 4000"-->
<xsl:when test="$p_index = count($p_items/EXPENSE)">
<!--When index = count of expense items in bill ie at last item
-->
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="sumExpItems">
<xsl:with-param name="p_index" select="$p_index+1"/>
<xsl:with-param name="p_items" select="$p_items"/>
<xsl:with-param name="p_runningTotal" select="$p_runningTotal +
$v_current_item"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$v_current_item +$v_remainingItems"/>
</xsl:template>
This works when i have about 100 expense items

However my source xml has more than 4000 items and i am getting "The
XSL stack has overflowed - probable cause is infinite template
recursion.."

I'm pretty sure the recursive template does not loop infinitely as it
has an exit clause when it reaches the last EXPENSE element.

I'm using MSXML4 from xmlSpy

Anyone know

a) Is there an upper limit on number of recursion before the processor
secides its in an infinite loop.

b) can the above be made more efficient

c) any other i can get round the above..

Thanks in advance..

Will

Aug 22 '06 #1
1 1608
I don't know enough about MSXSL to be able to advise you on whether its
limit can be reset. However, in the "other ideas" category:

A non-recursive solution would be to gather all the a*b values in a
temporary document tree, and then call sum() on the result.
Unfortunately in XSLT 1.0 you'll need to use the EXSLT node-set
extension function to convert the result tree fragment into a form that
can be processed further, but that's a fairly standard nuisance.

Untested fragment just to illustrate the concept:

<xsl:variable name="products">
<xsl:for-each "//expense">
<product><xsl:value-of select="DEBT_INPUT_VALUE_BEFORE_SPLIT *
CTXR_TAX_RATE"/></product>
</xsl:for-each>
</xsl:variable>

The calculated sum-of-products is:
<xsl:value-of select="sum(exslt:node-set($products)/product)"/>
Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
10
by: paulw | last post by:
Hi Please give problems that "HAS TO" to use recursion (recursive calls to itself.) Preferrably real world examples, not knights tour. I'm thinking about eliminating the use of stack... ...
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
18
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in...
6
by: Andre Kempe | last post by:
hej folks. i have a heap with fixed size and want to determine the depth of a element with given index at compile-time. therefore i wrote some templates. however, when i use template...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
13
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
2
by: Victor Lin | last post by:
Hi, I encounter a problem with pickle. I download a html from: ...
30
by: Jeff Bigham | last post by:
So, it appears that Javascript has a recursion limit of about 1000 levels on FF, maybe less/more on other browsers. Should such deep recursion then generally be avoided in Javascript?...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.