Hi Sassan,
You found a correct solution. Another way you can use is to create your rules as follows:
<xr:ruleset context="/Questionnaire/PartList/Part/FLN[CFLN]">
<xr:calculate target="Total" createNode="last">
<xr:value>sum(CFLN)</xr:value>
</xr:calculate>
</xr:ruleset>
In the above rule, instead of checking for the “Total” element, we look to see if there are child <CFLN> elements which indicate that a total amount needs to be calculated. Then, we let the <calculate> rule create the <Total> element by adding the createNode=”last” attribute. It gets us the same result, but you don’t have to create the <Total> element in your source document.
Regards,
Waleed
-----Original Message-----
From: xrules@yahoogroups.com
[mailto:xrules@yahoogroups.com] On Behalf Of radobject
Sent: Saturday, January 13, 2007
4:26 PM
To: xrules@yahoogroups.com
Subject: [xrules] I found ... :)
Hi,
If you want calculate some fields and set result into another xml
element but you don't know that all tag has it. You can use this
XRule.
My XML data :
<Part>
<ID>1</ID>
<FLN ID="F051601001"
<FLN ID="F051601002"
<FLN ID="F051601003"
</Part>
<Part>
<ID>2</ID>
<FLN ID="F051601004"
<CFLN ID="1">10</CFLN>
<CFLN ID="2">2</CFLN>
<CFLN ID="3">4</CFLN>
<Total/>
</FLN>
</Part>
and I wrote this XRule : (Some FLN do't have a Total tag)
<?xml version="1.0" encoding="utf-
<xr:rules xmlns:xr="http://www.xrules.
<xr:ruleset context="/Questionn
[Total='']">
<xr:calculate target="Total"
<xr:value>sum(
</xr:calculate>
</xr:ruleset>
</xr:rules>
Best regards
Sasan Nikookar