~zorba-coders/zorba/excel-module

« back to all changes in this revision

Viewing changes to src/com/zorba-xquery/www/modules/excel/math-sumproduct.xq

  • Committer: ceejatec
  • Date: 2011-05-18 23:30:51 UTC
  • Revision ID: svn-v4:8046edc3-af21-0410-8661-ec7318497eea:modules/excel/trunk:10449
Use PROJECT_SOURCE_DIR; set all eol-style to "native".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(:
2
 
 : Copyright 2006-2009 The FLWOR Foundation.
3
 
 :
4
 
 : Licensed under the Apache License, Version 2.0 (the "License");
5
 
 : you may not use this file except in compliance with the License.
6
 
 : You may obtain a copy of the License at
7
 
 :
8
 
 : http://www.apache.org/licenses/LICENSE-2.0
9
 
 :
10
 
 : Unless required by applicable law or agreed to in writing, software
11
 
 : distributed under the License is distributed on an "AS IS" BASIS,
12
 
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 : See the License for the specific language governing permissions and
14
 
 : limitations under the License.
15
 
:)
16
 
 
17
 
(:~
18
 
 : Module implementing the sumproduct functions from Excel 2003 math library.
19
 
 : There are 30 functions defined, implementing the same function
20
 
 : but with 1 to 30 parameters.
21
 
 : Each parameter can be a sequence of infinite length.
22
 
 :
23
 
 : @see <a href="http://office.microsoft.com/en-us/excel/HP052092931033.aspx"
24
 
 : target="_blank">Excel 2003 Documentation: Math-sumproduct Functions</a>
25
 
 :
26
 
 : @spec XQuery Specification: January 2007
27
 
 : @author Daniel Turcanu
28
 
 :
29
 
 :)
30
 
module namespace  excel = "http://www.zorba-xquery.com/modules/excel/math-sumproduct";
31
 
 
32
 
(:~
33
 
 : Import excel-math module functions.
34
 
:)
35
 
import module namespace excel-math = "http://www.zorba-xquery.com/modules/excel/math";
36
 
 
37
 
 
38
 
(:~
39
 
 : Sums the values in the sequence.
40
 
 : The sequence can be of any length.
41
 
 : 
42
 
 : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
43
 
 : @param $array1 the sequence of numbers or arguments castable to numeric
44
 
 : @return the sum
45
 
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
46
 
 : @example rbkt/Queries/zorba/excel/math/sumproduct1.xq
47
 
:)
48
 
declare function excel:sumproduct( $array1 as xs:anyAtomicType*) as xs:anyAtomicType
49
 
 {
50
 
   excel-math:sum( $array1 )
51
 
 };
52
 
 
53
 
(:~
54
 
 : Multiplies the elements on the same position in each sequence
55
 
 : and sums up the results.
56
 
 : 
57
 
 : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
58
 
 : @param $array1 the sequences of numbers or arguments castable to numeric
59
 
 : @param $array2 the sequences of numbers or arguments castable to numeric
60
 
 : @return the sum of products
61
 
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
62
 
 : @example rbkt/Queries/zorba/excel/math/sumproduct2.xq
63
 
:)
64
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
65
 
                                    $array2 as xs:anyAtomicType*  ) as xs:anyAtomicType
66
 
 {
67
 
    if( fn:empty($array1) or 
68
 
        fn:empty($array2)) 
69
 
        then
70
 
      0
71
 
    else
72
 
      excel-math:cast-as-numeric($array1[1]) * 
73
 
      excel-math:cast-as-numeric($array2[1]) + excel:sumproduct( fn:subsequence($array1,2),
74
 
                                                          fn:subsequence($array2,2))
75
 
 };
76
 
 
77
 
 (:~
78
 
  : Multiplies the elements on the same position in each sequence
79
 
  : and sums up the results.
80
 
  : 
81
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
82
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
83
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
84
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
85
 
  : @return the sum of products
86
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
87
 
  : @example rbkt/Queries/zorba/excel/math/sumproduct3.xq
88
 
:)
89
 
declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
90
 
                                    $array2 as xs:anyAtomicType*,
91
 
                                    $array3 as xs:anyAtomicType*  ) as xs:anyAtomicType
92
 
 {
93
 
    if( fn:empty($array1) or 
94
 
        fn:empty($array2) or
95
 
        fn:empty($array3)) 
96
 
        then
97
 
      0
98
 
    else
99
 
        excel-math:cast-as-numeric($array1[1]) * 
100
 
        excel-math:cast-as-numeric($array2[1]) * 
101
 
        excel-math:cast-as-numeric($array3[1]) +
102
 
                    excel:sumproduct(  fn:subsequence($array1,2),
103
 
                                             fn:subsequence($array2,2),
104
 
                                             fn:subsequence($array3,2))
105
 
 };
106
 
 
107
 
 (:~
108
 
  : Multiplies the elements on the same position in each sequence
109
 
  : and sums up the results.
110
 
  : 
111
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
112
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
113
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
114
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
115
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
116
 
  : @return the sum of products
117
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
118
 
:)
119
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
120
 
                                    $array2 as xs:anyAtomicType*,
121
 
                                    $array3 as xs:anyAtomicType*,
122
 
                                    $array4 as xs:anyAtomicType*  ) as xs:anyAtomicType
123
 
 {
124
 
    if( fn:empty($array1) or 
125
 
        fn:empty($array2) or
126
 
        fn:empty($array3) or
127
 
        fn:empty($array4)) 
128
 
        then
129
 
      0
130
 
    else
131
 
        excel-math:cast-as-numeric($array1[1]) * 
132
 
        excel-math:cast-as-numeric($array2[1]) * 
133
 
        excel-math:cast-as-numeric($array3[1]) * 
134
 
        excel-math:cast-as-numeric($array4[1]) +
135
 
                    excel:sumproduct(  fn:subsequence($array1,2),
136
 
                                             fn:subsequence($array2,2),
137
 
                                             fn:subsequence($array3,2),
138
 
                                             fn:subsequence($array4,2))
139
 
 };
140
 
 
141
 
 (:~
142
 
  : Multiplies the elements on the same position in each sequence
143
 
  : and sums up the results.
144
 
  : 
145
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
146
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
147
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
148
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
149
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
150
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
151
 
  : @return the sum of products
152
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
153
 
:)
154
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
155
 
                                    $array2 as xs:anyAtomicType*,
156
 
                                    $array3 as xs:anyAtomicType*,
157
 
                                    $array4 as xs:anyAtomicType*,
158
 
                                    $array5 as xs:anyAtomicType*  ) as xs:anyAtomicType
159
 
 {
160
 
    if( fn:empty($array1) or 
161
 
        fn:empty($array2) or
162
 
        fn:empty($array3) or
163
 
        fn:empty($array4) or
164
 
        fn:empty($array5)) 
165
 
        then
166
 
      0
167
 
    else
168
 
        excel-math:cast-as-numeric($array1[1]) * 
169
 
        excel-math:cast-as-numeric($array2[1]) * 
170
 
        excel-math:cast-as-numeric($array3[1]) * 
171
 
        excel-math:cast-as-numeric($array4[1]) * 
172
 
        excel-math:cast-as-numeric($array5[1]) +
173
 
                    excel:sumproduct(  fn:subsequence($array1,2),
174
 
                                             fn:subsequence($array2,2),
175
 
                                             fn:subsequence($array3,2),
176
 
                                             fn:subsequence($array4,2),
177
 
                                             fn:subsequence($array5,2))
178
 
 };
179
 
 
180
 
 (:~
181
 
  : Multiplies the elements on the same position in each sequence
182
 
  : and sums up the results.
183
 
  : 
184
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
185
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
186
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
187
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
188
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
189
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
190
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
191
 
  : @return the sum of products
192
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
193
 
:)
194
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
195
 
                                    $array2 as xs:anyAtomicType*,
196
 
                                    $array3 as xs:anyAtomicType*,
197
 
                                    $array4 as xs:anyAtomicType*,
198
 
                                    $array5 as xs:anyAtomicType*,
199
 
                                    $array6 as xs:anyAtomicType*  ) as xs:anyAtomicType
200
 
 {
201
 
    if( fn:empty($array1) or 
202
 
        fn:empty($array2) or
203
 
        fn:empty($array3) or
204
 
        fn:empty($array4) or
205
 
        fn:empty($array5) or
206
 
        fn:empty($array6)) 
207
 
        then
208
 
      0
209
 
    else
210
 
        excel-math:cast-as-numeric($array1[1]) * 
211
 
        excel-math:cast-as-numeric($array2[1]) * 
212
 
        excel-math:cast-as-numeric($array3[1]) * 
213
 
        excel-math:cast-as-numeric($array4[1]) * 
214
 
        excel-math:cast-as-numeric($array5[1]) * 
215
 
        excel-math:cast-as-numeric($array6[1]) +
216
 
                    excel:sumproduct(  fn:subsequence($array1,2),
217
 
                                             fn:subsequence($array2,2),
218
 
                                             fn:subsequence($array3,2),
219
 
                                             fn:subsequence($array4,2),
220
 
                                             fn:subsequence($array5,2),
221
 
                                             fn:subsequence($array6,2))
222
 
 };
223
 
 
224
 
 (:~
225
 
  : Multiplies the elements on the same position in each sequence
226
 
  : and sums up the results.
227
 
  : 
228
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
229
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
230
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
231
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
232
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
233
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
234
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
235
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
236
 
  : @return the sum of products
237
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
238
 
:)
239
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
240
 
                                    $array2 as xs:anyAtomicType*,
241
 
                                    $array3 as xs:anyAtomicType*,
242
 
                                    $array4 as xs:anyAtomicType*,
243
 
                                    $array5 as xs:anyAtomicType*,
244
 
                                    $array6 as xs:anyAtomicType*,
245
 
                                    $array7 as xs:anyAtomicType*  ) as xs:anyAtomicType
246
 
 {
247
 
    if( fn:empty($array1) or 
248
 
        fn:empty($array2) or
249
 
        fn:empty($array3) or
250
 
        fn:empty($array4) or
251
 
        fn:empty($array5) or
252
 
        fn:empty($array6) or
253
 
        fn:empty($array7)) 
254
 
        then
255
 
      0
256
 
    else
257
 
        excel-math:cast-as-numeric($array1[1]) * 
258
 
        excel-math:cast-as-numeric($array2[1]) * 
259
 
        excel-math:cast-as-numeric($array3[1]) * 
260
 
        excel-math:cast-as-numeric($array4[1]) * 
261
 
        excel-math:cast-as-numeric($array5[1]) * 
262
 
        excel-math:cast-as-numeric($array6[1]) * 
263
 
        excel-math:cast-as-numeric($array7[1]) +
264
 
                    excel:sumproduct(  fn:subsequence($array1,2),
265
 
                                             fn:subsequence($array2,2),
266
 
                                             fn:subsequence($array3,2),
267
 
                                             fn:subsequence($array4,2),
268
 
                                             fn:subsequence($array5,2),
269
 
                                             fn:subsequence($array6,2),
270
 
                                             fn:subsequence($array7,2))
271
 
 };
272
 
 
273
 
 (:~
274
 
  : Multiplies the elements on the same position in each sequence
275
 
  : and sums up the results.
276
 
  : 
277
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
278
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
279
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
280
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
281
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
282
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
283
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
284
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
285
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
286
 
  : @return the sum of products
287
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
288
 
:)
289
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
290
 
                                    $array2 as xs:anyAtomicType*,
291
 
                                    $array3 as xs:anyAtomicType*,
292
 
                                    $array4 as xs:anyAtomicType*,
293
 
                                    $array5 as xs:anyAtomicType*,
294
 
                                    $array6 as xs:anyAtomicType*,
295
 
                                    $array7 as xs:anyAtomicType*,
296
 
                                    $array8 as xs:anyAtomicType*  ) as xs:anyAtomicType
297
 
 {
298
 
    if( fn:empty($array1) or 
299
 
        fn:empty($array2) or
300
 
        fn:empty($array3) or
301
 
        fn:empty($array4) or
302
 
        fn:empty($array5) or
303
 
        fn:empty($array6) or
304
 
        fn:empty($array7) or
305
 
        fn:empty($array8)) 
306
 
        then
307
 
      0
308
 
    else
309
 
        excel-math:cast-as-numeric($array1[1]) * 
310
 
        excel-math:cast-as-numeric($array2[1]) * 
311
 
        excel-math:cast-as-numeric($array3[1]) * 
312
 
        excel-math:cast-as-numeric($array4[1]) * 
313
 
        excel-math:cast-as-numeric($array5[1]) * 
314
 
        excel-math:cast-as-numeric($array6[1]) * 
315
 
        excel-math:cast-as-numeric($array7[1]) * 
316
 
        excel-math:cast-as-numeric($array8[1]) +
317
 
                    excel:sumproduct(  fn:subsequence($array1,2),
318
 
                                             fn:subsequence($array2,2),
319
 
                                             fn:subsequence($array3,2),
320
 
                                             fn:subsequence($array4,2),
321
 
                                             fn:subsequence($array5,2),
322
 
                                             fn:subsequence($array6,2),
323
 
                                             fn:subsequence($array7,2),
324
 
                                             fn:subsequence($array8,2))
325
 
 };
326
 
 
327
 
 (:~
328
 
  : Multiplies the elements on the same position in each sequence
329
 
  : and sums up the results.
330
 
  : 
331
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
332
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
333
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
334
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
335
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
336
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
337
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
338
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
339
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
340
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
341
 
  : @return the sum of products
342
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
343
 
:)
344
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
345
 
                                    $array2 as xs:anyAtomicType*,
346
 
                                    $array3 as xs:anyAtomicType*,
347
 
                                    $array4 as xs:anyAtomicType*,
348
 
                                    $array5 as xs:anyAtomicType*,
349
 
                                    $array6 as xs:anyAtomicType*,
350
 
                                    $array7 as xs:anyAtomicType*,
351
 
                                    $array8 as xs:anyAtomicType*,
352
 
                                    $array9 as xs:anyAtomicType*  ) as xs:anyAtomicType
353
 
 {
354
 
    if( fn:empty($array1) or 
355
 
        fn:empty($array2) or
356
 
        fn:empty($array3) or
357
 
        fn:empty($array4) or
358
 
        fn:empty($array5) or
359
 
        fn:empty($array6) or
360
 
        fn:empty($array7) or
361
 
        fn:empty($array8) or
362
 
        fn:empty($array9)) 
363
 
        then
364
 
      0
365
 
    else
366
 
        excel-math:cast-as-numeric($array1[1]) * 
367
 
        excel-math:cast-as-numeric($array2[1]) * 
368
 
        excel-math:cast-as-numeric($array3[1]) * 
369
 
        excel-math:cast-as-numeric($array4[1]) * 
370
 
        excel-math:cast-as-numeric($array5[1]) * 
371
 
        excel-math:cast-as-numeric($array6[1]) * 
372
 
        excel-math:cast-as-numeric($array7[1]) * 
373
 
        excel-math:cast-as-numeric($array8[1]) * 
374
 
        excel-math:cast-as-numeric($array9[1]) +
375
 
                    excel:sumproduct(  fn:subsequence($array1,2),
376
 
                                             fn:subsequence($array2,2),
377
 
                                             fn:subsequence($array3,2),
378
 
                                             fn:subsequence($array4,2),
379
 
                                             fn:subsequence($array5,2),
380
 
                                             fn:subsequence($array6,2),
381
 
                                             fn:subsequence($array7,2),
382
 
                                             fn:subsequence($array8,2),
383
 
                                             fn:subsequence($array9,2))
384
 
 };
385
 
 
386
 
 (:~
387
 
  : Multiplies the elements on the same position in each sequence
388
 
  : and sums up the results.
389
 
  : 
390
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
391
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
392
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
393
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
394
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
395
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
396
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
397
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
398
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
399
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
400
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
401
 
  : @return the sum of products
402
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
403
 
:)
404
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
405
 
                                    $array2 as xs:anyAtomicType*,
406
 
                                    $array3 as xs:anyAtomicType*,
407
 
                                    $array4 as xs:anyAtomicType*,
408
 
                                    $array5 as xs:anyAtomicType*,
409
 
                                    $array6 as xs:anyAtomicType*,
410
 
                                    $array7 as xs:anyAtomicType*,
411
 
                                    $array8 as xs:anyAtomicType*,
412
 
                                    $array9 as xs:anyAtomicType*,
413
 
                                    $array10 as xs:anyAtomicType*  ) as xs:anyAtomicType
414
 
 {
415
 
    if( fn:empty($array1) or 
416
 
        fn:empty($array2) or
417
 
        fn:empty($array3) or
418
 
        fn:empty($array4) or
419
 
        fn:empty($array5) or
420
 
        fn:empty($array6) or
421
 
        fn:empty($array7) or
422
 
        fn:empty($array8) or
423
 
        fn:empty($array9) or
424
 
        fn:empty($array10)) 
425
 
        then
426
 
      0
427
 
    else
428
 
        excel-math:cast-as-numeric($array1[1]) * 
429
 
        excel-math:cast-as-numeric($array2[1]) * 
430
 
        excel-math:cast-as-numeric($array3[1]) * 
431
 
        excel-math:cast-as-numeric($array4[1]) * 
432
 
        excel-math:cast-as-numeric($array5[1]) * 
433
 
        excel-math:cast-as-numeric($array6[1]) * 
434
 
        excel-math:cast-as-numeric($array7[1]) * 
435
 
        excel-math:cast-as-numeric($array8[1]) * 
436
 
        excel-math:cast-as-numeric($array9[1]) * 
437
 
        excel-math:cast-as-numeric($array10[1]) +
438
 
                    excel:sumproduct(  fn:subsequence($array1,2),
439
 
                                             fn:subsequence($array2,2),
440
 
                                             fn:subsequence($array3,2),
441
 
                                             fn:subsequence($array4,2),
442
 
                                             fn:subsequence($array5,2),
443
 
                                             fn:subsequence($array6,2),
444
 
                                             fn:subsequence($array7,2),
445
 
                                             fn:subsequence($array8,2),
446
 
                                             fn:subsequence($array9,2),
447
 
                                             fn:subsequence($array10,2))
448
 
 };
449
 
 
450
 
 (:~
451
 
  : Multiplies the elements on the same position in each sequence
452
 
  : and sums up the results.
453
 
  : 
454
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
455
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
456
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
457
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
458
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
459
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
460
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
461
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
462
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
463
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
464
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
465
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
466
 
  : @return the sum of products
467
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
468
 
:)
469
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
470
 
                                    $array2 as xs:anyAtomicType*,
471
 
                                    $array3 as xs:anyAtomicType*,
472
 
                                    $array4 as xs:anyAtomicType*,
473
 
                                    $array5 as xs:anyAtomicType*,
474
 
                                    $array6 as xs:anyAtomicType*,
475
 
                                    $array7 as xs:anyAtomicType*,
476
 
                                    $array8 as xs:anyAtomicType*,
477
 
                                    $array9 as xs:anyAtomicType*,
478
 
                                    $array10 as xs:anyAtomicType*,
479
 
                                    $array11 as xs:anyAtomicType*  ) as xs:anyAtomicType
480
 
 {
481
 
    if( fn:empty($array1) or 
482
 
        fn:empty($array2) or
483
 
        fn:empty($array3) or
484
 
        fn:empty($array4) or
485
 
        fn:empty($array5) or
486
 
        fn:empty($array6) or
487
 
        fn:empty($array7) or
488
 
        fn:empty($array8) or
489
 
        fn:empty($array9) or
490
 
        fn:empty($array10) or
491
 
        fn:empty($array11)) 
492
 
        then
493
 
      0
494
 
    else
495
 
        excel-math:cast-as-numeric($array1[1]) * 
496
 
        excel-math:cast-as-numeric($array2[1]) * 
497
 
        excel-math:cast-as-numeric($array3[1]) * 
498
 
        excel-math:cast-as-numeric($array4[1]) * 
499
 
        excel-math:cast-as-numeric($array5[1]) * 
500
 
        excel-math:cast-as-numeric($array6[1]) * 
501
 
        excel-math:cast-as-numeric($array7[1]) * 
502
 
        excel-math:cast-as-numeric($array8[1]) * 
503
 
        excel-math:cast-as-numeric($array9[1]) * 
504
 
        excel-math:cast-as-numeric($array10[1]) * 
505
 
        excel-math:cast-as-numeric($array11[1]) +
506
 
                    excel:sumproduct(  fn:subsequence($array1,2),
507
 
                                             fn:subsequence($array2,2),
508
 
                                             fn:subsequence($array3,2),
509
 
                                             fn:subsequence($array4,2),
510
 
                                             fn:subsequence($array5,2),
511
 
                                             fn:subsequence($array6,2),
512
 
                                             fn:subsequence($array7,2),
513
 
                                             fn:subsequence($array8,2),
514
 
                                             fn:subsequence($array9,2),
515
 
                                             fn:subsequence($array10,2),
516
 
                                             fn:subsequence($array11,2))
517
 
 };
518
 
 
519
 
 (:~
520
 
  : Multiplies the elements on the same position in each sequence
521
 
  : and sums up the results.
522
 
  : 
523
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
524
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
525
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
526
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
527
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
528
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
529
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
530
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
531
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
532
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
533
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
534
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
535
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
536
 
  : @return the sum of products
537
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
538
 
:)
539
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
540
 
                                    $array2 as xs:anyAtomicType*,
541
 
                                    $array3 as xs:anyAtomicType*,
542
 
                                    $array4 as xs:anyAtomicType*,
543
 
                                    $array5 as xs:anyAtomicType*,
544
 
                                    $array6 as xs:anyAtomicType*,
545
 
                                    $array7 as xs:anyAtomicType*,
546
 
                                    $array8 as xs:anyAtomicType*,
547
 
                                    $array9 as xs:anyAtomicType*,
548
 
                                    $array10 as xs:anyAtomicType*,
549
 
                                    $array11 as xs:anyAtomicType*,
550
 
                                    $array12 as xs:anyAtomicType*  ) as xs:anyAtomicType
551
 
 {
552
 
    if( fn:empty($array1) or 
553
 
        fn:empty($array2) or
554
 
        fn:empty($array3) or
555
 
        fn:empty($array4) or
556
 
        fn:empty($array5) or
557
 
        fn:empty($array6) or
558
 
        fn:empty($array7) or
559
 
        fn:empty($array8) or
560
 
        fn:empty($array9) or
561
 
        fn:empty($array10) or
562
 
        fn:empty($array11) or
563
 
        fn:empty($array12)) 
564
 
        then
565
 
      0
566
 
    else
567
 
        excel-math:cast-as-numeric($array1[1]) * 
568
 
        excel-math:cast-as-numeric($array2[1]) * 
569
 
        excel-math:cast-as-numeric($array3[1]) * 
570
 
        excel-math:cast-as-numeric($array4[1]) * 
571
 
        excel-math:cast-as-numeric($array5[1]) * 
572
 
        excel-math:cast-as-numeric($array6[1]) * 
573
 
        excel-math:cast-as-numeric($array7[1]) * 
574
 
        excel-math:cast-as-numeric($array8[1]) * 
575
 
        excel-math:cast-as-numeric($array9[1]) * 
576
 
        excel-math:cast-as-numeric($array10[1]) * 
577
 
        excel-math:cast-as-numeric($array11[1]) * 
578
 
        excel-math:cast-as-numeric($array12[1]) +
579
 
                    excel:sumproduct(  fn:subsequence($array1,2),
580
 
                                             fn:subsequence($array2,2),
581
 
                                             fn:subsequence($array3,2),
582
 
                                             fn:subsequence($array4,2),
583
 
                                             fn:subsequence($array5,2),
584
 
                                             fn:subsequence($array6,2),
585
 
                                             fn:subsequence($array7,2),
586
 
                                             fn:subsequence($array8,2),
587
 
                                             fn:subsequence($array9,2),
588
 
                                             fn:subsequence($array10,2),
589
 
                                             fn:subsequence($array11,2),
590
 
                                             fn:subsequence($array12,2))
591
 
 };
592
 
 
593
 
 
594
 
 (:~
595
 
  : Multiplies the elements on the same position in each sequence
596
 
  : and sums up the results.
597
 
  : 
598
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
599
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
600
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
601
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
602
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
603
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
604
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
605
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
606
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
607
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
608
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
609
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
610
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
611
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
612
 
  : @return the sum of products
613
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
614
 
:)
615
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
616
 
                                    $array2 as xs:anyAtomicType*,
617
 
                                    $array3 as xs:anyAtomicType*,
618
 
                                    $array4 as xs:anyAtomicType*,
619
 
                                    $array5 as xs:anyAtomicType*,
620
 
                                    $array6 as xs:anyAtomicType*,
621
 
                                    $array7 as xs:anyAtomicType*,
622
 
                                    $array8 as xs:anyAtomicType*,
623
 
                                    $array9 as xs:anyAtomicType*,
624
 
                                    $array10 as xs:anyAtomicType*,
625
 
                                    $array11 as xs:anyAtomicType*,
626
 
                                    $array12 as xs:anyAtomicType*,
627
 
                                    $array13 as xs:anyAtomicType*  ) as xs:anyAtomicType
628
 
 {
629
 
    if( fn:empty($array1) or 
630
 
        fn:empty($array2) or
631
 
        fn:empty($array3) or
632
 
        fn:empty($array4) or
633
 
        fn:empty($array5) or
634
 
        fn:empty($array6) or
635
 
        fn:empty($array7) or
636
 
        fn:empty($array8) or
637
 
        fn:empty($array9) or
638
 
        fn:empty($array10) or
639
 
        fn:empty($array11) or
640
 
        fn:empty($array12) or
641
 
        fn:empty($array13)) 
642
 
        then
643
 
      0
644
 
    else
645
 
        excel-math:cast-as-numeric($array1[1]) * 
646
 
        excel-math:cast-as-numeric($array2[1]) * 
647
 
        excel-math:cast-as-numeric($array3[1]) * 
648
 
        excel-math:cast-as-numeric($array4[1]) * 
649
 
        excel-math:cast-as-numeric($array5[1]) * 
650
 
        excel-math:cast-as-numeric($array6[1]) * 
651
 
        excel-math:cast-as-numeric($array7[1]) * 
652
 
        excel-math:cast-as-numeric($array8[1]) * 
653
 
        excel-math:cast-as-numeric($array9[1]) * 
654
 
        excel-math:cast-as-numeric($array10[1]) * 
655
 
        excel-math:cast-as-numeric($array11[1]) * 
656
 
        excel-math:cast-as-numeric($array12[1]) * 
657
 
        excel-math:cast-as-numeric($array13[1]) +
658
 
                    excel:sumproduct(  fn:subsequence($array1,2),
659
 
                                             fn:subsequence($array2,2),
660
 
                                             fn:subsequence($array3,2),
661
 
                                             fn:subsequence($array4,2),
662
 
                                             fn:subsequence($array5,2),
663
 
                                             fn:subsequence($array6,2),
664
 
                                             fn:subsequence($array7,2),
665
 
                                             fn:subsequence($array8,2),
666
 
                                             fn:subsequence($array9,2),
667
 
                                             fn:subsequence($array10,2),
668
 
                                             fn:subsequence($array11,2),
669
 
                                             fn:subsequence($array12,2),
670
 
                                             fn:subsequence($array13,2))
671
 
 };
672
 
 
673
 
 (:~
674
 
  : Multiplies the elements on the same position in each sequence
675
 
  : and sums up the results.
676
 
  : 
677
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
678
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
679
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
680
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
681
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
682
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
683
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
684
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
685
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
686
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
687
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
688
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
689
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
690
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
691
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
692
 
  : @return the sum of products
693
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
694
 
:)
695
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
696
 
                                    $array2 as xs:anyAtomicType*,
697
 
                                    $array3 as xs:anyAtomicType*,
698
 
                                    $array4 as xs:anyAtomicType*,
699
 
                                    $array5 as xs:anyAtomicType*,
700
 
                                    $array6 as xs:anyAtomicType*,
701
 
                                    $array7 as xs:anyAtomicType*,
702
 
                                    $array8 as xs:anyAtomicType*,
703
 
                                    $array9 as xs:anyAtomicType*,
704
 
                                    $array10 as xs:anyAtomicType*,
705
 
                                    $array11 as xs:anyAtomicType*,
706
 
                                    $array12 as xs:anyAtomicType*,
707
 
                                    $array13 as xs:anyAtomicType*,
708
 
                                    $array14 as xs:anyAtomicType*  ) as xs:anyAtomicType
709
 
 {
710
 
    if( fn:empty($array1) or 
711
 
        fn:empty($array2) or
712
 
        fn:empty($array3) or
713
 
        fn:empty($array4) or
714
 
        fn:empty($array5) or
715
 
        fn:empty($array6) or
716
 
        fn:empty($array7) or
717
 
        fn:empty($array8) or
718
 
        fn:empty($array9) or
719
 
        fn:empty($array10) or
720
 
        fn:empty($array11) or
721
 
        fn:empty($array12) or
722
 
        fn:empty($array13) or
723
 
        fn:empty($array14)) 
724
 
        then
725
 
      0
726
 
    else
727
 
        excel-math:cast-as-numeric($array1[1]) * 
728
 
        excel-math:cast-as-numeric($array2[1]) * 
729
 
        excel-math:cast-as-numeric($array3[1]) * 
730
 
        excel-math:cast-as-numeric($array4[1]) * 
731
 
        excel-math:cast-as-numeric($array5[1]) * 
732
 
        excel-math:cast-as-numeric($array6[1]) * 
733
 
        excel-math:cast-as-numeric($array7[1]) * 
734
 
        excel-math:cast-as-numeric($array8[1]) * 
735
 
        excel-math:cast-as-numeric($array9[1]) * 
736
 
        excel-math:cast-as-numeric($array10[1]) * 
737
 
        excel-math:cast-as-numeric($array11[1]) * 
738
 
        excel-math:cast-as-numeric($array12[1]) * 
739
 
        excel-math:cast-as-numeric($array13[1]) * 
740
 
        excel-math:cast-as-numeric($array14[1]) +
741
 
                    excel:sumproduct(  fn:subsequence($array1,2),
742
 
                                             fn:subsequence($array2,2),
743
 
                                             fn:subsequence($array3,2),
744
 
                                             fn:subsequence($array4,2),
745
 
                                             fn:subsequence($array5,2),
746
 
                                             fn:subsequence($array6,2),
747
 
                                             fn:subsequence($array7,2),
748
 
                                             fn:subsequence($array8,2),
749
 
                                             fn:subsequence($array9,2),
750
 
                                             fn:subsequence($array10,2),
751
 
                                             fn:subsequence($array11,2),
752
 
                                             fn:subsequence($array12,2),
753
 
                                             fn:subsequence($array13,2),
754
 
                                             fn:subsequence($array14,2))
755
 
 };
756
 
 
757
 
 (:~
758
 
  : Multiplies the elements on the same position in each sequence
759
 
  : and sums up the results.
760
 
  : 
761
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
762
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
763
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
764
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
765
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
766
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
767
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
768
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
769
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
770
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
771
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
772
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
773
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
774
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
775
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
776
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
777
 
  : @return the sum of products
778
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
779
 
:)
780
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
781
 
                                    $array2 as xs:anyAtomicType*,
782
 
                                    $array3 as xs:anyAtomicType*,
783
 
                                    $array4 as xs:anyAtomicType*,
784
 
                                    $array5 as xs:anyAtomicType*,
785
 
                                    $array6 as xs:anyAtomicType*,
786
 
                                    $array7 as xs:anyAtomicType*,
787
 
                                    $array8 as xs:anyAtomicType*,
788
 
                                    $array9 as xs:anyAtomicType*,
789
 
                                    $array10 as xs:anyAtomicType*,
790
 
                                    $array11 as xs:anyAtomicType*,
791
 
                                    $array12 as xs:anyAtomicType*,
792
 
                                    $array13 as xs:anyAtomicType*,
793
 
                                    $array14 as xs:anyAtomicType*,
794
 
                                    $array15 as xs:anyAtomicType*  ) as xs:anyAtomicType
795
 
 {
796
 
    if( fn:empty($array1) or 
797
 
        fn:empty($array2) or
798
 
        fn:empty($array3) or
799
 
        fn:empty($array4) or
800
 
        fn:empty($array5) or
801
 
        fn:empty($array6) or
802
 
        fn:empty($array7) or
803
 
        fn:empty($array8) or
804
 
        fn:empty($array9) or
805
 
        fn:empty($array10) or
806
 
        fn:empty($array11) or
807
 
        fn:empty($array12) or
808
 
        fn:empty($array13) or
809
 
        fn:empty($array14) or
810
 
        fn:empty($array15)) 
811
 
        then
812
 
      0
813
 
    else
814
 
        excel-math:cast-as-numeric($array1[1]) * 
815
 
        excel-math:cast-as-numeric($array2[1]) * 
816
 
        excel-math:cast-as-numeric($array3[1]) * 
817
 
        excel-math:cast-as-numeric($array4[1]) * 
818
 
        excel-math:cast-as-numeric($array5[1]) * 
819
 
        excel-math:cast-as-numeric($array6[1]) * 
820
 
        excel-math:cast-as-numeric($array7[1]) * 
821
 
        excel-math:cast-as-numeric($array8[1]) * 
822
 
        excel-math:cast-as-numeric($array9[1]) * 
823
 
        excel-math:cast-as-numeric($array10[1]) * 
824
 
        excel-math:cast-as-numeric($array11[1]) * 
825
 
        excel-math:cast-as-numeric($array12[1]) * 
826
 
        excel-math:cast-as-numeric($array13[1]) * 
827
 
        excel-math:cast-as-numeric($array14[1]) * 
828
 
        excel-math:cast-as-numeric($array15[1]) +
829
 
                    excel:sumproduct(  fn:subsequence($array1,2),
830
 
                                             fn:subsequence($array2,2),
831
 
                                             fn:subsequence($array3,2),
832
 
                                             fn:subsequence($array4,2),
833
 
                                             fn:subsequence($array5,2),
834
 
                                             fn:subsequence($array6,2),
835
 
                                             fn:subsequence($array7,2),
836
 
                                             fn:subsequence($array8,2),
837
 
                                             fn:subsequence($array9,2),
838
 
                                             fn:subsequence($array10,2),
839
 
                                             fn:subsequence($array11,2),
840
 
                                             fn:subsequence($array12,2),
841
 
                                             fn:subsequence($array13,2),
842
 
                                             fn:subsequence($array14,2),
843
 
                                             fn:subsequence($array15,2))
844
 
 };
845
 
 
846
 
 (:~
847
 
  : Multiplies the elements on the same position in each sequence
848
 
  : and sums up the results.
849
 
  : 
850
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
851
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
852
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
853
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
854
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
855
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
856
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
857
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
858
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
859
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
860
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
861
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
862
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
863
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
864
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
865
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
866
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
867
 
  : @return the sum of products
868
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
869
 
:)
870
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
871
 
                                    $array2 as xs:anyAtomicType*,
872
 
                                    $array3 as xs:anyAtomicType*,
873
 
                                    $array4 as xs:anyAtomicType*,
874
 
                                    $array5 as xs:anyAtomicType*,
875
 
                                    $array6 as xs:anyAtomicType*,
876
 
                                    $array7 as xs:anyAtomicType*,
877
 
                                    $array8 as xs:anyAtomicType*,
878
 
                                    $array9 as xs:anyAtomicType*,
879
 
                                    $array10 as xs:anyAtomicType*,
880
 
                                    $array11 as xs:anyAtomicType*,
881
 
                                    $array12 as xs:anyAtomicType*,
882
 
                                    $array13 as xs:anyAtomicType*,
883
 
                                    $array14 as xs:anyAtomicType*,
884
 
                                    $array15 as xs:anyAtomicType*,
885
 
                                    $array16 as xs:anyAtomicType*  ) as xs:anyAtomicType
886
 
 {
887
 
    if( fn:empty($array1) or 
888
 
        fn:empty($array2) or
889
 
        fn:empty($array3) or
890
 
        fn:empty($array4) or
891
 
        fn:empty($array5) or
892
 
        fn:empty($array6) or
893
 
        fn:empty($array7) or
894
 
        fn:empty($array8) or
895
 
        fn:empty($array9) or
896
 
        fn:empty($array10) or
897
 
        fn:empty($array11) or
898
 
        fn:empty($array12) or
899
 
        fn:empty($array13) or
900
 
        fn:empty($array14) or
901
 
        fn:empty($array15) or
902
 
        fn:empty($array16)) 
903
 
        then
904
 
      0
905
 
    else
906
 
        excel-math:cast-as-numeric($array1[1]) * 
907
 
        excel-math:cast-as-numeric($array2[1]) * 
908
 
        excel-math:cast-as-numeric($array3[1]) * 
909
 
        excel-math:cast-as-numeric($array4[1]) * 
910
 
        excel-math:cast-as-numeric($array5[1]) * 
911
 
        excel-math:cast-as-numeric($array6[1]) * 
912
 
        excel-math:cast-as-numeric($array7[1]) * 
913
 
        excel-math:cast-as-numeric($array8[1]) * 
914
 
        excel-math:cast-as-numeric($array9[1]) * 
915
 
        excel-math:cast-as-numeric($array10[1]) * 
916
 
        excel-math:cast-as-numeric($array11[1]) * 
917
 
        excel-math:cast-as-numeric($array12[1]) * 
918
 
        excel-math:cast-as-numeric($array13[1]) * 
919
 
        excel-math:cast-as-numeric($array14[1]) * 
920
 
        excel-math:cast-as-numeric($array15[1]) * 
921
 
        excel-math:cast-as-numeric($array16[1]) +
922
 
                    excel:sumproduct(  fn:subsequence($array1,2),
923
 
                                             fn:subsequence($array2,2),
924
 
                                             fn:subsequence($array3,2),
925
 
                                             fn:subsequence($array4,2),
926
 
                                             fn:subsequence($array5,2),
927
 
                                             fn:subsequence($array6,2),
928
 
                                             fn:subsequence($array7,2),
929
 
                                             fn:subsequence($array8,2),
930
 
                                             fn:subsequence($array9,2),
931
 
                                             fn:subsequence($array10,2),
932
 
                                             fn:subsequence($array11,2),
933
 
                                             fn:subsequence($array12,2),
934
 
                                             fn:subsequence($array13,2),
935
 
                                             fn:subsequence($array14,2),
936
 
                                             fn:subsequence($array15,2),
937
 
                                             fn:subsequence($array16,2))
938
 
 };
939
 
 
940
 
 (:~
941
 
  : Multiplies the elements on the same position in each sequence
942
 
  : and sums up the results.
943
 
  : 
944
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
945
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
946
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
947
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
948
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
949
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
950
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
951
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
952
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
953
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
954
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
955
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
956
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
957
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
958
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
959
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
960
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
961
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
962
 
  : @return the sum of products
963
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
964
 
:)
965
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
966
 
                                    $array2 as xs:anyAtomicType*,
967
 
                                    $array3 as xs:anyAtomicType*,
968
 
                                    $array4 as xs:anyAtomicType*,
969
 
                                    $array5 as xs:anyAtomicType*,
970
 
                                    $array6 as xs:anyAtomicType*,
971
 
                                    $array7 as xs:anyAtomicType*,
972
 
                                    $array8 as xs:anyAtomicType*,
973
 
                                    $array9 as xs:anyAtomicType*,
974
 
                                    $array10 as xs:anyAtomicType*,
975
 
                                    $array11 as xs:anyAtomicType*,
976
 
                                    $array12 as xs:anyAtomicType*,
977
 
                                    $array13 as xs:anyAtomicType*,
978
 
                                    $array14 as xs:anyAtomicType*,
979
 
                                    $array15 as xs:anyAtomicType*,
980
 
                                    $array16 as xs:anyAtomicType*,
981
 
                                    $array17 as xs:anyAtomicType*  ) as xs:anyAtomicType
982
 
 {
983
 
    if( fn:empty($array1) or 
984
 
        fn:empty($array2) or
985
 
        fn:empty($array3) or
986
 
        fn:empty($array4) or
987
 
        fn:empty($array5) or
988
 
        fn:empty($array6) or
989
 
        fn:empty($array7) or
990
 
        fn:empty($array8) or
991
 
        fn:empty($array9) or
992
 
        fn:empty($array10) or
993
 
        fn:empty($array11) or
994
 
        fn:empty($array12) or
995
 
        fn:empty($array13) or
996
 
        fn:empty($array14) or
997
 
        fn:empty($array15) or
998
 
        fn:empty($array16) or
999
 
        fn:empty($array17)) 
1000
 
        then
1001
 
      0
1002
 
    else
1003
 
        excel-math:cast-as-numeric($array1[1]) * 
1004
 
        excel-math:cast-as-numeric($array2[1]) * 
1005
 
        excel-math:cast-as-numeric($array3[1]) * 
1006
 
        excel-math:cast-as-numeric($array4[1]) * 
1007
 
        excel-math:cast-as-numeric($array5[1]) * 
1008
 
        excel-math:cast-as-numeric($array6[1]) * 
1009
 
        excel-math:cast-as-numeric($array7[1]) * 
1010
 
        excel-math:cast-as-numeric($array8[1]) * 
1011
 
        excel-math:cast-as-numeric($array9[1]) * 
1012
 
        excel-math:cast-as-numeric($array10[1]) * 
1013
 
        excel-math:cast-as-numeric($array11[1]) * 
1014
 
        excel-math:cast-as-numeric($array12[1]) * 
1015
 
        excel-math:cast-as-numeric($array13[1]) * 
1016
 
        excel-math:cast-as-numeric($array14[1]) * 
1017
 
        excel-math:cast-as-numeric($array15[1]) * 
1018
 
        excel-math:cast-as-numeric($array16[1]) * 
1019
 
        excel-math:cast-as-numeric($array17[1]) +
1020
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1021
 
                                             fn:subsequence($array2,2),
1022
 
                                             fn:subsequence($array3,2),
1023
 
                                             fn:subsequence($array4,2),
1024
 
                                             fn:subsequence($array5,2),
1025
 
                                             fn:subsequence($array6,2),
1026
 
                                             fn:subsequence($array7,2),
1027
 
                                             fn:subsequence($array8,2),
1028
 
                                             fn:subsequence($array9,2),
1029
 
                                             fn:subsequence($array10,2),
1030
 
                                             fn:subsequence($array11,2),
1031
 
                                             fn:subsequence($array12,2),
1032
 
                                             fn:subsequence($array13,2),
1033
 
                                             fn:subsequence($array14,2),
1034
 
                                             fn:subsequence($array15,2),
1035
 
                                             fn:subsequence($array16,2),
1036
 
                                             fn:subsequence($array17,2))
1037
 
 };
1038
 
 
1039
 
 (:~
1040
 
  : Multiplies the elements on the same position in each sequence
1041
 
  : and sums up the results.
1042
 
  : 
1043
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1044
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1045
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1046
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1047
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1048
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1049
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1050
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1051
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1052
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1053
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1054
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1055
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1056
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1057
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1058
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1059
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1060
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1061
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1062
 
  : @return the sum of products
1063
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1064
 
:)
1065
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1066
 
                                    $array2 as xs:anyAtomicType*,
1067
 
                                    $array3 as xs:anyAtomicType*,
1068
 
                                    $array4 as xs:anyAtomicType*,
1069
 
                                    $array5 as xs:anyAtomicType*,
1070
 
                                    $array6 as xs:anyAtomicType*,
1071
 
                                    $array7 as xs:anyAtomicType*,
1072
 
                                    $array8 as xs:anyAtomicType*,
1073
 
                                    $array9 as xs:anyAtomicType*,
1074
 
                                    $array10 as xs:anyAtomicType*,
1075
 
                                    $array11 as xs:anyAtomicType*,
1076
 
                                    $array12 as xs:anyAtomicType*,
1077
 
                                    $array13 as xs:anyAtomicType*,
1078
 
                                    $array14 as xs:anyAtomicType*,
1079
 
                                    $array15 as xs:anyAtomicType*,
1080
 
                                    $array16 as xs:anyAtomicType*,
1081
 
                                    $array17 as xs:anyAtomicType*,
1082
 
                                    $array18 as xs:anyAtomicType*  ) as xs:anyAtomicType
1083
 
 {
1084
 
    if( fn:empty($array1) or 
1085
 
        fn:empty($array2) or
1086
 
        fn:empty($array3) or
1087
 
        fn:empty($array4) or
1088
 
        fn:empty($array5) or
1089
 
        fn:empty($array6) or
1090
 
        fn:empty($array7) or
1091
 
        fn:empty($array8) or
1092
 
        fn:empty($array9) or
1093
 
        fn:empty($array10) or
1094
 
        fn:empty($array11) or
1095
 
        fn:empty($array12) or
1096
 
        fn:empty($array13) or
1097
 
        fn:empty($array14) or
1098
 
        fn:empty($array15) or
1099
 
        fn:empty($array16) or
1100
 
        fn:empty($array17) or
1101
 
        fn:empty($array18)) 
1102
 
        then
1103
 
      0
1104
 
    else
1105
 
        excel-math:cast-as-numeric($array1[1]) * 
1106
 
        excel-math:cast-as-numeric($array2[1]) * 
1107
 
        excel-math:cast-as-numeric($array3[1]) * 
1108
 
        excel-math:cast-as-numeric($array4[1]) * 
1109
 
        excel-math:cast-as-numeric($array5[1]) * 
1110
 
        excel-math:cast-as-numeric($array6[1]) * 
1111
 
        excel-math:cast-as-numeric($array7[1]) * 
1112
 
        excel-math:cast-as-numeric($array8[1]) * 
1113
 
        excel-math:cast-as-numeric($array9[1]) * 
1114
 
        excel-math:cast-as-numeric($array10[1]) * 
1115
 
        excel-math:cast-as-numeric($array11[1]) * 
1116
 
        excel-math:cast-as-numeric($array12[1]) * 
1117
 
        excel-math:cast-as-numeric($array13[1]) * 
1118
 
        excel-math:cast-as-numeric($array14[1]) * 
1119
 
        excel-math:cast-as-numeric($array15[1]) * 
1120
 
        excel-math:cast-as-numeric($array16[1]) * 
1121
 
        excel-math:cast-as-numeric($array17[1]) * 
1122
 
        excel-math:cast-as-numeric($array18[1]) +
1123
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1124
 
                                             fn:subsequence($array2,2),
1125
 
                                             fn:subsequence($array3,2),
1126
 
                                             fn:subsequence($array4,2),
1127
 
                                             fn:subsequence($array5,2),
1128
 
                                             fn:subsequence($array6,2),
1129
 
                                             fn:subsequence($array7,2),
1130
 
                                             fn:subsequence($array8,2),
1131
 
                                             fn:subsequence($array9,2),
1132
 
                                             fn:subsequence($array10,2),
1133
 
                                             fn:subsequence($array11,2),
1134
 
                                             fn:subsequence($array12,2),
1135
 
                                             fn:subsequence($array13,2),
1136
 
                                             fn:subsequence($array14,2),
1137
 
                                             fn:subsequence($array15,2),
1138
 
                                             fn:subsequence($array16,2),
1139
 
                                             fn:subsequence($array17,2),
1140
 
                                             fn:subsequence($array18,2))
1141
 
 };
1142
 
 
1143
 
 (:~
1144
 
  : Multiplies the elements on the same position in each sequence
1145
 
  : and sums up the results.
1146
 
  : 
1147
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1148
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1149
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1150
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1151
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1152
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1153
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1154
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1155
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1156
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1157
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1158
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1159
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1160
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1161
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1162
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1163
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1164
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1165
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1166
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1167
 
  : @return the sum of products
1168
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1169
 
:)
1170
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1171
 
                                    $array2 as xs:anyAtomicType*,
1172
 
                                    $array3 as xs:anyAtomicType*,
1173
 
                                    $array4 as xs:anyAtomicType*,
1174
 
                                    $array5 as xs:anyAtomicType*,
1175
 
                                    $array6 as xs:anyAtomicType*,
1176
 
                                    $array7 as xs:anyAtomicType*,
1177
 
                                    $array8 as xs:anyAtomicType*,
1178
 
                                    $array9 as xs:anyAtomicType*,
1179
 
                                    $array10 as xs:anyAtomicType*,
1180
 
                                    $array11 as xs:anyAtomicType*,
1181
 
                                    $array12 as xs:anyAtomicType*,
1182
 
                                    $array13 as xs:anyAtomicType*,
1183
 
                                    $array14 as xs:anyAtomicType*,
1184
 
                                    $array15 as xs:anyAtomicType*,
1185
 
                                    $array16 as xs:anyAtomicType*,
1186
 
                                    $array17 as xs:anyAtomicType*,
1187
 
                                    $array18 as xs:anyAtomicType*,
1188
 
                                    $array19 as xs:anyAtomicType*  ) as xs:anyAtomicType
1189
 
 {
1190
 
    if( fn:empty($array1) or 
1191
 
        fn:empty($array2) or
1192
 
        fn:empty($array3) or
1193
 
        fn:empty($array4) or
1194
 
        fn:empty($array5) or
1195
 
        fn:empty($array6) or
1196
 
        fn:empty($array7) or
1197
 
        fn:empty($array8) or
1198
 
        fn:empty($array9) or
1199
 
        fn:empty($array10) or
1200
 
        fn:empty($array11) or
1201
 
        fn:empty($array12) or
1202
 
        fn:empty($array13) or
1203
 
        fn:empty($array14) or
1204
 
        fn:empty($array15) or
1205
 
        fn:empty($array16) or
1206
 
        fn:empty($array17) or
1207
 
        fn:empty($array18) or
1208
 
        fn:empty($array19)) 
1209
 
        then
1210
 
      0
1211
 
    else
1212
 
        excel-math:cast-as-numeric($array1[1]) * 
1213
 
        excel-math:cast-as-numeric($array2[1]) * 
1214
 
        excel-math:cast-as-numeric($array3[1]) * 
1215
 
        excel-math:cast-as-numeric($array4[1]) * 
1216
 
        excel-math:cast-as-numeric($array5[1]) * 
1217
 
        excel-math:cast-as-numeric($array6[1]) * 
1218
 
        excel-math:cast-as-numeric($array7[1]) * 
1219
 
        excel-math:cast-as-numeric($array8[1]) * 
1220
 
        excel-math:cast-as-numeric($array9[1]) * 
1221
 
        excel-math:cast-as-numeric($array10[1]) * 
1222
 
        excel-math:cast-as-numeric($array11[1]) * 
1223
 
        excel-math:cast-as-numeric($array12[1]) * 
1224
 
        excel-math:cast-as-numeric($array13[1]) * 
1225
 
        excel-math:cast-as-numeric($array14[1]) * 
1226
 
        excel-math:cast-as-numeric($array15[1]) * 
1227
 
        excel-math:cast-as-numeric($array16[1]) * 
1228
 
        excel-math:cast-as-numeric($array17[1]) * 
1229
 
        excel-math:cast-as-numeric($array18[1]) *
1230
 
        excel-math:cast-as-numeric($array19[1]) +
1231
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1232
 
                                             fn:subsequence($array2,2),
1233
 
                                             fn:subsequence($array3,2),
1234
 
                                             fn:subsequence($array4,2),
1235
 
                                             fn:subsequence($array5,2),
1236
 
                                             fn:subsequence($array6,2),
1237
 
                                             fn:subsequence($array7,2),
1238
 
                                             fn:subsequence($array8,2),
1239
 
                                             fn:subsequence($array9,2),
1240
 
                                             fn:subsequence($array10,2),
1241
 
                                             fn:subsequence($array11,2),
1242
 
                                             fn:subsequence($array12,2),
1243
 
                                             fn:subsequence($array13,2),
1244
 
                                             fn:subsequence($array14,2),
1245
 
                                             fn:subsequence($array15,2),
1246
 
                                             fn:subsequence($array16,2),
1247
 
                                             fn:subsequence($array17,2),
1248
 
                                             fn:subsequence($array18,2),
1249
 
                                             fn:subsequence($array19,2))
1250
 
 };
1251
 
  
1252
 
 (:~
1253
 
  : Multiplies the elements on the same position in each sequence
1254
 
  : and sums up the results.
1255
 
  : 
1256
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1257
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1258
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1259
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1260
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1261
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1262
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1263
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1264
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1265
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1266
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1267
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1268
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1269
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1270
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1271
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1272
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1273
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1274
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1275
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1276
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1277
 
  : @return the sum of products
1278
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1279
 
:)
1280
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1281
 
                                    $array2 as xs:anyAtomicType*,
1282
 
                                    $array3 as xs:anyAtomicType*,
1283
 
                                    $array4 as xs:anyAtomicType*,
1284
 
                                    $array5 as xs:anyAtomicType*,
1285
 
                                    $array6 as xs:anyAtomicType*,
1286
 
                                    $array7 as xs:anyAtomicType*,
1287
 
                                    $array8 as xs:anyAtomicType*,
1288
 
                                    $array9 as xs:anyAtomicType*,
1289
 
                                    $array10 as xs:anyAtomicType*,
1290
 
                                    $array11 as xs:anyAtomicType*,
1291
 
                                    $array12 as xs:anyAtomicType*,
1292
 
                                    $array13 as xs:anyAtomicType*,
1293
 
                                    $array14 as xs:anyAtomicType*,
1294
 
                                    $array15 as xs:anyAtomicType*,
1295
 
                                    $array16 as xs:anyAtomicType*,
1296
 
                                    $array17 as xs:anyAtomicType*,
1297
 
                                    $array18 as xs:anyAtomicType*,
1298
 
                                    $array19 as xs:anyAtomicType*,
1299
 
                                    $array20 as xs:anyAtomicType*  ) as xs:anyAtomicType
1300
 
 {
1301
 
    if( fn:empty($array1) or 
1302
 
        fn:empty($array2) or
1303
 
        fn:empty($array3) or
1304
 
        fn:empty($array4) or
1305
 
        fn:empty($array5) or
1306
 
        fn:empty($array6) or
1307
 
        fn:empty($array7) or
1308
 
        fn:empty($array8) or
1309
 
        fn:empty($array9) or
1310
 
        fn:empty($array10) or
1311
 
        fn:empty($array11) or
1312
 
        fn:empty($array12) or
1313
 
        fn:empty($array13) or
1314
 
        fn:empty($array14) or
1315
 
        fn:empty($array15) or
1316
 
        fn:empty($array16) or
1317
 
        fn:empty($array17) or
1318
 
        fn:empty($array18) or
1319
 
        fn:empty($array19) or
1320
 
        fn:empty($array20)) 
1321
 
        then
1322
 
      0
1323
 
    else
1324
 
        excel-math:cast-as-numeric($array1[1]) * 
1325
 
        excel-math:cast-as-numeric($array2[1]) * 
1326
 
        excel-math:cast-as-numeric($array3[1]) * 
1327
 
        excel-math:cast-as-numeric($array4[1]) * 
1328
 
        excel-math:cast-as-numeric($array5[1]) * 
1329
 
        excel-math:cast-as-numeric($array6[1]) * 
1330
 
        excel-math:cast-as-numeric($array7[1]) * 
1331
 
        excel-math:cast-as-numeric($array8[1]) * 
1332
 
        excel-math:cast-as-numeric($array9[1]) * 
1333
 
        excel-math:cast-as-numeric($array10[1]) * 
1334
 
        excel-math:cast-as-numeric($array11[1]) * 
1335
 
        excel-math:cast-as-numeric($array12[1]) * 
1336
 
        excel-math:cast-as-numeric($array13[1]) * 
1337
 
        excel-math:cast-as-numeric($array14[1]) * 
1338
 
        excel-math:cast-as-numeric($array15[1]) * 
1339
 
        excel-math:cast-as-numeric($array16[1]) * 
1340
 
        excel-math:cast-as-numeric($array17[1]) * 
1341
 
        excel-math:cast-as-numeric($array18[1]) *
1342
 
        excel-math:cast-as-numeric($array19[1]) *
1343
 
        excel-math:cast-as-numeric($array20[1]) +
1344
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1345
 
                                             fn:subsequence($array2,2),
1346
 
                                             fn:subsequence($array3,2),
1347
 
                                             fn:subsequence($array4,2),
1348
 
                                             fn:subsequence($array5,2),
1349
 
                                             fn:subsequence($array6,2),
1350
 
                                             fn:subsequence($array7,2),
1351
 
                                             fn:subsequence($array8,2),
1352
 
                                             fn:subsequence($array9,2),
1353
 
                                             fn:subsequence($array10,2),
1354
 
                                             fn:subsequence($array11,2),
1355
 
                                             fn:subsequence($array12,2),
1356
 
                                             fn:subsequence($array13,2),
1357
 
                                             fn:subsequence($array14,2),
1358
 
                                             fn:subsequence($array15,2),
1359
 
                                             fn:subsequence($array16,2),
1360
 
                                             fn:subsequence($array17,2),
1361
 
                                             fn:subsequence($array18,2),
1362
 
                                             fn:subsequence($array19,2),
1363
 
                                             fn:subsequence($array20,2))
1364
 
 };
1365
 
 
1366
 
 (:~
1367
 
  : Multiplies the elements on the same position in each sequence
1368
 
  : and sums up the results.
1369
 
  : 
1370
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1371
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1372
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1373
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1374
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1375
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1376
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1377
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1378
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1379
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1380
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1381
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1382
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1383
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1384
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1385
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1386
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1387
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1388
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1389
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1390
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1391
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
1392
 
  : @return the sum of products
1393
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1394
 
:)
1395
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1396
 
                                    $array2 as xs:anyAtomicType*,
1397
 
                                    $array3 as xs:anyAtomicType*,
1398
 
                                    $array4 as xs:anyAtomicType*,
1399
 
                                    $array5 as xs:anyAtomicType*,
1400
 
                                    $array6 as xs:anyAtomicType*,
1401
 
                                    $array7 as xs:anyAtomicType*,
1402
 
                                    $array8 as xs:anyAtomicType*,
1403
 
                                    $array9 as xs:anyAtomicType*,
1404
 
                                    $array10 as xs:anyAtomicType*,
1405
 
                                    $array11 as xs:anyAtomicType*,
1406
 
                                    $array12 as xs:anyAtomicType*,
1407
 
                                    $array13 as xs:anyAtomicType*,
1408
 
                                    $array14 as xs:anyAtomicType*,
1409
 
                                    $array15 as xs:anyAtomicType*,
1410
 
                                    $array16 as xs:anyAtomicType*,
1411
 
                                    $array17 as xs:anyAtomicType*,
1412
 
                                    $array18 as xs:anyAtomicType*,
1413
 
                                    $array19 as xs:anyAtomicType*,
1414
 
                                    $array20 as xs:anyAtomicType*,
1415
 
                                    $array21 as xs:anyAtomicType*  ) as xs:anyAtomicType
1416
 
 {
1417
 
    if( fn:empty($array1) or 
1418
 
        fn:empty($array2) or
1419
 
        fn:empty($array3) or
1420
 
        fn:empty($array4) or
1421
 
        fn:empty($array5) or
1422
 
        fn:empty($array6) or
1423
 
        fn:empty($array7) or
1424
 
        fn:empty($array8) or
1425
 
        fn:empty($array9) or
1426
 
        fn:empty($array10) or
1427
 
        fn:empty($array11) or
1428
 
        fn:empty($array12) or
1429
 
        fn:empty($array13) or
1430
 
        fn:empty($array14) or
1431
 
        fn:empty($array15) or
1432
 
        fn:empty($array16) or
1433
 
        fn:empty($array17) or
1434
 
        fn:empty($array18) or
1435
 
        fn:empty($array19) or
1436
 
        fn:empty($array20) or
1437
 
        fn:empty($array21)) 
1438
 
        then
1439
 
      0
1440
 
    else
1441
 
        excel-math:cast-as-numeric($array1[1]) * 
1442
 
        excel-math:cast-as-numeric($array2[1]) * 
1443
 
        excel-math:cast-as-numeric($array3[1]) * 
1444
 
        excel-math:cast-as-numeric($array4[1]) * 
1445
 
        excel-math:cast-as-numeric($array5[1]) * 
1446
 
        excel-math:cast-as-numeric($array6[1]) * 
1447
 
        excel-math:cast-as-numeric($array7[1]) * 
1448
 
        excel-math:cast-as-numeric($array8[1]) * 
1449
 
        excel-math:cast-as-numeric($array9[1]) * 
1450
 
        excel-math:cast-as-numeric($array10[1]) * 
1451
 
        excel-math:cast-as-numeric($array11[1]) * 
1452
 
        excel-math:cast-as-numeric($array12[1]) * 
1453
 
        excel-math:cast-as-numeric($array13[1]) * 
1454
 
        excel-math:cast-as-numeric($array14[1]) * 
1455
 
        excel-math:cast-as-numeric($array15[1]) * 
1456
 
        excel-math:cast-as-numeric($array16[1]) * 
1457
 
        excel-math:cast-as-numeric($array17[1]) * 
1458
 
        excel-math:cast-as-numeric($array18[1]) *
1459
 
        excel-math:cast-as-numeric($array19[1]) *
1460
 
        excel-math:cast-as-numeric($array20[1]) *
1461
 
        excel-math:cast-as-numeric($array21[1]) +
1462
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1463
 
                                             fn:subsequence($array2,2),
1464
 
                                             fn:subsequence($array3,2),
1465
 
                                             fn:subsequence($array4,2),
1466
 
                                             fn:subsequence($array5,2),
1467
 
                                             fn:subsequence($array6,2),
1468
 
                                             fn:subsequence($array7,2),
1469
 
                                             fn:subsequence($array8,2),
1470
 
                                             fn:subsequence($array9,2),
1471
 
                                             fn:subsequence($array10,2),
1472
 
                                             fn:subsequence($array11,2),
1473
 
                                             fn:subsequence($array12,2),
1474
 
                                             fn:subsequence($array13,2),
1475
 
                                             fn:subsequence($array14,2),
1476
 
                                             fn:subsequence($array15,2),
1477
 
                                             fn:subsequence($array16,2),
1478
 
                                             fn:subsequence($array17,2),
1479
 
                                             fn:subsequence($array18,2),
1480
 
                                             fn:subsequence($array19,2),
1481
 
                                             fn:subsequence($array20,2),
1482
 
                                             fn:subsequence($array21,2))
1483
 
 };
1484
 
 
1485
 
 (:~
1486
 
  : Multiplies the elements on the same position in each sequence
1487
 
  : and sums up the results.
1488
 
  : 
1489
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1490
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1491
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1492
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1493
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1494
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1495
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1496
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1497
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1498
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1499
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1500
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1501
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1502
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1503
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1504
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1505
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1506
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1507
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1508
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1509
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1510
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
1511
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
1512
 
  : @return the sum of products
1513
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1514
 
:)
1515
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1516
 
                                    $array2 as xs:anyAtomicType*,
1517
 
                                    $array3 as xs:anyAtomicType*,
1518
 
                                    $array4 as xs:anyAtomicType*,
1519
 
                                    $array5 as xs:anyAtomicType*,
1520
 
                                    $array6 as xs:anyAtomicType*,
1521
 
                                    $array7 as xs:anyAtomicType*,
1522
 
                                    $array8 as xs:anyAtomicType*,
1523
 
                                    $array9 as xs:anyAtomicType*,
1524
 
                                    $array10 as xs:anyAtomicType*,
1525
 
                                    $array11 as xs:anyAtomicType*,
1526
 
                                    $array12 as xs:anyAtomicType*,
1527
 
                                    $array13 as xs:anyAtomicType*,
1528
 
                                    $array14 as xs:anyAtomicType*,
1529
 
                                    $array15 as xs:anyAtomicType*,
1530
 
                                    $array16 as xs:anyAtomicType*,
1531
 
                                    $array17 as xs:anyAtomicType*,
1532
 
                                    $array18 as xs:anyAtomicType*,
1533
 
                                    $array19 as xs:anyAtomicType*,
1534
 
                                    $array20 as xs:anyAtomicType*,
1535
 
                                    $array21 as xs:anyAtomicType*,
1536
 
                                    $array22 as xs:anyAtomicType*  ) as xs:anyAtomicType
1537
 
 {
1538
 
    if( fn:empty($array1) or 
1539
 
        fn:empty($array2) or
1540
 
        fn:empty($array3) or
1541
 
        fn:empty($array4) or
1542
 
        fn:empty($array5) or
1543
 
        fn:empty($array6) or
1544
 
        fn:empty($array7) or
1545
 
        fn:empty($array8) or
1546
 
        fn:empty($array9) or
1547
 
        fn:empty($array10) or
1548
 
        fn:empty($array11) or
1549
 
        fn:empty($array12) or
1550
 
        fn:empty($array13) or
1551
 
        fn:empty($array14) or
1552
 
        fn:empty($array15) or
1553
 
        fn:empty($array16) or
1554
 
        fn:empty($array17) or
1555
 
        fn:empty($array18) or
1556
 
        fn:empty($array19) or
1557
 
        fn:empty($array20) or
1558
 
        fn:empty($array21) or
1559
 
        fn:empty($array22)) 
1560
 
        then
1561
 
      0
1562
 
    else
1563
 
        excel-math:cast-as-numeric($array1[1]) * 
1564
 
        excel-math:cast-as-numeric($array2[1]) * 
1565
 
        excel-math:cast-as-numeric($array3[1]) * 
1566
 
        excel-math:cast-as-numeric($array4[1]) * 
1567
 
        excel-math:cast-as-numeric($array5[1]) * 
1568
 
        excel-math:cast-as-numeric($array6[1]) * 
1569
 
        excel-math:cast-as-numeric($array7[1]) * 
1570
 
        excel-math:cast-as-numeric($array8[1]) * 
1571
 
        excel-math:cast-as-numeric($array9[1]) * 
1572
 
        excel-math:cast-as-numeric($array10[1]) * 
1573
 
        excel-math:cast-as-numeric($array11[1]) * 
1574
 
        excel-math:cast-as-numeric($array12[1]) * 
1575
 
        excel-math:cast-as-numeric($array13[1]) * 
1576
 
        excel-math:cast-as-numeric($array14[1]) * 
1577
 
        excel-math:cast-as-numeric($array15[1]) * 
1578
 
        excel-math:cast-as-numeric($array16[1]) * 
1579
 
        excel-math:cast-as-numeric($array17[1]) * 
1580
 
        excel-math:cast-as-numeric($array18[1]) *
1581
 
        excel-math:cast-as-numeric($array19[1]) *
1582
 
        excel-math:cast-as-numeric($array20[1]) *
1583
 
        excel-math:cast-as-numeric($array21[1]) *
1584
 
        excel-math:cast-as-numeric($array22[1]) +
1585
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1586
 
                                             fn:subsequence($array2,2),
1587
 
                                             fn:subsequence($array3,2),
1588
 
                                             fn:subsequence($array4,2),
1589
 
                                             fn:subsequence($array5,2),
1590
 
                                             fn:subsequence($array6,2),
1591
 
                                             fn:subsequence($array7,2),
1592
 
                                             fn:subsequence($array8,2),
1593
 
                                             fn:subsequence($array9,2),
1594
 
                                             fn:subsequence($array10,2),
1595
 
                                             fn:subsequence($array11,2),
1596
 
                                             fn:subsequence($array12,2),
1597
 
                                             fn:subsequence($array13,2),
1598
 
                                             fn:subsequence($array14,2),
1599
 
                                             fn:subsequence($array15,2),
1600
 
                                             fn:subsequence($array16,2),
1601
 
                                             fn:subsequence($array17,2),
1602
 
                                             fn:subsequence($array18,2),
1603
 
                                             fn:subsequence($array19,2),
1604
 
                                             fn:subsequence($array20,2),
1605
 
                                             fn:subsequence($array21,2),
1606
 
                                             fn:subsequence($array22,2))
1607
 
 };
1608
 
 
1609
 
 (:~
1610
 
  : Multiplies the elements on the same position in each sequence
1611
 
  : and sums up the results.
1612
 
  : 
1613
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1614
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1615
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1616
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1617
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1618
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1619
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1620
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1621
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1622
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1623
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1624
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1625
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1626
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1627
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1628
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1629
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1630
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1631
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1632
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1633
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1634
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
1635
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
1636
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
1637
 
  : @return the sum of products
1638
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1639
 
:)
1640
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1641
 
                                    $array2 as xs:anyAtomicType*,
1642
 
                                    $array3 as xs:anyAtomicType*,
1643
 
                                    $array4 as xs:anyAtomicType*,
1644
 
                                    $array5 as xs:anyAtomicType*,
1645
 
                                    $array6 as xs:anyAtomicType*,
1646
 
                                    $array7 as xs:anyAtomicType*,
1647
 
                                    $array8 as xs:anyAtomicType*,
1648
 
                                    $array9 as xs:anyAtomicType*,
1649
 
                                    $array10 as xs:anyAtomicType*,
1650
 
                                    $array11 as xs:anyAtomicType*,
1651
 
                                    $array12 as xs:anyAtomicType*,
1652
 
                                    $array13 as xs:anyAtomicType*,
1653
 
                                    $array14 as xs:anyAtomicType*,
1654
 
                                    $array15 as xs:anyAtomicType*,
1655
 
                                    $array16 as xs:anyAtomicType*,
1656
 
                                    $array17 as xs:anyAtomicType*,
1657
 
                                    $array18 as xs:anyAtomicType*,
1658
 
                                    $array19 as xs:anyAtomicType*,
1659
 
                                    $array20 as xs:anyAtomicType*,
1660
 
                                    $array21 as xs:anyAtomicType*,
1661
 
                                    $array22 as xs:anyAtomicType*,
1662
 
                                    $array23 as xs:anyAtomicType*  ) as xs:anyAtomicType
1663
 
 {
1664
 
    if( fn:empty($array1) or 
1665
 
        fn:empty($array2) or
1666
 
        fn:empty($array3) or
1667
 
        fn:empty($array4) or
1668
 
        fn:empty($array5) or
1669
 
        fn:empty($array6) or
1670
 
        fn:empty($array7) or
1671
 
        fn:empty($array8) or
1672
 
        fn:empty($array9) or
1673
 
        fn:empty($array10) or
1674
 
        fn:empty($array11) or
1675
 
        fn:empty($array12) or
1676
 
        fn:empty($array13) or
1677
 
        fn:empty($array14) or
1678
 
        fn:empty($array15) or
1679
 
        fn:empty($array16) or
1680
 
        fn:empty($array17) or
1681
 
        fn:empty($array18) or
1682
 
        fn:empty($array19) or
1683
 
        fn:empty($array20) or
1684
 
        fn:empty($array21) or
1685
 
        fn:empty($array22) or
1686
 
        fn:empty($array23)) 
1687
 
        then
1688
 
      0
1689
 
    else
1690
 
        excel-math:cast-as-numeric($array1[1]) * 
1691
 
        excel-math:cast-as-numeric($array2[1]) * 
1692
 
        excel-math:cast-as-numeric($array3[1]) * 
1693
 
        excel-math:cast-as-numeric($array4[1]) * 
1694
 
        excel-math:cast-as-numeric($array5[1]) * 
1695
 
        excel-math:cast-as-numeric($array6[1]) * 
1696
 
        excel-math:cast-as-numeric($array7[1]) * 
1697
 
        excel-math:cast-as-numeric($array8[1]) * 
1698
 
        excel-math:cast-as-numeric($array9[1]) * 
1699
 
        excel-math:cast-as-numeric($array10[1]) * 
1700
 
        excel-math:cast-as-numeric($array11[1]) * 
1701
 
        excel-math:cast-as-numeric($array12[1]) * 
1702
 
        excel-math:cast-as-numeric($array13[1]) * 
1703
 
        excel-math:cast-as-numeric($array14[1]) * 
1704
 
        excel-math:cast-as-numeric($array15[1]) * 
1705
 
        excel-math:cast-as-numeric($array16[1]) * 
1706
 
        excel-math:cast-as-numeric($array17[1]) * 
1707
 
        excel-math:cast-as-numeric($array18[1]) *
1708
 
        excel-math:cast-as-numeric($array19[1]) *
1709
 
        excel-math:cast-as-numeric($array20[1]) *
1710
 
        excel-math:cast-as-numeric($array21[1]) *
1711
 
        excel-math:cast-as-numeric($array22[1]) *
1712
 
        excel-math:cast-as-numeric($array23[1]) +
1713
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1714
 
                                             fn:subsequence($array2,2),
1715
 
                                             fn:subsequence($array3,2),
1716
 
                                             fn:subsequence($array4,2),
1717
 
                                             fn:subsequence($array5,2),
1718
 
                                             fn:subsequence($array6,2),
1719
 
                                             fn:subsequence($array7,2),
1720
 
                                             fn:subsequence($array8,2),
1721
 
                                             fn:subsequence($array9,2),
1722
 
                                             fn:subsequence($array10,2),
1723
 
                                             fn:subsequence($array11,2),
1724
 
                                             fn:subsequence($array12,2),
1725
 
                                             fn:subsequence($array13,2),
1726
 
                                             fn:subsequence($array14,2),
1727
 
                                             fn:subsequence($array15,2),
1728
 
                                             fn:subsequence($array16,2),
1729
 
                                             fn:subsequence($array17,2),
1730
 
                                             fn:subsequence($array18,2),
1731
 
                                             fn:subsequence($array19,2),
1732
 
                                             fn:subsequence($array20,2),
1733
 
                                             fn:subsequence($array21,2),
1734
 
                                             fn:subsequence($array22,2),
1735
 
                                             fn:subsequence($array23,2))
1736
 
 };
1737
 
 
1738
 
 (:~
1739
 
  : Multiplies the elements on the same position in each sequence
1740
 
  : and sums up the results.
1741
 
  : 
1742
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1743
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1744
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1745
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1746
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1747
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1748
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1749
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1750
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1751
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1752
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1753
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1754
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1755
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1756
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1757
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1758
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1759
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1760
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1761
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1762
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1763
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
1764
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
1765
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
1766
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
1767
 
  : @return the sum of products
1768
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1769
 
:)
1770
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1771
 
                                    $array2 as xs:anyAtomicType*,
1772
 
                                    $array3 as xs:anyAtomicType*,
1773
 
                                    $array4 as xs:anyAtomicType*,
1774
 
                                    $array5 as xs:anyAtomicType*,
1775
 
                                    $array6 as xs:anyAtomicType*,
1776
 
                                    $array7 as xs:anyAtomicType*,
1777
 
                                    $array8 as xs:anyAtomicType*,
1778
 
                                    $array9 as xs:anyAtomicType*,
1779
 
                                    $array10 as xs:anyAtomicType*,
1780
 
                                    $array11 as xs:anyAtomicType*,
1781
 
                                    $array12 as xs:anyAtomicType*,
1782
 
                                    $array13 as xs:anyAtomicType*,
1783
 
                                    $array14 as xs:anyAtomicType*,
1784
 
                                    $array15 as xs:anyAtomicType*,
1785
 
                                    $array16 as xs:anyAtomicType*,
1786
 
                                    $array17 as xs:anyAtomicType*,
1787
 
                                    $array18 as xs:anyAtomicType*,
1788
 
                                    $array19 as xs:anyAtomicType*,
1789
 
                                    $array20 as xs:anyAtomicType*,
1790
 
                                    $array21 as xs:anyAtomicType*,
1791
 
                                    $array22 as xs:anyAtomicType*,
1792
 
                                    $array23 as xs:anyAtomicType*,
1793
 
                                    $array24 as xs:anyAtomicType*  ) as xs:anyAtomicType
1794
 
 {
1795
 
    if( fn:empty($array1) or 
1796
 
        fn:empty($array2) or
1797
 
        fn:empty($array3) or
1798
 
        fn:empty($array4) or
1799
 
        fn:empty($array5) or
1800
 
        fn:empty($array6) or
1801
 
        fn:empty($array7) or
1802
 
        fn:empty($array8) or
1803
 
        fn:empty($array9) or
1804
 
        fn:empty($array10) or
1805
 
        fn:empty($array11) or
1806
 
        fn:empty($array12) or
1807
 
        fn:empty($array13) or
1808
 
        fn:empty($array14) or
1809
 
        fn:empty($array15) or
1810
 
        fn:empty($array16) or
1811
 
        fn:empty($array17) or
1812
 
        fn:empty($array18) or
1813
 
        fn:empty($array19) or
1814
 
        fn:empty($array20) or
1815
 
        fn:empty($array21) or
1816
 
        fn:empty($array22) or
1817
 
        fn:empty($array23) or
1818
 
        fn:empty($array24)) 
1819
 
        then
1820
 
      0
1821
 
    else
1822
 
        excel-math:cast-as-numeric($array1[1]) * 
1823
 
        excel-math:cast-as-numeric($array2[1]) * 
1824
 
        excel-math:cast-as-numeric($array3[1]) * 
1825
 
        excel-math:cast-as-numeric($array4[1]) * 
1826
 
        excel-math:cast-as-numeric($array5[1]) * 
1827
 
        excel-math:cast-as-numeric($array6[1]) * 
1828
 
        excel-math:cast-as-numeric($array7[1]) * 
1829
 
        excel-math:cast-as-numeric($array8[1]) * 
1830
 
        excel-math:cast-as-numeric($array9[1]) * 
1831
 
        excel-math:cast-as-numeric($array10[1]) * 
1832
 
        excel-math:cast-as-numeric($array11[1]) * 
1833
 
        excel-math:cast-as-numeric($array12[1]) * 
1834
 
        excel-math:cast-as-numeric($array13[1]) * 
1835
 
        excel-math:cast-as-numeric($array14[1]) * 
1836
 
        excel-math:cast-as-numeric($array15[1]) * 
1837
 
        excel-math:cast-as-numeric($array16[1]) * 
1838
 
        excel-math:cast-as-numeric($array17[1]) * 
1839
 
        excel-math:cast-as-numeric($array18[1]) *
1840
 
        excel-math:cast-as-numeric($array19[1]) *
1841
 
        excel-math:cast-as-numeric($array20[1]) *
1842
 
        excel-math:cast-as-numeric($array21[1]) *
1843
 
        excel-math:cast-as-numeric($array22[1]) *
1844
 
        excel-math:cast-as-numeric($array23[1]) *
1845
 
        excel-math:cast-as-numeric($array24[1]) +
1846
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1847
 
                                             fn:subsequence($array2,2),
1848
 
                                             fn:subsequence($array3,2),
1849
 
                                             fn:subsequence($array4,2),
1850
 
                                             fn:subsequence($array5,2),
1851
 
                                             fn:subsequence($array6,2),
1852
 
                                             fn:subsequence($array7,2),
1853
 
                                             fn:subsequence($array8,2),
1854
 
                                             fn:subsequence($array9,2),
1855
 
                                             fn:subsequence($array10,2),
1856
 
                                             fn:subsequence($array11,2),
1857
 
                                             fn:subsequence($array12,2),
1858
 
                                             fn:subsequence($array13,2),
1859
 
                                             fn:subsequence($array14,2),
1860
 
                                             fn:subsequence($array15,2),
1861
 
                                             fn:subsequence($array16,2),
1862
 
                                             fn:subsequence($array17,2),
1863
 
                                             fn:subsequence($array18,2),
1864
 
                                             fn:subsequence($array19,2),
1865
 
                                             fn:subsequence($array20,2),
1866
 
                                             fn:subsequence($array21,2),
1867
 
                                             fn:subsequence($array22,2),
1868
 
                                             fn:subsequence($array23,2),
1869
 
                                             fn:subsequence($array24,2))
1870
 
 };
1871
 
 
1872
 
 (:~
1873
 
  : Multiplies the elements on the same position in each sequence
1874
 
  : and sums up the results.
1875
 
  : 
1876
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
1877
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
1878
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
1879
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
1880
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
1881
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
1882
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
1883
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
1884
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
1885
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
1886
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
1887
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
1888
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
1889
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
1890
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
1891
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
1892
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
1893
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
1894
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
1895
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
1896
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
1897
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
1898
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
1899
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
1900
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
1901
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
1902
 
  : @return the sum of products
1903
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
1904
 
:)
1905
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
1906
 
                                    $array2 as xs:anyAtomicType*,
1907
 
                                    $array3 as xs:anyAtomicType*,
1908
 
                                    $array4 as xs:anyAtomicType*,
1909
 
                                    $array5 as xs:anyAtomicType*,
1910
 
                                    $array6 as xs:anyAtomicType*,
1911
 
                                    $array7 as xs:anyAtomicType*,
1912
 
                                    $array8 as xs:anyAtomicType*,
1913
 
                                    $array9 as xs:anyAtomicType*,
1914
 
                                    $array10 as xs:anyAtomicType*,
1915
 
                                    $array11 as xs:anyAtomicType*,
1916
 
                                    $array12 as xs:anyAtomicType*,
1917
 
                                    $array13 as xs:anyAtomicType*,
1918
 
                                    $array14 as xs:anyAtomicType*,
1919
 
                                    $array15 as xs:anyAtomicType*,
1920
 
                                    $array16 as xs:anyAtomicType*,
1921
 
                                    $array17 as xs:anyAtomicType*,
1922
 
                                    $array18 as xs:anyAtomicType*,
1923
 
                                    $array19 as xs:anyAtomicType*,
1924
 
                                    $array20 as xs:anyAtomicType*,
1925
 
                                    $array21 as xs:anyAtomicType*,
1926
 
                                    $array22 as xs:anyAtomicType*,
1927
 
                                    $array23 as xs:anyAtomicType*,
1928
 
                                    $array24 as xs:anyAtomicType*,
1929
 
                                    $array25 as xs:anyAtomicType*  ) as xs:anyAtomicType
1930
 
 {
1931
 
    if( fn:empty($array1) or 
1932
 
        fn:empty($array2) or
1933
 
        fn:empty($array3) or
1934
 
        fn:empty($array4) or
1935
 
        fn:empty($array5) or
1936
 
        fn:empty($array6) or
1937
 
        fn:empty($array7) or
1938
 
        fn:empty($array8) or
1939
 
        fn:empty($array9) or
1940
 
        fn:empty($array10) or
1941
 
        fn:empty($array11) or
1942
 
        fn:empty($array12) or
1943
 
        fn:empty($array13) or
1944
 
        fn:empty($array14) or
1945
 
        fn:empty($array15) or
1946
 
        fn:empty($array16) or
1947
 
        fn:empty($array17) or
1948
 
        fn:empty($array18) or
1949
 
        fn:empty($array19) or
1950
 
        fn:empty($array20) or
1951
 
        fn:empty($array21) or
1952
 
        fn:empty($array22) or
1953
 
        fn:empty($array23) or
1954
 
        fn:empty($array24) or
1955
 
        fn:empty($array25)) 
1956
 
        then
1957
 
      0
1958
 
    else
1959
 
        excel-math:cast-as-numeric($array1[1]) * 
1960
 
        excel-math:cast-as-numeric($array2[1]) * 
1961
 
        excel-math:cast-as-numeric($array3[1]) * 
1962
 
        excel-math:cast-as-numeric($array4[1]) * 
1963
 
        excel-math:cast-as-numeric($array5[1]) * 
1964
 
        excel-math:cast-as-numeric($array6[1]) * 
1965
 
        excel-math:cast-as-numeric($array7[1]) * 
1966
 
        excel-math:cast-as-numeric($array8[1]) * 
1967
 
        excel-math:cast-as-numeric($array9[1]) * 
1968
 
        excel-math:cast-as-numeric($array10[1]) * 
1969
 
        excel-math:cast-as-numeric($array11[1]) * 
1970
 
        excel-math:cast-as-numeric($array12[1]) * 
1971
 
        excel-math:cast-as-numeric($array13[1]) * 
1972
 
        excel-math:cast-as-numeric($array14[1]) * 
1973
 
        excel-math:cast-as-numeric($array15[1]) * 
1974
 
        excel-math:cast-as-numeric($array16[1]) * 
1975
 
        excel-math:cast-as-numeric($array17[1]) * 
1976
 
        excel-math:cast-as-numeric($array18[1]) *
1977
 
        excel-math:cast-as-numeric($array19[1]) *
1978
 
        excel-math:cast-as-numeric($array20[1]) *
1979
 
        excel-math:cast-as-numeric($array21[1]) *
1980
 
        excel-math:cast-as-numeric($array22[1]) *
1981
 
        excel-math:cast-as-numeric($array23[1]) *
1982
 
        excel-math:cast-as-numeric($array24[1]) *
1983
 
        excel-math:cast-as-numeric($array25[1]) +
1984
 
                    excel:sumproduct(  fn:subsequence($array1,2),
1985
 
                                             fn:subsequence($array2,2),
1986
 
                                             fn:subsequence($array3,2),
1987
 
                                             fn:subsequence($array4,2),
1988
 
                                             fn:subsequence($array5,2),
1989
 
                                             fn:subsequence($array6,2),
1990
 
                                             fn:subsequence($array7,2),
1991
 
                                             fn:subsequence($array8,2),
1992
 
                                             fn:subsequence($array9,2),
1993
 
                                             fn:subsequence($array10,2),
1994
 
                                             fn:subsequence($array11,2),
1995
 
                                             fn:subsequence($array12,2),
1996
 
                                             fn:subsequence($array13,2),
1997
 
                                             fn:subsequence($array14,2),
1998
 
                                             fn:subsequence($array15,2),
1999
 
                                             fn:subsequence($array16,2),
2000
 
                                             fn:subsequence($array17,2),
2001
 
                                             fn:subsequence($array18,2),
2002
 
                                             fn:subsequence($array19,2),
2003
 
                                             fn:subsequence($array20,2),
2004
 
                                             fn:subsequence($array21,2),
2005
 
                                             fn:subsequence($array22,2),
2006
 
                                             fn:subsequence($array23,2),
2007
 
                                             fn:subsequence($array24,2),
2008
 
                                             fn:subsequence($array25,2))
2009
 
 };
2010
 
 
2011
 
 (:~
2012
 
  : Multiplies the elements on the same position in each sequence
2013
 
  : and sums up the results.
2014
 
  : 
2015
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
2016
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
2017
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
2018
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
2019
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
2020
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
2021
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
2022
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
2023
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
2024
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
2025
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
2026
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
2027
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
2028
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
2029
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
2030
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
2031
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
2032
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
2033
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
2034
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
2035
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
2036
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
2037
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
2038
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
2039
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
2040
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
2041
 
  : @param $array26 the sequences of numbers or arguments castable to numeric
2042
 
  : @return the sum of products
2043
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2044
 
:)
2045
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
2046
 
                                    $array2 as xs:anyAtomicType*,
2047
 
                                    $array3 as xs:anyAtomicType*,
2048
 
                                    $array4 as xs:anyAtomicType*,
2049
 
                                    $array5 as xs:anyAtomicType*,
2050
 
                                    $array6 as xs:anyAtomicType*,
2051
 
                                    $array7 as xs:anyAtomicType*,
2052
 
                                    $array8 as xs:anyAtomicType*,
2053
 
                                    $array9 as xs:anyAtomicType*,
2054
 
                                    $array10 as xs:anyAtomicType*,
2055
 
                                    $array11 as xs:anyAtomicType*,
2056
 
                                    $array12 as xs:anyAtomicType*,
2057
 
                                    $array13 as xs:anyAtomicType*,
2058
 
                                    $array14 as xs:anyAtomicType*,
2059
 
                                    $array15 as xs:anyAtomicType*,
2060
 
                                    $array16 as xs:anyAtomicType*,
2061
 
                                    $array17 as xs:anyAtomicType*,
2062
 
                                    $array18 as xs:anyAtomicType*,
2063
 
                                    $array19 as xs:anyAtomicType*,
2064
 
                                    $array20 as xs:anyAtomicType*,
2065
 
                                    $array21 as xs:anyAtomicType*,
2066
 
                                    $array22 as xs:anyAtomicType*,
2067
 
                                    $array23 as xs:anyAtomicType*,
2068
 
                                    $array24 as xs:anyAtomicType*,
2069
 
                                    $array25 as xs:anyAtomicType*,
2070
 
                                    $array26 as xs:anyAtomicType*  ) as xs:anyAtomicType
2071
 
 {
2072
 
    if( fn:empty($array1) or 
2073
 
        fn:empty($array2) or
2074
 
        fn:empty($array3) or
2075
 
        fn:empty($array4) or
2076
 
        fn:empty($array5) or
2077
 
        fn:empty($array6) or
2078
 
        fn:empty($array7) or
2079
 
        fn:empty($array8) or
2080
 
        fn:empty($array9) or
2081
 
        fn:empty($array10) or
2082
 
        fn:empty($array11) or
2083
 
        fn:empty($array12) or
2084
 
        fn:empty($array13) or
2085
 
        fn:empty($array14) or
2086
 
        fn:empty($array15) or
2087
 
        fn:empty($array16) or
2088
 
        fn:empty($array17) or
2089
 
        fn:empty($array18) or
2090
 
        fn:empty($array19) or
2091
 
        fn:empty($array20) or
2092
 
        fn:empty($array21) or
2093
 
        fn:empty($array22) or
2094
 
        fn:empty($array23) or
2095
 
        fn:empty($array24) or
2096
 
        fn:empty($array25) or
2097
 
        fn:empty($array26)) 
2098
 
        then
2099
 
      0
2100
 
    else
2101
 
        excel-math:cast-as-numeric($array1[1]) * 
2102
 
        excel-math:cast-as-numeric($array2[1]) * 
2103
 
        excel-math:cast-as-numeric($array3[1]) * 
2104
 
        excel-math:cast-as-numeric($array4[1]) * 
2105
 
        excel-math:cast-as-numeric($array5[1]) * 
2106
 
        excel-math:cast-as-numeric($array6[1]) * 
2107
 
        excel-math:cast-as-numeric($array7[1]) * 
2108
 
        excel-math:cast-as-numeric($array8[1]) * 
2109
 
        excel-math:cast-as-numeric($array9[1]) * 
2110
 
        excel-math:cast-as-numeric($array10[1]) * 
2111
 
        excel-math:cast-as-numeric($array11[1]) * 
2112
 
        excel-math:cast-as-numeric($array12[1]) * 
2113
 
        excel-math:cast-as-numeric($array13[1]) * 
2114
 
        excel-math:cast-as-numeric($array14[1]) * 
2115
 
        excel-math:cast-as-numeric($array15[1]) * 
2116
 
        excel-math:cast-as-numeric($array16[1]) * 
2117
 
        excel-math:cast-as-numeric($array17[1]) * 
2118
 
        excel-math:cast-as-numeric($array18[1]) *
2119
 
        excel-math:cast-as-numeric($array19[1]) *
2120
 
        excel-math:cast-as-numeric($array20[1]) *
2121
 
        excel-math:cast-as-numeric($array21[1]) *
2122
 
        excel-math:cast-as-numeric($array22[1]) *
2123
 
        excel-math:cast-as-numeric($array23[1]) *
2124
 
        excel-math:cast-as-numeric($array24[1]) *
2125
 
        excel-math:cast-as-numeric($array25[1]) *
2126
 
        excel-math:cast-as-numeric($array26[1]) +
2127
 
                    excel:sumproduct(  fn:subsequence($array1,2),
2128
 
                                             fn:subsequence($array2,2),
2129
 
                                             fn:subsequence($array3,2),
2130
 
                                             fn:subsequence($array4,2),
2131
 
                                             fn:subsequence($array5,2),
2132
 
                                             fn:subsequence($array6,2),
2133
 
                                             fn:subsequence($array7,2),
2134
 
                                             fn:subsequence($array8,2),
2135
 
                                             fn:subsequence($array9,2),
2136
 
                                             fn:subsequence($array10,2),
2137
 
                                             fn:subsequence($array11,2),
2138
 
                                             fn:subsequence($array12,2),
2139
 
                                             fn:subsequence($array13,2),
2140
 
                                             fn:subsequence($array14,2),
2141
 
                                             fn:subsequence($array15,2),
2142
 
                                             fn:subsequence($array16,2),
2143
 
                                             fn:subsequence($array17,2),
2144
 
                                             fn:subsequence($array18,2),
2145
 
                                             fn:subsequence($array19,2),
2146
 
                                             fn:subsequence($array20,2),
2147
 
                                             fn:subsequence($array21,2),
2148
 
                                             fn:subsequence($array22,2),
2149
 
                                             fn:subsequence($array23,2),
2150
 
                                             fn:subsequence($array24,2),
2151
 
                                             fn:subsequence($array25,2),
2152
 
                                             fn:subsequence($array26,2))
2153
 
 };
2154
 
 
2155
 
 (:~
2156
 
  : Multiplies the elements on the same position in each sequence
2157
 
  : and sums up the results.
2158
 
  : 
2159
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
2160
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
2161
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
2162
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
2163
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
2164
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
2165
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
2166
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
2167
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
2168
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
2169
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
2170
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
2171
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
2172
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
2173
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
2174
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
2175
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
2176
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
2177
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
2178
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
2179
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
2180
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
2181
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
2182
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
2183
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
2184
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
2185
 
  : @param $array26 the sequences of numbers or arguments castable to numeric
2186
 
  : @param $array27 the sequences of numbers or arguments castable to numeric
2187
 
  : @return the sum of products
2188
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2189
 
:)
2190
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
2191
 
                                    $array2 as xs:anyAtomicType*,
2192
 
                                    $array3 as xs:anyAtomicType*,
2193
 
                                    $array4 as xs:anyAtomicType*,
2194
 
                                    $array5 as xs:anyAtomicType*,
2195
 
                                    $array6 as xs:anyAtomicType*,
2196
 
                                    $array7 as xs:anyAtomicType*,
2197
 
                                    $array8 as xs:anyAtomicType*,
2198
 
                                    $array9 as xs:anyAtomicType*,
2199
 
                                    $array10 as xs:anyAtomicType*,
2200
 
                                    $array11 as xs:anyAtomicType*,
2201
 
                                    $array12 as xs:anyAtomicType*,
2202
 
                                    $array13 as xs:anyAtomicType*,
2203
 
                                    $array14 as xs:anyAtomicType*,
2204
 
                                    $array15 as xs:anyAtomicType*,
2205
 
                                    $array16 as xs:anyAtomicType*,
2206
 
                                    $array17 as xs:anyAtomicType*,
2207
 
                                    $array18 as xs:anyAtomicType*,
2208
 
                                    $array19 as xs:anyAtomicType*,
2209
 
                                    $array20 as xs:anyAtomicType*,
2210
 
                                    $array21 as xs:anyAtomicType*,
2211
 
                                    $array22 as xs:anyAtomicType*,
2212
 
                                    $array23 as xs:anyAtomicType*,
2213
 
                                    $array24 as xs:anyAtomicType*,
2214
 
                                    $array25 as xs:anyAtomicType*,
2215
 
                                    $array26 as xs:anyAtomicType*,
2216
 
                                    $array27 as xs:anyAtomicType*  ) as xs:anyAtomicType
2217
 
 {
2218
 
    if( fn:empty($array1) or 
2219
 
        fn:empty($array2) or
2220
 
        fn:empty($array3) or
2221
 
        fn:empty($array4) or
2222
 
        fn:empty($array5) or
2223
 
        fn:empty($array6) or
2224
 
        fn:empty($array7) or
2225
 
        fn:empty($array8) or
2226
 
        fn:empty($array9) or
2227
 
        fn:empty($array10) or
2228
 
        fn:empty($array11) or
2229
 
        fn:empty($array12) or
2230
 
        fn:empty($array13) or
2231
 
        fn:empty($array14) or
2232
 
        fn:empty($array15) or
2233
 
        fn:empty($array16) or
2234
 
        fn:empty($array17) or
2235
 
        fn:empty($array18) or
2236
 
        fn:empty($array19) or
2237
 
        fn:empty($array20) or
2238
 
        fn:empty($array21) or
2239
 
        fn:empty($array22) or
2240
 
        fn:empty($array23) or
2241
 
        fn:empty($array24) or
2242
 
        fn:empty($array25) or
2243
 
        fn:empty($array26) or
2244
 
        fn:empty($array27)) 
2245
 
        then
2246
 
      0
2247
 
    else
2248
 
        excel-math:cast-as-numeric($array1[1]) * 
2249
 
        excel-math:cast-as-numeric($array2[1]) * 
2250
 
        excel-math:cast-as-numeric($array3[1]) * 
2251
 
        excel-math:cast-as-numeric($array4[1]) * 
2252
 
        excel-math:cast-as-numeric($array5[1]) * 
2253
 
        excel-math:cast-as-numeric($array6[1]) * 
2254
 
        excel-math:cast-as-numeric($array7[1]) * 
2255
 
        excel-math:cast-as-numeric($array8[1]) * 
2256
 
        excel-math:cast-as-numeric($array9[1]) * 
2257
 
        excel-math:cast-as-numeric($array10[1]) * 
2258
 
        excel-math:cast-as-numeric($array11[1]) * 
2259
 
        excel-math:cast-as-numeric($array12[1]) * 
2260
 
        excel-math:cast-as-numeric($array13[1]) * 
2261
 
        excel-math:cast-as-numeric($array14[1]) * 
2262
 
        excel-math:cast-as-numeric($array15[1]) * 
2263
 
        excel-math:cast-as-numeric($array16[1]) * 
2264
 
        excel-math:cast-as-numeric($array17[1]) * 
2265
 
        excel-math:cast-as-numeric($array18[1]) *
2266
 
        excel-math:cast-as-numeric($array19[1]) *
2267
 
        excel-math:cast-as-numeric($array20[1]) *
2268
 
        excel-math:cast-as-numeric($array21[1]) *
2269
 
        excel-math:cast-as-numeric($array22[1]) *
2270
 
        excel-math:cast-as-numeric($array23[1]) *
2271
 
        excel-math:cast-as-numeric($array24[1]) *
2272
 
        excel-math:cast-as-numeric($array25[1]) *
2273
 
        excel-math:cast-as-numeric($array26[1]) *
2274
 
        excel-math:cast-as-numeric($array27[1]) +
2275
 
                    excel:sumproduct(  fn:subsequence($array1,2),
2276
 
                                             fn:subsequence($array2,2),
2277
 
                                             fn:subsequence($array3,2),
2278
 
                                             fn:subsequence($array4,2),
2279
 
                                             fn:subsequence($array5,2),
2280
 
                                             fn:subsequence($array6,2),
2281
 
                                             fn:subsequence($array7,2),
2282
 
                                             fn:subsequence($array8,2),
2283
 
                                             fn:subsequence($array9,2),
2284
 
                                             fn:subsequence($array10,2),
2285
 
                                             fn:subsequence($array11,2),
2286
 
                                             fn:subsequence($array12,2),
2287
 
                                             fn:subsequence($array13,2),
2288
 
                                             fn:subsequence($array14,2),
2289
 
                                             fn:subsequence($array15,2),
2290
 
                                             fn:subsequence($array16,2),
2291
 
                                             fn:subsequence($array17,2),
2292
 
                                             fn:subsequence($array18,2),
2293
 
                                             fn:subsequence($array19,2),
2294
 
                                             fn:subsequence($array20,2),
2295
 
                                             fn:subsequence($array21,2),
2296
 
                                             fn:subsequence($array22,2),
2297
 
                                             fn:subsequence($array23,2),
2298
 
                                             fn:subsequence($array24,2),
2299
 
                                             fn:subsequence($array25,2),
2300
 
                                             fn:subsequence($array26,2),
2301
 
                                             fn:subsequence($array27,2))
2302
 
 };
2303
 
 
2304
 
 (:~
2305
 
  : Multiplies the elements on the same position in each sequence
2306
 
  : and sums up the results.
2307
 
  : 
2308
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
2309
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
2310
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
2311
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
2312
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
2313
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
2314
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
2315
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
2316
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
2317
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
2318
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
2319
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
2320
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
2321
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
2322
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
2323
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
2324
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
2325
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
2326
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
2327
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
2328
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
2329
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
2330
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
2331
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
2332
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
2333
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
2334
 
  : @param $array26 the sequences of numbers or arguments castable to numeric
2335
 
  : @param $array27 the sequences of numbers or arguments castable to numeric
2336
 
  : @param $array28 the sequences of numbers or arguments castable to numeric
2337
 
  : @return the sum of products
2338
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2339
 
:)
2340
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
2341
 
                                    $array2 as xs:anyAtomicType*,
2342
 
                                    $array3 as xs:anyAtomicType*,
2343
 
                                    $array4 as xs:anyAtomicType*,
2344
 
                                    $array5 as xs:anyAtomicType*,
2345
 
                                    $array6 as xs:anyAtomicType*,
2346
 
                                    $array7 as xs:anyAtomicType*,
2347
 
                                    $array8 as xs:anyAtomicType*,
2348
 
                                    $array9 as xs:anyAtomicType*,
2349
 
                                    $array10 as xs:anyAtomicType*,
2350
 
                                    $array11 as xs:anyAtomicType*,
2351
 
                                    $array12 as xs:anyAtomicType*,
2352
 
                                    $array13 as xs:anyAtomicType*,
2353
 
                                    $array14 as xs:anyAtomicType*,
2354
 
                                    $array15 as xs:anyAtomicType*,
2355
 
                                    $array16 as xs:anyAtomicType*,
2356
 
                                    $array17 as xs:anyAtomicType*,
2357
 
                                    $array18 as xs:anyAtomicType*,
2358
 
                                    $array19 as xs:anyAtomicType*,
2359
 
                                    $array20 as xs:anyAtomicType*,
2360
 
                                    $array21 as xs:anyAtomicType*,
2361
 
                                    $array22 as xs:anyAtomicType*,
2362
 
                                    $array23 as xs:anyAtomicType*,
2363
 
                                    $array24 as xs:anyAtomicType*,
2364
 
                                    $array25 as xs:anyAtomicType*,
2365
 
                                    $array26 as xs:anyAtomicType*,
2366
 
                                    $array27 as xs:anyAtomicType*,
2367
 
                                    $array28 as xs:anyAtomicType*  ) as xs:anyAtomicType
2368
 
 {
2369
 
    if( fn:empty($array1) or 
2370
 
        fn:empty($array2) or
2371
 
        fn:empty($array3) or
2372
 
        fn:empty($array4) or
2373
 
        fn:empty($array5) or
2374
 
        fn:empty($array6) or
2375
 
        fn:empty($array7) or
2376
 
        fn:empty($array8) or
2377
 
        fn:empty($array9) or
2378
 
        fn:empty($array10) or
2379
 
        fn:empty($array11) or
2380
 
        fn:empty($array12) or
2381
 
        fn:empty($array13) or
2382
 
        fn:empty($array14) or
2383
 
        fn:empty($array15) or
2384
 
        fn:empty($array16) or
2385
 
        fn:empty($array17) or
2386
 
        fn:empty($array18) or
2387
 
        fn:empty($array19) or
2388
 
        fn:empty($array20) or
2389
 
        fn:empty($array21) or
2390
 
        fn:empty($array22) or
2391
 
        fn:empty($array23) or
2392
 
        fn:empty($array24) or
2393
 
        fn:empty($array25) or
2394
 
        fn:empty($array26) or
2395
 
        fn:empty($array27) or
2396
 
        fn:empty($array28)) 
2397
 
        then
2398
 
      0
2399
 
    else
2400
 
        excel-math:cast-as-numeric($array1[1]) * 
2401
 
        excel-math:cast-as-numeric($array2[1]) * 
2402
 
        excel-math:cast-as-numeric($array3[1]) * 
2403
 
        excel-math:cast-as-numeric($array4[1]) * 
2404
 
        excel-math:cast-as-numeric($array5[1]) * 
2405
 
        excel-math:cast-as-numeric($array6[1]) * 
2406
 
        excel-math:cast-as-numeric($array7[1]) * 
2407
 
        excel-math:cast-as-numeric($array8[1]) * 
2408
 
        excel-math:cast-as-numeric($array9[1]) * 
2409
 
        excel-math:cast-as-numeric($array10[1]) * 
2410
 
        excel-math:cast-as-numeric($array11[1]) * 
2411
 
        excel-math:cast-as-numeric($array12[1]) * 
2412
 
        excel-math:cast-as-numeric($array13[1]) * 
2413
 
        excel-math:cast-as-numeric($array14[1]) * 
2414
 
        excel-math:cast-as-numeric($array15[1]) * 
2415
 
        excel-math:cast-as-numeric($array16[1]) * 
2416
 
        excel-math:cast-as-numeric($array17[1]) * 
2417
 
        excel-math:cast-as-numeric($array18[1]) *
2418
 
        excel-math:cast-as-numeric($array19[1]) *
2419
 
        excel-math:cast-as-numeric($array20[1]) *
2420
 
        excel-math:cast-as-numeric($array21[1]) *
2421
 
        excel-math:cast-as-numeric($array22[1]) *
2422
 
        excel-math:cast-as-numeric($array23[1]) *
2423
 
        excel-math:cast-as-numeric($array24[1]) *
2424
 
        excel-math:cast-as-numeric($array25[1]) *
2425
 
        excel-math:cast-as-numeric($array26[1]) *
2426
 
        excel-math:cast-as-numeric($array27[1]) *
2427
 
        excel-math:cast-as-numeric($array28[1]) +
2428
 
                    excel:sumproduct(  fn:subsequence($array1,2),
2429
 
                                             fn:subsequence($array2,2),
2430
 
                                             fn:subsequence($array3,2),
2431
 
                                             fn:subsequence($array4,2),
2432
 
                                             fn:subsequence($array5,2),
2433
 
                                             fn:subsequence($array6,2),
2434
 
                                             fn:subsequence($array7,2),
2435
 
                                             fn:subsequence($array8,2),
2436
 
                                             fn:subsequence($array9,2),
2437
 
                                             fn:subsequence($array10,2),
2438
 
                                             fn:subsequence($array11,2),
2439
 
                                             fn:subsequence($array12,2),
2440
 
                                             fn:subsequence($array13,2),
2441
 
                                             fn:subsequence($array14,2),
2442
 
                                             fn:subsequence($array15,2),
2443
 
                                             fn:subsequence($array16,2),
2444
 
                                             fn:subsequence($array17,2),
2445
 
                                             fn:subsequence($array18,2),
2446
 
                                             fn:subsequence($array19,2),
2447
 
                                             fn:subsequence($array20,2),
2448
 
                                             fn:subsequence($array21,2),
2449
 
                                             fn:subsequence($array22,2),
2450
 
                                             fn:subsequence($array23,2),
2451
 
                                             fn:subsequence($array24,2),
2452
 
                                             fn:subsequence($array25,2),
2453
 
                                             fn:subsequence($array26,2),
2454
 
                                             fn:subsequence($array27,2),
2455
 
                                             fn:subsequence($array28,2))
2456
 
 };
2457
 
 
2458
 
 (:~
2459
 
  : Multiplies the elements on the same position in each sequence
2460
 
  : and sums up the results.
2461
 
  : 
2462
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
2463
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
2464
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
2465
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
2466
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
2467
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
2468
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
2469
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
2470
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
2471
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
2472
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
2473
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
2474
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
2475
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
2476
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
2477
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
2478
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
2479
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
2480
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
2481
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
2482
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
2483
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
2484
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
2485
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
2486
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
2487
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
2488
 
  : @param $array26 the sequences of numbers or arguments castable to numeric
2489
 
  : @param $array27 the sequences of numbers or arguments castable to numeric
2490
 
  : @param $array28 the sequences of numbers or arguments castable to numeric
2491
 
  : @param $array29 the sequences of numbers or arguments castable to numeric
2492
 
  : @return the sum of products
2493
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2494
 
:)
2495
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
2496
 
                                    $array2 as xs:anyAtomicType*,
2497
 
                                    $array3 as xs:anyAtomicType*,
2498
 
                                    $array4 as xs:anyAtomicType*,
2499
 
                                    $array5 as xs:anyAtomicType*,
2500
 
                                    $array6 as xs:anyAtomicType*,
2501
 
                                    $array7 as xs:anyAtomicType*,
2502
 
                                    $array8 as xs:anyAtomicType*,
2503
 
                                    $array9 as xs:anyAtomicType*,
2504
 
                                    $array10 as xs:anyAtomicType*,
2505
 
                                    $array11 as xs:anyAtomicType*,
2506
 
                                    $array12 as xs:anyAtomicType*,
2507
 
                                    $array13 as xs:anyAtomicType*,
2508
 
                                    $array14 as xs:anyAtomicType*,
2509
 
                                    $array15 as xs:anyAtomicType*,
2510
 
                                    $array16 as xs:anyAtomicType*,
2511
 
                                    $array17 as xs:anyAtomicType*,
2512
 
                                    $array18 as xs:anyAtomicType*,
2513
 
                                    $array19 as xs:anyAtomicType*,
2514
 
                                    $array20 as xs:anyAtomicType*,
2515
 
                                    $array21 as xs:anyAtomicType*,
2516
 
                                    $array22 as xs:anyAtomicType*,
2517
 
                                    $array23 as xs:anyAtomicType*,
2518
 
                                    $array24 as xs:anyAtomicType*,
2519
 
                                    $array25 as xs:anyAtomicType*,
2520
 
                                    $array26 as xs:anyAtomicType*,
2521
 
                                    $array27 as xs:anyAtomicType*,
2522
 
                                    $array28 as xs:anyAtomicType*,
2523
 
                                    $array29 as xs:anyAtomicType*  ) as xs:anyAtomicType
2524
 
 {
2525
 
    if( fn:empty($array1) or 
2526
 
        fn:empty($array2) or
2527
 
        fn:empty($array3) or
2528
 
        fn:empty($array4) or
2529
 
        fn:empty($array5) or
2530
 
        fn:empty($array6) or
2531
 
        fn:empty($array7) or
2532
 
        fn:empty($array8) or
2533
 
        fn:empty($array9) or
2534
 
        fn:empty($array10) or
2535
 
        fn:empty($array11) or
2536
 
        fn:empty($array12) or
2537
 
        fn:empty($array13) or
2538
 
        fn:empty($array14) or
2539
 
        fn:empty($array15) or
2540
 
        fn:empty($array16) or
2541
 
        fn:empty($array17) or
2542
 
        fn:empty($array18) or
2543
 
        fn:empty($array19) or
2544
 
        fn:empty($array20) or
2545
 
        fn:empty($array21) or
2546
 
        fn:empty($array22) or
2547
 
        fn:empty($array23) or
2548
 
        fn:empty($array24) or
2549
 
        fn:empty($array25) or
2550
 
        fn:empty($array26) or
2551
 
        fn:empty($array27) or
2552
 
        fn:empty($array28) or
2553
 
        fn:empty($array29)) 
2554
 
        then
2555
 
      0
2556
 
    else
2557
 
        excel-math:cast-as-numeric($array1[1]) * 
2558
 
        excel-math:cast-as-numeric($array2[1]) * 
2559
 
        excel-math:cast-as-numeric($array3[1]) * 
2560
 
        excel-math:cast-as-numeric($array4[1]) * 
2561
 
        excel-math:cast-as-numeric($array5[1]) * 
2562
 
        excel-math:cast-as-numeric($array6[1]) * 
2563
 
        excel-math:cast-as-numeric($array7[1]) * 
2564
 
        excel-math:cast-as-numeric($array8[1]) * 
2565
 
        excel-math:cast-as-numeric($array9[1]) * 
2566
 
        excel-math:cast-as-numeric($array10[1]) * 
2567
 
        excel-math:cast-as-numeric($array11[1]) * 
2568
 
        excel-math:cast-as-numeric($array12[1]) * 
2569
 
        excel-math:cast-as-numeric($array13[1]) * 
2570
 
        excel-math:cast-as-numeric($array14[1]) * 
2571
 
        excel-math:cast-as-numeric($array15[1]) * 
2572
 
        excel-math:cast-as-numeric($array16[1]) * 
2573
 
        excel-math:cast-as-numeric($array17[1]) * 
2574
 
        excel-math:cast-as-numeric($array18[1]) *
2575
 
        excel-math:cast-as-numeric($array19[1]) *
2576
 
        excel-math:cast-as-numeric($array20[1]) *
2577
 
        excel-math:cast-as-numeric($array21[1]) *
2578
 
        excel-math:cast-as-numeric($array22[1]) *
2579
 
        excel-math:cast-as-numeric($array23[1]) *
2580
 
        excel-math:cast-as-numeric($array24[1]) *
2581
 
        excel-math:cast-as-numeric($array25[1]) *
2582
 
        excel-math:cast-as-numeric($array26[1]) *
2583
 
        excel-math:cast-as-numeric($array27[1]) *
2584
 
        excel-math:cast-as-numeric($array28[1]) *
2585
 
        excel-math:cast-as-numeric($array29[1]) +
2586
 
                    excel:sumproduct(  fn:subsequence($array1,2),
2587
 
                                             fn:subsequence($array2,2),
2588
 
                                             fn:subsequence($array3,2),
2589
 
                                             fn:subsequence($array4,2),
2590
 
                                             fn:subsequence($array5,2),
2591
 
                                             fn:subsequence($array6,2),
2592
 
                                             fn:subsequence($array7,2),
2593
 
                                             fn:subsequence($array8,2),
2594
 
                                             fn:subsequence($array9,2),
2595
 
                                             fn:subsequence($array10,2),
2596
 
                                             fn:subsequence($array11,2),
2597
 
                                             fn:subsequence($array12,2),
2598
 
                                             fn:subsequence($array13,2),
2599
 
                                             fn:subsequence($array14,2),
2600
 
                                             fn:subsequence($array15,2),
2601
 
                                             fn:subsequence($array16,2),
2602
 
                                             fn:subsequence($array17,2),
2603
 
                                             fn:subsequence($array18,2),
2604
 
                                             fn:subsequence($array19,2),
2605
 
                                             fn:subsequence($array20,2),
2606
 
                                             fn:subsequence($array21,2),
2607
 
                                             fn:subsequence($array22,2),
2608
 
                                             fn:subsequence($array23,2),
2609
 
                                             fn:subsequence($array24,2),
2610
 
                                             fn:subsequence($array25,2),
2611
 
                                             fn:subsequence($array26,2),
2612
 
                                             fn:subsequence($array27,2),
2613
 
                                             fn:subsequence($array28,2),
2614
 
                                             fn:subsequence($array29,2))
2615
 
 };
2616
 
 
2617
 
 (:~
2618
 
  : Multiplies the elements on the same position in each sequence
2619
 
  : and sums up the results.
2620
 
  : 
2621
 
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
2622
 
  : @param $array1 the sequences of numbers or arguments castable to numeric
2623
 
  : @param $array2 the sequences of numbers or arguments castable to numeric
2624
 
  : @param $array3 the sequences of numbers or arguments castable to numeric
2625
 
  : @param $array4 the sequences of numbers or arguments castable to numeric
2626
 
  : @param $array5 the sequences of numbers or arguments castable to numeric
2627
 
  : @param $array6 the sequences of numbers or arguments castable to numeric
2628
 
  : @param $array7 the sequences of numbers or arguments castable to numeric
2629
 
  : @param $array8 the sequences of numbers or arguments castable to numeric
2630
 
  : @param $array9 the sequences of numbers or arguments castable to numeric
2631
 
  : @param $array10 the sequences of numbers or arguments castable to numeric
2632
 
  : @param $array11 the sequences of numbers or arguments castable to numeric
2633
 
  : @param $array12 the sequences of numbers or arguments castable to numeric
2634
 
  : @param $array13 the sequences of numbers or arguments castable to numeric
2635
 
  : @param $array14 the sequences of numbers or arguments castable to numeric
2636
 
  : @param $array15 the sequences of numbers or arguments castable to numeric
2637
 
  : @param $array16 the sequences of numbers or arguments castable to numeric
2638
 
  : @param $array17 the sequences of numbers or arguments castable to numeric
2639
 
  : @param $array18 the sequences of numbers or arguments castable to numeric
2640
 
  : @param $array19 the sequences of numbers or arguments castable to numeric
2641
 
  : @param $array20 the sequences of numbers or arguments castable to numeric
2642
 
  : @param $array21 the sequences of numbers or arguments castable to numeric
2643
 
  : @param $array22 the sequences of numbers or arguments castable to numeric
2644
 
  : @param $array23 the sequences of numbers or arguments castable to numeric
2645
 
  : @param $array24 the sequences of numbers or arguments castable to numeric
2646
 
  : @param $array25 the sequences of numbers or arguments castable to numeric
2647
 
  : @param $array26 the sequences of numbers or arguments castable to numeric
2648
 
  : @param $array27 the sequences of numbers or arguments castable to numeric
2649
 
  : @param $array28 the sequences of numbers or arguments castable to numeric
2650
 
  : @param $array29 the sequences of numbers or arguments castable to numeric
2651
 
  : @param $array30 the sequences of numbers or arguments castable to numeric
2652
 
  : @return the sum of products
2653
 
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2654
 
:)
2655
 
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
2656
 
                                    $array2 as xs:anyAtomicType*,
2657
 
                                    $array3 as xs:anyAtomicType*,
2658
 
                                    $array4 as xs:anyAtomicType*,
2659
 
                                    $array5 as xs:anyAtomicType*,
2660
 
                                    $array6 as xs:anyAtomicType*,
2661
 
                                    $array7 as xs:anyAtomicType*,
2662
 
                                    $array8 as xs:anyAtomicType*,
2663
 
                                    $array9 as xs:anyAtomicType*,
2664
 
                                    $array10 as xs:anyAtomicType*,
2665
 
                                    $array11 as xs:anyAtomicType*,
2666
 
                                    $array12 as xs:anyAtomicType*,
2667
 
                                    $array13 as xs:anyAtomicType*,
2668
 
                                    $array14 as xs:anyAtomicType*,
2669
 
                                    $array15 as xs:anyAtomicType*,
2670
 
                                    $array16 as xs:anyAtomicType*,
2671
 
                                    $array17 as xs:anyAtomicType*,
2672
 
                                    $array18 as xs:anyAtomicType*,
2673
 
                                    $array19 as xs:anyAtomicType*,
2674
 
                                    $array20 as xs:anyAtomicType*,
2675
 
                                    $array21 as xs:anyAtomicType*,
2676
 
                                    $array22 as xs:anyAtomicType*,
2677
 
                                    $array23 as xs:anyAtomicType*,
2678
 
                                    $array24 as xs:anyAtomicType*,
2679
 
                                    $array25 as xs:anyAtomicType*,
2680
 
                                    $array26 as xs:anyAtomicType*,
2681
 
                                    $array27 as xs:anyAtomicType*,
2682
 
                                    $array28 as xs:anyAtomicType*,
2683
 
                                    $array29 as xs:anyAtomicType*,
2684
 
                                    $array30 as xs:anyAtomicType*  ) as xs:anyAtomicType
2685
 
 {
2686
 
    if( fn:empty($array1) or 
2687
 
        fn:empty($array2) or
2688
 
        fn:empty($array3) or
2689
 
        fn:empty($array4) or
2690
 
        fn:empty($array5) or
2691
 
        fn:empty($array6) or
2692
 
        fn:empty($array7) or
2693
 
        fn:empty($array8) or
2694
 
        fn:empty($array9) or
2695
 
        fn:empty($array10) or
2696
 
        fn:empty($array11) or
2697
 
        fn:empty($array12) or
2698
 
        fn:empty($array13) or
2699
 
        fn:empty($array14) or
2700
 
        fn:empty($array15) or
2701
 
        fn:empty($array16) or
2702
 
        fn:empty($array17) or
2703
 
        fn:empty($array18) or
2704
 
        fn:empty($array19) or
2705
 
        fn:empty($array20) or
2706
 
        fn:empty($array21) or
2707
 
        fn:empty($array22) or
2708
 
        fn:empty($array23) or
2709
 
        fn:empty($array24) or
2710
 
        fn:empty($array25) or
2711
 
        fn:empty($array26) or
2712
 
        fn:empty($array27) or
2713
 
        fn:empty($array28) or
2714
 
        fn:empty($array29) or
2715
 
        fn:empty($array30)) 
2716
 
        then
2717
 
      0
2718
 
    else
2719
 
        excel-math:cast-as-numeric($array1[1]) * 
2720
 
        excel-math:cast-as-numeric($array2[1]) * 
2721
 
        excel-math:cast-as-numeric($array3[1]) * 
2722
 
        excel-math:cast-as-numeric($array4[1]) * 
2723
 
        excel-math:cast-as-numeric($array5[1]) * 
2724
 
        excel-math:cast-as-numeric($array6[1]) * 
2725
 
        excel-math:cast-as-numeric($array7[1]) * 
2726
 
        excel-math:cast-as-numeric($array8[1]) * 
2727
 
        excel-math:cast-as-numeric($array9[1]) * 
2728
 
        excel-math:cast-as-numeric($array10[1]) * 
2729
 
        excel-math:cast-as-numeric($array11[1]) * 
2730
 
        excel-math:cast-as-numeric($array12[1]) * 
2731
 
        excel-math:cast-as-numeric($array13[1]) * 
2732
 
        excel-math:cast-as-numeric($array14[1]) * 
2733
 
        excel-math:cast-as-numeric($array15[1]) * 
2734
 
        excel-math:cast-as-numeric($array16[1]) * 
2735
 
        excel-math:cast-as-numeric($array17[1]) * 
2736
 
        excel-math:cast-as-numeric($array18[1]) *
2737
 
        excel-math:cast-as-numeric($array19[1]) *
2738
 
        excel-math:cast-as-numeric($array20[1]) *
2739
 
        excel-math:cast-as-numeric($array21[1]) *
2740
 
        excel-math:cast-as-numeric($array22[1]) *
2741
 
        excel-math:cast-as-numeric($array23[1]) *
2742
 
        excel-math:cast-as-numeric($array24[1]) *
2743
 
        excel-math:cast-as-numeric($array25[1]) *
2744
 
        excel-math:cast-as-numeric($array26[1]) *
2745
 
        excel-math:cast-as-numeric($array27[1]) *
2746
 
        excel-math:cast-as-numeric($array28[1]) *
2747
 
        excel-math:cast-as-numeric($array29[1]) *
2748
 
        excel-math:cast-as-numeric($array30[1]) +
2749
 
                    excel:sumproduct(  fn:subsequence($array1,2),
2750
 
                                             fn:subsequence($array2,2),
2751
 
                                             fn:subsequence($array3,2),
2752
 
                                             fn:subsequence($array4,2),
2753
 
                                             fn:subsequence($array5,2),
2754
 
                                             fn:subsequence($array6,2),
2755
 
                                             fn:subsequence($array7,2),
2756
 
                                             fn:subsequence($array8,2),
2757
 
                                             fn:subsequence($array9,2),
2758
 
                                             fn:subsequence($array10,2),
2759
 
                                             fn:subsequence($array11,2),
2760
 
                                             fn:subsequence($array12,2),
2761
 
                                             fn:subsequence($array13,2),
2762
 
                                             fn:subsequence($array14,2),
2763
 
                                             fn:subsequence($array15,2),
2764
 
                                             fn:subsequence($array16,2),
2765
 
                                             fn:subsequence($array17,2),
2766
 
                                             fn:subsequence($array18,2),
2767
 
                                             fn:subsequence($array19,2),
2768
 
                                             fn:subsequence($array20,2),
2769
 
                                             fn:subsequence($array21,2),
2770
 
                                             fn:subsequence($array22,2),
2771
 
                                             fn:subsequence($array23,2),
2772
 
                                             fn:subsequence($array24,2),
2773
 
                                             fn:subsequence($array25,2),
2774
 
                                             fn:subsequence($array26,2),
2775
 
                                             fn:subsequence($array27,2),
2776
 
                                             fn:subsequence($array28,2),
2777
 
                                             fn:subsequence($array29,2),
2778
 
                                             fn:subsequence($array30,2))
2779
 
 };
2780
 
 
2781
 
(:~
2782
 
 : Returns the sum of the squares of the arguments.
2783
 
 : It used the sumproduct function.
2784
 
 : 
2785
 
 : @see http://office.microsoft.com/en-us/excel/HP052092951033.aspx
2786
 
 : @param $numbers the sequence of one or more numbers or arguments castable to numeric
2787
 
 : @return the sum of squared values, as numeric type
2788
 
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
2789
 
 : @example rbkt/Queries/zorba/excel/math/sumsq1.xq
2790
 
:)
2791
 
 declare function excel:sumsq( $numbers as xs:anyAtomicType+) as xs:anyAtomicType
2792
 
 {
2793
 
   excel:sumproduct($numbers, $numbers)
2794
 
 };
2795
 
 
 
1
(:
 
2
 : Copyright 2006-2009 The FLWOR Foundation.
 
3
 :
 
4
 : Licensed under the Apache License, Version 2.0 (the "License");
 
5
 : you may not use this file except in compliance with the License.
 
6
 : You may obtain a copy of the License at
 
7
 :
 
8
 : http://www.apache.org/licenses/LICENSE-2.0
 
9
 :
 
10
 : Unless required by applicable law or agreed to in writing, software
 
11
 : distributed under the License is distributed on an "AS IS" BASIS,
 
12
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 : See the License for the specific language governing permissions and
 
14
 : limitations under the License.
 
15
:)
 
16
 
 
17
(:~
 
18
 : Module implementing the sumproduct functions from Excel 2003 math library.
 
19
 : There are 30 functions defined, implementing the same function
 
20
 : but with 1 to 30 parameters.
 
21
 : Each parameter can be a sequence of infinite length.
 
22
 :
 
23
 : @see <a href="http://office.microsoft.com/en-us/excel/HP052092931033.aspx"
 
24
 : target="_blank">Excel 2003 Documentation: Math-sumproduct Functions</a>
 
25
 :
 
26
 : @spec XQuery Specification: January 2007
 
27
 : @author Daniel Turcanu
 
28
 :
 
29
 :)
 
30
module namespace  excel = "http://www.zorba-xquery.com/modules/excel/math-sumproduct";
 
31
 
 
32
(:~
 
33
 : Import excel-math module functions.
 
34
:)
 
35
import module namespace excel-math = "http://www.zorba-xquery.com/modules/excel/math";
 
36
 
 
37
 
 
38
(:~
 
39
 : Sums the values in the sequence.
 
40
 : The sequence can be of any length.
 
41
 : 
 
42
 : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
43
 : @param $array1 the sequence of numbers or arguments castable to numeric
 
44
 : @return the sum
 
45
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
46
 : @example rbkt/Queries/zorba/excel/math/sumproduct1.xq
 
47
:)
 
48
declare function excel:sumproduct( $array1 as xs:anyAtomicType*) as xs:anyAtomicType
 
49
 {
 
50
   excel-math:sum( $array1 )
 
51
 };
 
52
 
 
53
(:~
 
54
 : Multiplies the elements on the same position in each sequence
 
55
 : and sums up the results.
 
56
 : 
 
57
 : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
58
 : @param $array1 the sequences of numbers or arguments castable to numeric
 
59
 : @param $array2 the sequences of numbers or arguments castable to numeric
 
60
 : @return the sum of products
 
61
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
62
 : @example rbkt/Queries/zorba/excel/math/sumproduct2.xq
 
63
:)
 
64
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
65
                                    $array2 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
66
 {
 
67
    if( fn:empty($array1) or 
 
68
        fn:empty($array2)) 
 
69
        then
 
70
      0
 
71
    else
 
72
      excel-math:cast-as-numeric($array1[1]) * 
 
73
      excel-math:cast-as-numeric($array2[1]) + excel:sumproduct( fn:subsequence($array1,2),
 
74
                                                          fn:subsequence($array2,2))
 
75
 };
 
76
 
 
77
 (:~
 
78
  : Multiplies the elements on the same position in each sequence
 
79
  : and sums up the results.
 
80
  : 
 
81
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
82
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
83
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
84
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
85
  : @return the sum of products
 
86
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
87
  : @example rbkt/Queries/zorba/excel/math/sumproduct3.xq
 
88
:)
 
89
declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
90
                                    $array2 as xs:anyAtomicType*,
 
91
                                    $array3 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
92
 {
 
93
    if( fn:empty($array1) or 
 
94
        fn:empty($array2) or
 
95
        fn:empty($array3)) 
 
96
        then
 
97
      0
 
98
    else
 
99
        excel-math:cast-as-numeric($array1[1]) * 
 
100
        excel-math:cast-as-numeric($array2[1]) * 
 
101
        excel-math:cast-as-numeric($array3[1]) +
 
102
                    excel:sumproduct(  fn:subsequence($array1,2),
 
103
                                             fn:subsequence($array2,2),
 
104
                                             fn:subsequence($array3,2))
 
105
 };
 
106
 
 
107
 (:~
 
108
  : Multiplies the elements on the same position in each sequence
 
109
  : and sums up the results.
 
110
  : 
 
111
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
112
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
113
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
114
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
115
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
116
  : @return the sum of products
 
117
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
118
:)
 
119
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
120
                                    $array2 as xs:anyAtomicType*,
 
121
                                    $array3 as xs:anyAtomicType*,
 
122
                                    $array4 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
123
 {
 
124
    if( fn:empty($array1) or 
 
125
        fn:empty($array2) or
 
126
        fn:empty($array3) or
 
127
        fn:empty($array4)) 
 
128
        then
 
129
      0
 
130
    else
 
131
        excel-math:cast-as-numeric($array1[1]) * 
 
132
        excel-math:cast-as-numeric($array2[1]) * 
 
133
        excel-math:cast-as-numeric($array3[1]) * 
 
134
        excel-math:cast-as-numeric($array4[1]) +
 
135
                    excel:sumproduct(  fn:subsequence($array1,2),
 
136
                                             fn:subsequence($array2,2),
 
137
                                             fn:subsequence($array3,2),
 
138
                                             fn:subsequence($array4,2))
 
139
 };
 
140
 
 
141
 (:~
 
142
  : Multiplies the elements on the same position in each sequence
 
143
  : and sums up the results.
 
144
  : 
 
145
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
146
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
147
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
148
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
149
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
150
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
151
  : @return the sum of products
 
152
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
153
:)
 
154
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
155
                                    $array2 as xs:anyAtomicType*,
 
156
                                    $array3 as xs:anyAtomicType*,
 
157
                                    $array4 as xs:anyAtomicType*,
 
158
                                    $array5 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
159
 {
 
160
    if( fn:empty($array1) or 
 
161
        fn:empty($array2) or
 
162
        fn:empty($array3) or
 
163
        fn:empty($array4) or
 
164
        fn:empty($array5)) 
 
165
        then
 
166
      0
 
167
    else
 
168
        excel-math:cast-as-numeric($array1[1]) * 
 
169
        excel-math:cast-as-numeric($array2[1]) * 
 
170
        excel-math:cast-as-numeric($array3[1]) * 
 
171
        excel-math:cast-as-numeric($array4[1]) * 
 
172
        excel-math:cast-as-numeric($array5[1]) +
 
173
                    excel:sumproduct(  fn:subsequence($array1,2),
 
174
                                             fn:subsequence($array2,2),
 
175
                                             fn:subsequence($array3,2),
 
176
                                             fn:subsequence($array4,2),
 
177
                                             fn:subsequence($array5,2))
 
178
 };
 
179
 
 
180
 (:~
 
181
  : Multiplies the elements on the same position in each sequence
 
182
  : and sums up the results.
 
183
  : 
 
184
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
185
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
186
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
187
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
188
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
189
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
190
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
191
  : @return the sum of products
 
192
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
193
:)
 
194
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
195
                                    $array2 as xs:anyAtomicType*,
 
196
                                    $array3 as xs:anyAtomicType*,
 
197
                                    $array4 as xs:anyAtomicType*,
 
198
                                    $array5 as xs:anyAtomicType*,
 
199
                                    $array6 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
200
 {
 
201
    if( fn:empty($array1) or 
 
202
        fn:empty($array2) or
 
203
        fn:empty($array3) or
 
204
        fn:empty($array4) or
 
205
        fn:empty($array5) or
 
206
        fn:empty($array6)) 
 
207
        then
 
208
      0
 
209
    else
 
210
        excel-math:cast-as-numeric($array1[1]) * 
 
211
        excel-math:cast-as-numeric($array2[1]) * 
 
212
        excel-math:cast-as-numeric($array3[1]) * 
 
213
        excel-math:cast-as-numeric($array4[1]) * 
 
214
        excel-math:cast-as-numeric($array5[1]) * 
 
215
        excel-math:cast-as-numeric($array6[1]) +
 
216
                    excel:sumproduct(  fn:subsequence($array1,2),
 
217
                                             fn:subsequence($array2,2),
 
218
                                             fn:subsequence($array3,2),
 
219
                                             fn:subsequence($array4,2),
 
220
                                             fn:subsequence($array5,2),
 
221
                                             fn:subsequence($array6,2))
 
222
 };
 
223
 
 
224
 (:~
 
225
  : Multiplies the elements on the same position in each sequence
 
226
  : and sums up the results.
 
227
  : 
 
228
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
229
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
230
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
231
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
232
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
233
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
234
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
235
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
236
  : @return the sum of products
 
237
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
238
:)
 
239
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
240
                                    $array2 as xs:anyAtomicType*,
 
241
                                    $array3 as xs:anyAtomicType*,
 
242
                                    $array4 as xs:anyAtomicType*,
 
243
                                    $array5 as xs:anyAtomicType*,
 
244
                                    $array6 as xs:anyAtomicType*,
 
245
                                    $array7 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
246
 {
 
247
    if( fn:empty($array1) or 
 
248
        fn:empty($array2) or
 
249
        fn:empty($array3) or
 
250
        fn:empty($array4) or
 
251
        fn:empty($array5) or
 
252
        fn:empty($array6) or
 
253
        fn:empty($array7)) 
 
254
        then
 
255
      0
 
256
    else
 
257
        excel-math:cast-as-numeric($array1[1]) * 
 
258
        excel-math:cast-as-numeric($array2[1]) * 
 
259
        excel-math:cast-as-numeric($array3[1]) * 
 
260
        excel-math:cast-as-numeric($array4[1]) * 
 
261
        excel-math:cast-as-numeric($array5[1]) * 
 
262
        excel-math:cast-as-numeric($array6[1]) * 
 
263
        excel-math:cast-as-numeric($array7[1]) +
 
264
                    excel:sumproduct(  fn:subsequence($array1,2),
 
265
                                             fn:subsequence($array2,2),
 
266
                                             fn:subsequence($array3,2),
 
267
                                             fn:subsequence($array4,2),
 
268
                                             fn:subsequence($array5,2),
 
269
                                             fn:subsequence($array6,2),
 
270
                                             fn:subsequence($array7,2))
 
271
 };
 
272
 
 
273
 (:~
 
274
  : Multiplies the elements on the same position in each sequence
 
275
  : and sums up the results.
 
276
  : 
 
277
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
278
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
279
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
280
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
281
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
282
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
283
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
284
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
285
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
286
  : @return the sum of products
 
287
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
288
:)
 
289
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
290
                                    $array2 as xs:anyAtomicType*,
 
291
                                    $array3 as xs:anyAtomicType*,
 
292
                                    $array4 as xs:anyAtomicType*,
 
293
                                    $array5 as xs:anyAtomicType*,
 
294
                                    $array6 as xs:anyAtomicType*,
 
295
                                    $array7 as xs:anyAtomicType*,
 
296
                                    $array8 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
297
 {
 
298
    if( fn:empty($array1) or 
 
299
        fn:empty($array2) or
 
300
        fn:empty($array3) or
 
301
        fn:empty($array4) or
 
302
        fn:empty($array5) or
 
303
        fn:empty($array6) or
 
304
        fn:empty($array7) or
 
305
        fn:empty($array8)) 
 
306
        then
 
307
      0
 
308
    else
 
309
        excel-math:cast-as-numeric($array1[1]) * 
 
310
        excel-math:cast-as-numeric($array2[1]) * 
 
311
        excel-math:cast-as-numeric($array3[1]) * 
 
312
        excel-math:cast-as-numeric($array4[1]) * 
 
313
        excel-math:cast-as-numeric($array5[1]) * 
 
314
        excel-math:cast-as-numeric($array6[1]) * 
 
315
        excel-math:cast-as-numeric($array7[1]) * 
 
316
        excel-math:cast-as-numeric($array8[1]) +
 
317
                    excel:sumproduct(  fn:subsequence($array1,2),
 
318
                                             fn:subsequence($array2,2),
 
319
                                             fn:subsequence($array3,2),
 
320
                                             fn:subsequence($array4,2),
 
321
                                             fn:subsequence($array5,2),
 
322
                                             fn:subsequence($array6,2),
 
323
                                             fn:subsequence($array7,2),
 
324
                                             fn:subsequence($array8,2))
 
325
 };
 
326
 
 
327
 (:~
 
328
  : Multiplies the elements on the same position in each sequence
 
329
  : and sums up the results.
 
330
  : 
 
331
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
332
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
333
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
334
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
335
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
336
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
337
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
338
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
339
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
340
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
341
  : @return the sum of products
 
342
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
343
:)
 
344
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
345
                                    $array2 as xs:anyAtomicType*,
 
346
                                    $array3 as xs:anyAtomicType*,
 
347
                                    $array4 as xs:anyAtomicType*,
 
348
                                    $array5 as xs:anyAtomicType*,
 
349
                                    $array6 as xs:anyAtomicType*,
 
350
                                    $array7 as xs:anyAtomicType*,
 
351
                                    $array8 as xs:anyAtomicType*,
 
352
                                    $array9 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
353
 {
 
354
    if( fn:empty($array1) or 
 
355
        fn:empty($array2) or
 
356
        fn:empty($array3) or
 
357
        fn:empty($array4) or
 
358
        fn:empty($array5) or
 
359
        fn:empty($array6) or
 
360
        fn:empty($array7) or
 
361
        fn:empty($array8) or
 
362
        fn:empty($array9)) 
 
363
        then
 
364
      0
 
365
    else
 
366
        excel-math:cast-as-numeric($array1[1]) * 
 
367
        excel-math:cast-as-numeric($array2[1]) * 
 
368
        excel-math:cast-as-numeric($array3[1]) * 
 
369
        excel-math:cast-as-numeric($array4[1]) * 
 
370
        excel-math:cast-as-numeric($array5[1]) * 
 
371
        excel-math:cast-as-numeric($array6[1]) * 
 
372
        excel-math:cast-as-numeric($array7[1]) * 
 
373
        excel-math:cast-as-numeric($array8[1]) * 
 
374
        excel-math:cast-as-numeric($array9[1]) +
 
375
                    excel:sumproduct(  fn:subsequence($array1,2),
 
376
                                             fn:subsequence($array2,2),
 
377
                                             fn:subsequence($array3,2),
 
378
                                             fn:subsequence($array4,2),
 
379
                                             fn:subsequence($array5,2),
 
380
                                             fn:subsequence($array6,2),
 
381
                                             fn:subsequence($array7,2),
 
382
                                             fn:subsequence($array8,2),
 
383
                                             fn:subsequence($array9,2))
 
384
 };
 
385
 
 
386
 (:~
 
387
  : Multiplies the elements on the same position in each sequence
 
388
  : and sums up the results.
 
389
  : 
 
390
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
391
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
392
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
393
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
394
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
395
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
396
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
397
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
398
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
399
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
400
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
401
  : @return the sum of products
 
402
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
403
:)
 
404
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
405
                                    $array2 as xs:anyAtomicType*,
 
406
                                    $array3 as xs:anyAtomicType*,
 
407
                                    $array4 as xs:anyAtomicType*,
 
408
                                    $array5 as xs:anyAtomicType*,
 
409
                                    $array6 as xs:anyAtomicType*,
 
410
                                    $array7 as xs:anyAtomicType*,
 
411
                                    $array8 as xs:anyAtomicType*,
 
412
                                    $array9 as xs:anyAtomicType*,
 
413
                                    $array10 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
414
 {
 
415
    if( fn:empty($array1) or 
 
416
        fn:empty($array2) or
 
417
        fn:empty($array3) or
 
418
        fn:empty($array4) or
 
419
        fn:empty($array5) or
 
420
        fn:empty($array6) or
 
421
        fn:empty($array7) or
 
422
        fn:empty($array8) or
 
423
        fn:empty($array9) or
 
424
        fn:empty($array10)) 
 
425
        then
 
426
      0
 
427
    else
 
428
        excel-math:cast-as-numeric($array1[1]) * 
 
429
        excel-math:cast-as-numeric($array2[1]) * 
 
430
        excel-math:cast-as-numeric($array3[1]) * 
 
431
        excel-math:cast-as-numeric($array4[1]) * 
 
432
        excel-math:cast-as-numeric($array5[1]) * 
 
433
        excel-math:cast-as-numeric($array6[1]) * 
 
434
        excel-math:cast-as-numeric($array7[1]) * 
 
435
        excel-math:cast-as-numeric($array8[1]) * 
 
436
        excel-math:cast-as-numeric($array9[1]) * 
 
437
        excel-math:cast-as-numeric($array10[1]) +
 
438
                    excel:sumproduct(  fn:subsequence($array1,2),
 
439
                                             fn:subsequence($array2,2),
 
440
                                             fn:subsequence($array3,2),
 
441
                                             fn:subsequence($array4,2),
 
442
                                             fn:subsequence($array5,2),
 
443
                                             fn:subsequence($array6,2),
 
444
                                             fn:subsequence($array7,2),
 
445
                                             fn:subsequence($array8,2),
 
446
                                             fn:subsequence($array9,2),
 
447
                                             fn:subsequence($array10,2))
 
448
 };
 
449
 
 
450
 (:~
 
451
  : Multiplies the elements on the same position in each sequence
 
452
  : and sums up the results.
 
453
  : 
 
454
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
455
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
456
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
457
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
458
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
459
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
460
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
461
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
462
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
463
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
464
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
465
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
466
  : @return the sum of products
 
467
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
468
:)
 
469
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
470
                                    $array2 as xs:anyAtomicType*,
 
471
                                    $array3 as xs:anyAtomicType*,
 
472
                                    $array4 as xs:anyAtomicType*,
 
473
                                    $array5 as xs:anyAtomicType*,
 
474
                                    $array6 as xs:anyAtomicType*,
 
475
                                    $array7 as xs:anyAtomicType*,
 
476
                                    $array8 as xs:anyAtomicType*,
 
477
                                    $array9 as xs:anyAtomicType*,
 
478
                                    $array10 as xs:anyAtomicType*,
 
479
                                    $array11 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
480
 {
 
481
    if( fn:empty($array1) or 
 
482
        fn:empty($array2) or
 
483
        fn:empty($array3) or
 
484
        fn:empty($array4) or
 
485
        fn:empty($array5) or
 
486
        fn:empty($array6) or
 
487
        fn:empty($array7) or
 
488
        fn:empty($array8) or
 
489
        fn:empty($array9) or
 
490
        fn:empty($array10) or
 
491
        fn:empty($array11)) 
 
492
        then
 
493
      0
 
494
    else
 
495
        excel-math:cast-as-numeric($array1[1]) * 
 
496
        excel-math:cast-as-numeric($array2[1]) * 
 
497
        excel-math:cast-as-numeric($array3[1]) * 
 
498
        excel-math:cast-as-numeric($array4[1]) * 
 
499
        excel-math:cast-as-numeric($array5[1]) * 
 
500
        excel-math:cast-as-numeric($array6[1]) * 
 
501
        excel-math:cast-as-numeric($array7[1]) * 
 
502
        excel-math:cast-as-numeric($array8[1]) * 
 
503
        excel-math:cast-as-numeric($array9[1]) * 
 
504
        excel-math:cast-as-numeric($array10[1]) * 
 
505
        excel-math:cast-as-numeric($array11[1]) +
 
506
                    excel:sumproduct(  fn:subsequence($array1,2),
 
507
                                             fn:subsequence($array2,2),
 
508
                                             fn:subsequence($array3,2),
 
509
                                             fn:subsequence($array4,2),
 
510
                                             fn:subsequence($array5,2),
 
511
                                             fn:subsequence($array6,2),
 
512
                                             fn:subsequence($array7,2),
 
513
                                             fn:subsequence($array8,2),
 
514
                                             fn:subsequence($array9,2),
 
515
                                             fn:subsequence($array10,2),
 
516
                                             fn:subsequence($array11,2))
 
517
 };
 
518
 
 
519
 (:~
 
520
  : Multiplies the elements on the same position in each sequence
 
521
  : and sums up the results.
 
522
  : 
 
523
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
524
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
525
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
526
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
527
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
528
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
529
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
530
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
531
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
532
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
533
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
534
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
535
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
536
  : @return the sum of products
 
537
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
538
:)
 
539
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
540
                                    $array2 as xs:anyAtomicType*,
 
541
                                    $array3 as xs:anyAtomicType*,
 
542
                                    $array4 as xs:anyAtomicType*,
 
543
                                    $array5 as xs:anyAtomicType*,
 
544
                                    $array6 as xs:anyAtomicType*,
 
545
                                    $array7 as xs:anyAtomicType*,
 
546
                                    $array8 as xs:anyAtomicType*,
 
547
                                    $array9 as xs:anyAtomicType*,
 
548
                                    $array10 as xs:anyAtomicType*,
 
549
                                    $array11 as xs:anyAtomicType*,
 
550
                                    $array12 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
551
 {
 
552
    if( fn:empty($array1) or 
 
553
        fn:empty($array2) or
 
554
        fn:empty($array3) or
 
555
        fn:empty($array4) or
 
556
        fn:empty($array5) or
 
557
        fn:empty($array6) or
 
558
        fn:empty($array7) or
 
559
        fn:empty($array8) or
 
560
        fn:empty($array9) or
 
561
        fn:empty($array10) or
 
562
        fn:empty($array11) or
 
563
        fn:empty($array12)) 
 
564
        then
 
565
      0
 
566
    else
 
567
        excel-math:cast-as-numeric($array1[1]) * 
 
568
        excel-math:cast-as-numeric($array2[1]) * 
 
569
        excel-math:cast-as-numeric($array3[1]) * 
 
570
        excel-math:cast-as-numeric($array4[1]) * 
 
571
        excel-math:cast-as-numeric($array5[1]) * 
 
572
        excel-math:cast-as-numeric($array6[1]) * 
 
573
        excel-math:cast-as-numeric($array7[1]) * 
 
574
        excel-math:cast-as-numeric($array8[1]) * 
 
575
        excel-math:cast-as-numeric($array9[1]) * 
 
576
        excel-math:cast-as-numeric($array10[1]) * 
 
577
        excel-math:cast-as-numeric($array11[1]) * 
 
578
        excel-math:cast-as-numeric($array12[1]) +
 
579
                    excel:sumproduct(  fn:subsequence($array1,2),
 
580
                                             fn:subsequence($array2,2),
 
581
                                             fn:subsequence($array3,2),
 
582
                                             fn:subsequence($array4,2),
 
583
                                             fn:subsequence($array5,2),
 
584
                                             fn:subsequence($array6,2),
 
585
                                             fn:subsequence($array7,2),
 
586
                                             fn:subsequence($array8,2),
 
587
                                             fn:subsequence($array9,2),
 
588
                                             fn:subsequence($array10,2),
 
589
                                             fn:subsequence($array11,2),
 
590
                                             fn:subsequence($array12,2))
 
591
 };
 
592
 
 
593
 
 
594
 (:~
 
595
  : Multiplies the elements on the same position in each sequence
 
596
  : and sums up the results.
 
597
  : 
 
598
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
599
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
600
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
601
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
602
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
603
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
604
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
605
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
606
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
607
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
608
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
609
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
610
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
611
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
612
  : @return the sum of products
 
613
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
614
:)
 
615
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
616
                                    $array2 as xs:anyAtomicType*,
 
617
                                    $array3 as xs:anyAtomicType*,
 
618
                                    $array4 as xs:anyAtomicType*,
 
619
                                    $array5 as xs:anyAtomicType*,
 
620
                                    $array6 as xs:anyAtomicType*,
 
621
                                    $array7 as xs:anyAtomicType*,
 
622
                                    $array8 as xs:anyAtomicType*,
 
623
                                    $array9 as xs:anyAtomicType*,
 
624
                                    $array10 as xs:anyAtomicType*,
 
625
                                    $array11 as xs:anyAtomicType*,
 
626
                                    $array12 as xs:anyAtomicType*,
 
627
                                    $array13 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
628
 {
 
629
    if( fn:empty($array1) or 
 
630
        fn:empty($array2) or
 
631
        fn:empty($array3) or
 
632
        fn:empty($array4) or
 
633
        fn:empty($array5) or
 
634
        fn:empty($array6) or
 
635
        fn:empty($array7) or
 
636
        fn:empty($array8) or
 
637
        fn:empty($array9) or
 
638
        fn:empty($array10) or
 
639
        fn:empty($array11) or
 
640
        fn:empty($array12) or
 
641
        fn:empty($array13)) 
 
642
        then
 
643
      0
 
644
    else
 
645
        excel-math:cast-as-numeric($array1[1]) * 
 
646
        excel-math:cast-as-numeric($array2[1]) * 
 
647
        excel-math:cast-as-numeric($array3[1]) * 
 
648
        excel-math:cast-as-numeric($array4[1]) * 
 
649
        excel-math:cast-as-numeric($array5[1]) * 
 
650
        excel-math:cast-as-numeric($array6[1]) * 
 
651
        excel-math:cast-as-numeric($array7[1]) * 
 
652
        excel-math:cast-as-numeric($array8[1]) * 
 
653
        excel-math:cast-as-numeric($array9[1]) * 
 
654
        excel-math:cast-as-numeric($array10[1]) * 
 
655
        excel-math:cast-as-numeric($array11[1]) * 
 
656
        excel-math:cast-as-numeric($array12[1]) * 
 
657
        excel-math:cast-as-numeric($array13[1]) +
 
658
                    excel:sumproduct(  fn:subsequence($array1,2),
 
659
                                             fn:subsequence($array2,2),
 
660
                                             fn:subsequence($array3,2),
 
661
                                             fn:subsequence($array4,2),
 
662
                                             fn:subsequence($array5,2),
 
663
                                             fn:subsequence($array6,2),
 
664
                                             fn:subsequence($array7,2),
 
665
                                             fn:subsequence($array8,2),
 
666
                                             fn:subsequence($array9,2),
 
667
                                             fn:subsequence($array10,2),
 
668
                                             fn:subsequence($array11,2),
 
669
                                             fn:subsequence($array12,2),
 
670
                                             fn:subsequence($array13,2))
 
671
 };
 
672
 
 
673
 (:~
 
674
  : Multiplies the elements on the same position in each sequence
 
675
  : and sums up the results.
 
676
  : 
 
677
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
678
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
679
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
680
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
681
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
682
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
683
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
684
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
685
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
686
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
687
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
688
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
689
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
690
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
691
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
692
  : @return the sum of products
 
693
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
694
:)
 
695
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
696
                                    $array2 as xs:anyAtomicType*,
 
697
                                    $array3 as xs:anyAtomicType*,
 
698
                                    $array4 as xs:anyAtomicType*,
 
699
                                    $array5 as xs:anyAtomicType*,
 
700
                                    $array6 as xs:anyAtomicType*,
 
701
                                    $array7 as xs:anyAtomicType*,
 
702
                                    $array8 as xs:anyAtomicType*,
 
703
                                    $array9 as xs:anyAtomicType*,
 
704
                                    $array10 as xs:anyAtomicType*,
 
705
                                    $array11 as xs:anyAtomicType*,
 
706
                                    $array12 as xs:anyAtomicType*,
 
707
                                    $array13 as xs:anyAtomicType*,
 
708
                                    $array14 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
709
 {
 
710
    if( fn:empty($array1) or 
 
711
        fn:empty($array2) or
 
712
        fn:empty($array3) or
 
713
        fn:empty($array4) or
 
714
        fn:empty($array5) or
 
715
        fn:empty($array6) or
 
716
        fn:empty($array7) or
 
717
        fn:empty($array8) or
 
718
        fn:empty($array9) or
 
719
        fn:empty($array10) or
 
720
        fn:empty($array11) or
 
721
        fn:empty($array12) or
 
722
        fn:empty($array13) or
 
723
        fn:empty($array14)) 
 
724
        then
 
725
      0
 
726
    else
 
727
        excel-math:cast-as-numeric($array1[1]) * 
 
728
        excel-math:cast-as-numeric($array2[1]) * 
 
729
        excel-math:cast-as-numeric($array3[1]) * 
 
730
        excel-math:cast-as-numeric($array4[1]) * 
 
731
        excel-math:cast-as-numeric($array5[1]) * 
 
732
        excel-math:cast-as-numeric($array6[1]) * 
 
733
        excel-math:cast-as-numeric($array7[1]) * 
 
734
        excel-math:cast-as-numeric($array8[1]) * 
 
735
        excel-math:cast-as-numeric($array9[1]) * 
 
736
        excel-math:cast-as-numeric($array10[1]) * 
 
737
        excel-math:cast-as-numeric($array11[1]) * 
 
738
        excel-math:cast-as-numeric($array12[1]) * 
 
739
        excel-math:cast-as-numeric($array13[1]) * 
 
740
        excel-math:cast-as-numeric($array14[1]) +
 
741
                    excel:sumproduct(  fn:subsequence($array1,2),
 
742
                                             fn:subsequence($array2,2),
 
743
                                             fn:subsequence($array3,2),
 
744
                                             fn:subsequence($array4,2),
 
745
                                             fn:subsequence($array5,2),
 
746
                                             fn:subsequence($array6,2),
 
747
                                             fn:subsequence($array7,2),
 
748
                                             fn:subsequence($array8,2),
 
749
                                             fn:subsequence($array9,2),
 
750
                                             fn:subsequence($array10,2),
 
751
                                             fn:subsequence($array11,2),
 
752
                                             fn:subsequence($array12,2),
 
753
                                             fn:subsequence($array13,2),
 
754
                                             fn:subsequence($array14,2))
 
755
 };
 
756
 
 
757
 (:~
 
758
  : Multiplies the elements on the same position in each sequence
 
759
  : and sums up the results.
 
760
  : 
 
761
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
762
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
763
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
764
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
765
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
766
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
767
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
768
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
769
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
770
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
771
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
772
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
773
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
774
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
775
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
776
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
777
  : @return the sum of products
 
778
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
779
:)
 
780
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
781
                                    $array2 as xs:anyAtomicType*,
 
782
                                    $array3 as xs:anyAtomicType*,
 
783
                                    $array4 as xs:anyAtomicType*,
 
784
                                    $array5 as xs:anyAtomicType*,
 
785
                                    $array6 as xs:anyAtomicType*,
 
786
                                    $array7 as xs:anyAtomicType*,
 
787
                                    $array8 as xs:anyAtomicType*,
 
788
                                    $array9 as xs:anyAtomicType*,
 
789
                                    $array10 as xs:anyAtomicType*,
 
790
                                    $array11 as xs:anyAtomicType*,
 
791
                                    $array12 as xs:anyAtomicType*,
 
792
                                    $array13 as xs:anyAtomicType*,
 
793
                                    $array14 as xs:anyAtomicType*,
 
794
                                    $array15 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
795
 {
 
796
    if( fn:empty($array1) or 
 
797
        fn:empty($array2) or
 
798
        fn:empty($array3) or
 
799
        fn:empty($array4) or
 
800
        fn:empty($array5) or
 
801
        fn:empty($array6) or
 
802
        fn:empty($array7) or
 
803
        fn:empty($array8) or
 
804
        fn:empty($array9) or
 
805
        fn:empty($array10) or
 
806
        fn:empty($array11) or
 
807
        fn:empty($array12) or
 
808
        fn:empty($array13) or
 
809
        fn:empty($array14) or
 
810
        fn:empty($array15)) 
 
811
        then
 
812
      0
 
813
    else
 
814
        excel-math:cast-as-numeric($array1[1]) * 
 
815
        excel-math:cast-as-numeric($array2[1]) * 
 
816
        excel-math:cast-as-numeric($array3[1]) * 
 
817
        excel-math:cast-as-numeric($array4[1]) * 
 
818
        excel-math:cast-as-numeric($array5[1]) * 
 
819
        excel-math:cast-as-numeric($array6[1]) * 
 
820
        excel-math:cast-as-numeric($array7[1]) * 
 
821
        excel-math:cast-as-numeric($array8[1]) * 
 
822
        excel-math:cast-as-numeric($array9[1]) * 
 
823
        excel-math:cast-as-numeric($array10[1]) * 
 
824
        excel-math:cast-as-numeric($array11[1]) * 
 
825
        excel-math:cast-as-numeric($array12[1]) * 
 
826
        excel-math:cast-as-numeric($array13[1]) * 
 
827
        excel-math:cast-as-numeric($array14[1]) * 
 
828
        excel-math:cast-as-numeric($array15[1]) +
 
829
                    excel:sumproduct(  fn:subsequence($array1,2),
 
830
                                             fn:subsequence($array2,2),
 
831
                                             fn:subsequence($array3,2),
 
832
                                             fn:subsequence($array4,2),
 
833
                                             fn:subsequence($array5,2),
 
834
                                             fn:subsequence($array6,2),
 
835
                                             fn:subsequence($array7,2),
 
836
                                             fn:subsequence($array8,2),
 
837
                                             fn:subsequence($array9,2),
 
838
                                             fn:subsequence($array10,2),
 
839
                                             fn:subsequence($array11,2),
 
840
                                             fn:subsequence($array12,2),
 
841
                                             fn:subsequence($array13,2),
 
842
                                             fn:subsequence($array14,2),
 
843
                                             fn:subsequence($array15,2))
 
844
 };
 
845
 
 
846
 (:~
 
847
  : Multiplies the elements on the same position in each sequence
 
848
  : and sums up the results.
 
849
  : 
 
850
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
851
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
852
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
853
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
854
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
855
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
856
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
857
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
858
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
859
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
860
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
861
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
862
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
863
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
864
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
865
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
866
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
867
  : @return the sum of products
 
868
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
869
:)
 
870
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
871
                                    $array2 as xs:anyAtomicType*,
 
872
                                    $array3 as xs:anyAtomicType*,
 
873
                                    $array4 as xs:anyAtomicType*,
 
874
                                    $array5 as xs:anyAtomicType*,
 
875
                                    $array6 as xs:anyAtomicType*,
 
876
                                    $array7 as xs:anyAtomicType*,
 
877
                                    $array8 as xs:anyAtomicType*,
 
878
                                    $array9 as xs:anyAtomicType*,
 
879
                                    $array10 as xs:anyAtomicType*,
 
880
                                    $array11 as xs:anyAtomicType*,
 
881
                                    $array12 as xs:anyAtomicType*,
 
882
                                    $array13 as xs:anyAtomicType*,
 
883
                                    $array14 as xs:anyAtomicType*,
 
884
                                    $array15 as xs:anyAtomicType*,
 
885
                                    $array16 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
886
 {
 
887
    if( fn:empty($array1) or 
 
888
        fn:empty($array2) or
 
889
        fn:empty($array3) or
 
890
        fn:empty($array4) or
 
891
        fn:empty($array5) or
 
892
        fn:empty($array6) or
 
893
        fn:empty($array7) or
 
894
        fn:empty($array8) or
 
895
        fn:empty($array9) or
 
896
        fn:empty($array10) or
 
897
        fn:empty($array11) or
 
898
        fn:empty($array12) or
 
899
        fn:empty($array13) or
 
900
        fn:empty($array14) or
 
901
        fn:empty($array15) or
 
902
        fn:empty($array16)) 
 
903
        then
 
904
      0
 
905
    else
 
906
        excel-math:cast-as-numeric($array1[1]) * 
 
907
        excel-math:cast-as-numeric($array2[1]) * 
 
908
        excel-math:cast-as-numeric($array3[1]) * 
 
909
        excel-math:cast-as-numeric($array4[1]) * 
 
910
        excel-math:cast-as-numeric($array5[1]) * 
 
911
        excel-math:cast-as-numeric($array6[1]) * 
 
912
        excel-math:cast-as-numeric($array7[1]) * 
 
913
        excel-math:cast-as-numeric($array8[1]) * 
 
914
        excel-math:cast-as-numeric($array9[1]) * 
 
915
        excel-math:cast-as-numeric($array10[1]) * 
 
916
        excel-math:cast-as-numeric($array11[1]) * 
 
917
        excel-math:cast-as-numeric($array12[1]) * 
 
918
        excel-math:cast-as-numeric($array13[1]) * 
 
919
        excel-math:cast-as-numeric($array14[1]) * 
 
920
        excel-math:cast-as-numeric($array15[1]) * 
 
921
        excel-math:cast-as-numeric($array16[1]) +
 
922
                    excel:sumproduct(  fn:subsequence($array1,2),
 
923
                                             fn:subsequence($array2,2),
 
924
                                             fn:subsequence($array3,2),
 
925
                                             fn:subsequence($array4,2),
 
926
                                             fn:subsequence($array5,2),
 
927
                                             fn:subsequence($array6,2),
 
928
                                             fn:subsequence($array7,2),
 
929
                                             fn:subsequence($array8,2),
 
930
                                             fn:subsequence($array9,2),
 
931
                                             fn:subsequence($array10,2),
 
932
                                             fn:subsequence($array11,2),
 
933
                                             fn:subsequence($array12,2),
 
934
                                             fn:subsequence($array13,2),
 
935
                                             fn:subsequence($array14,2),
 
936
                                             fn:subsequence($array15,2),
 
937
                                             fn:subsequence($array16,2))
 
938
 };
 
939
 
 
940
 (:~
 
941
  : Multiplies the elements on the same position in each sequence
 
942
  : and sums up the results.
 
943
  : 
 
944
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
945
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
946
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
947
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
948
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
949
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
950
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
951
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
952
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
953
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
954
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
955
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
956
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
957
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
958
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
959
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
960
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
961
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
962
  : @return the sum of products
 
963
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
964
:)
 
965
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
966
                                    $array2 as xs:anyAtomicType*,
 
967
                                    $array3 as xs:anyAtomicType*,
 
968
                                    $array4 as xs:anyAtomicType*,
 
969
                                    $array5 as xs:anyAtomicType*,
 
970
                                    $array6 as xs:anyAtomicType*,
 
971
                                    $array7 as xs:anyAtomicType*,
 
972
                                    $array8 as xs:anyAtomicType*,
 
973
                                    $array9 as xs:anyAtomicType*,
 
974
                                    $array10 as xs:anyAtomicType*,
 
975
                                    $array11 as xs:anyAtomicType*,
 
976
                                    $array12 as xs:anyAtomicType*,
 
977
                                    $array13 as xs:anyAtomicType*,
 
978
                                    $array14 as xs:anyAtomicType*,
 
979
                                    $array15 as xs:anyAtomicType*,
 
980
                                    $array16 as xs:anyAtomicType*,
 
981
                                    $array17 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
982
 {
 
983
    if( fn:empty($array1) or 
 
984
        fn:empty($array2) or
 
985
        fn:empty($array3) or
 
986
        fn:empty($array4) or
 
987
        fn:empty($array5) or
 
988
        fn:empty($array6) or
 
989
        fn:empty($array7) or
 
990
        fn:empty($array8) or
 
991
        fn:empty($array9) or
 
992
        fn:empty($array10) or
 
993
        fn:empty($array11) or
 
994
        fn:empty($array12) or
 
995
        fn:empty($array13) or
 
996
        fn:empty($array14) or
 
997
        fn:empty($array15) or
 
998
        fn:empty($array16) or
 
999
        fn:empty($array17)) 
 
1000
        then
 
1001
      0
 
1002
    else
 
1003
        excel-math:cast-as-numeric($array1[1]) * 
 
1004
        excel-math:cast-as-numeric($array2[1]) * 
 
1005
        excel-math:cast-as-numeric($array3[1]) * 
 
1006
        excel-math:cast-as-numeric($array4[1]) * 
 
1007
        excel-math:cast-as-numeric($array5[1]) * 
 
1008
        excel-math:cast-as-numeric($array6[1]) * 
 
1009
        excel-math:cast-as-numeric($array7[1]) * 
 
1010
        excel-math:cast-as-numeric($array8[1]) * 
 
1011
        excel-math:cast-as-numeric($array9[1]) * 
 
1012
        excel-math:cast-as-numeric($array10[1]) * 
 
1013
        excel-math:cast-as-numeric($array11[1]) * 
 
1014
        excel-math:cast-as-numeric($array12[1]) * 
 
1015
        excel-math:cast-as-numeric($array13[1]) * 
 
1016
        excel-math:cast-as-numeric($array14[1]) * 
 
1017
        excel-math:cast-as-numeric($array15[1]) * 
 
1018
        excel-math:cast-as-numeric($array16[1]) * 
 
1019
        excel-math:cast-as-numeric($array17[1]) +
 
1020
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1021
                                             fn:subsequence($array2,2),
 
1022
                                             fn:subsequence($array3,2),
 
1023
                                             fn:subsequence($array4,2),
 
1024
                                             fn:subsequence($array5,2),
 
1025
                                             fn:subsequence($array6,2),
 
1026
                                             fn:subsequence($array7,2),
 
1027
                                             fn:subsequence($array8,2),
 
1028
                                             fn:subsequence($array9,2),
 
1029
                                             fn:subsequence($array10,2),
 
1030
                                             fn:subsequence($array11,2),
 
1031
                                             fn:subsequence($array12,2),
 
1032
                                             fn:subsequence($array13,2),
 
1033
                                             fn:subsequence($array14,2),
 
1034
                                             fn:subsequence($array15,2),
 
1035
                                             fn:subsequence($array16,2),
 
1036
                                             fn:subsequence($array17,2))
 
1037
 };
 
1038
 
 
1039
 (:~
 
1040
  : Multiplies the elements on the same position in each sequence
 
1041
  : and sums up the results.
 
1042
  : 
 
1043
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1044
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1045
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1046
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1047
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1048
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1049
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1050
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1051
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1052
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1053
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1054
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1055
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1056
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1057
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1058
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1059
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1060
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1061
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1062
  : @return the sum of products
 
1063
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1064
:)
 
1065
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1066
                                    $array2 as xs:anyAtomicType*,
 
1067
                                    $array3 as xs:anyAtomicType*,
 
1068
                                    $array4 as xs:anyAtomicType*,
 
1069
                                    $array5 as xs:anyAtomicType*,
 
1070
                                    $array6 as xs:anyAtomicType*,
 
1071
                                    $array7 as xs:anyAtomicType*,
 
1072
                                    $array8 as xs:anyAtomicType*,
 
1073
                                    $array9 as xs:anyAtomicType*,
 
1074
                                    $array10 as xs:anyAtomicType*,
 
1075
                                    $array11 as xs:anyAtomicType*,
 
1076
                                    $array12 as xs:anyAtomicType*,
 
1077
                                    $array13 as xs:anyAtomicType*,
 
1078
                                    $array14 as xs:anyAtomicType*,
 
1079
                                    $array15 as xs:anyAtomicType*,
 
1080
                                    $array16 as xs:anyAtomicType*,
 
1081
                                    $array17 as xs:anyAtomicType*,
 
1082
                                    $array18 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1083
 {
 
1084
    if( fn:empty($array1) or 
 
1085
        fn:empty($array2) or
 
1086
        fn:empty($array3) or
 
1087
        fn:empty($array4) or
 
1088
        fn:empty($array5) or
 
1089
        fn:empty($array6) or
 
1090
        fn:empty($array7) or
 
1091
        fn:empty($array8) or
 
1092
        fn:empty($array9) or
 
1093
        fn:empty($array10) or
 
1094
        fn:empty($array11) or
 
1095
        fn:empty($array12) or
 
1096
        fn:empty($array13) or
 
1097
        fn:empty($array14) or
 
1098
        fn:empty($array15) or
 
1099
        fn:empty($array16) or
 
1100
        fn:empty($array17) or
 
1101
        fn:empty($array18)) 
 
1102
        then
 
1103
      0
 
1104
    else
 
1105
        excel-math:cast-as-numeric($array1[1]) * 
 
1106
        excel-math:cast-as-numeric($array2[1]) * 
 
1107
        excel-math:cast-as-numeric($array3[1]) * 
 
1108
        excel-math:cast-as-numeric($array4[1]) * 
 
1109
        excel-math:cast-as-numeric($array5[1]) * 
 
1110
        excel-math:cast-as-numeric($array6[1]) * 
 
1111
        excel-math:cast-as-numeric($array7[1]) * 
 
1112
        excel-math:cast-as-numeric($array8[1]) * 
 
1113
        excel-math:cast-as-numeric($array9[1]) * 
 
1114
        excel-math:cast-as-numeric($array10[1]) * 
 
1115
        excel-math:cast-as-numeric($array11[1]) * 
 
1116
        excel-math:cast-as-numeric($array12[1]) * 
 
1117
        excel-math:cast-as-numeric($array13[1]) * 
 
1118
        excel-math:cast-as-numeric($array14[1]) * 
 
1119
        excel-math:cast-as-numeric($array15[1]) * 
 
1120
        excel-math:cast-as-numeric($array16[1]) * 
 
1121
        excel-math:cast-as-numeric($array17[1]) * 
 
1122
        excel-math:cast-as-numeric($array18[1]) +
 
1123
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1124
                                             fn:subsequence($array2,2),
 
1125
                                             fn:subsequence($array3,2),
 
1126
                                             fn:subsequence($array4,2),
 
1127
                                             fn:subsequence($array5,2),
 
1128
                                             fn:subsequence($array6,2),
 
1129
                                             fn:subsequence($array7,2),
 
1130
                                             fn:subsequence($array8,2),
 
1131
                                             fn:subsequence($array9,2),
 
1132
                                             fn:subsequence($array10,2),
 
1133
                                             fn:subsequence($array11,2),
 
1134
                                             fn:subsequence($array12,2),
 
1135
                                             fn:subsequence($array13,2),
 
1136
                                             fn:subsequence($array14,2),
 
1137
                                             fn:subsequence($array15,2),
 
1138
                                             fn:subsequence($array16,2),
 
1139
                                             fn:subsequence($array17,2),
 
1140
                                             fn:subsequence($array18,2))
 
1141
 };
 
1142
 
 
1143
 (:~
 
1144
  : Multiplies the elements on the same position in each sequence
 
1145
  : and sums up the results.
 
1146
  : 
 
1147
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1148
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1149
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1150
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1151
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1152
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1153
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1154
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1155
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1156
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1157
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1158
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1159
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1160
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1161
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1162
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1163
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1164
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1165
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1166
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1167
  : @return the sum of products
 
1168
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1169
:)
 
1170
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1171
                                    $array2 as xs:anyAtomicType*,
 
1172
                                    $array3 as xs:anyAtomicType*,
 
1173
                                    $array4 as xs:anyAtomicType*,
 
1174
                                    $array5 as xs:anyAtomicType*,
 
1175
                                    $array6 as xs:anyAtomicType*,
 
1176
                                    $array7 as xs:anyAtomicType*,
 
1177
                                    $array8 as xs:anyAtomicType*,
 
1178
                                    $array9 as xs:anyAtomicType*,
 
1179
                                    $array10 as xs:anyAtomicType*,
 
1180
                                    $array11 as xs:anyAtomicType*,
 
1181
                                    $array12 as xs:anyAtomicType*,
 
1182
                                    $array13 as xs:anyAtomicType*,
 
1183
                                    $array14 as xs:anyAtomicType*,
 
1184
                                    $array15 as xs:anyAtomicType*,
 
1185
                                    $array16 as xs:anyAtomicType*,
 
1186
                                    $array17 as xs:anyAtomicType*,
 
1187
                                    $array18 as xs:anyAtomicType*,
 
1188
                                    $array19 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1189
 {
 
1190
    if( fn:empty($array1) or 
 
1191
        fn:empty($array2) or
 
1192
        fn:empty($array3) or
 
1193
        fn:empty($array4) or
 
1194
        fn:empty($array5) or
 
1195
        fn:empty($array6) or
 
1196
        fn:empty($array7) or
 
1197
        fn:empty($array8) or
 
1198
        fn:empty($array9) or
 
1199
        fn:empty($array10) or
 
1200
        fn:empty($array11) or
 
1201
        fn:empty($array12) or
 
1202
        fn:empty($array13) or
 
1203
        fn:empty($array14) or
 
1204
        fn:empty($array15) or
 
1205
        fn:empty($array16) or
 
1206
        fn:empty($array17) or
 
1207
        fn:empty($array18) or
 
1208
        fn:empty($array19)) 
 
1209
        then
 
1210
      0
 
1211
    else
 
1212
        excel-math:cast-as-numeric($array1[1]) * 
 
1213
        excel-math:cast-as-numeric($array2[1]) * 
 
1214
        excel-math:cast-as-numeric($array3[1]) * 
 
1215
        excel-math:cast-as-numeric($array4[1]) * 
 
1216
        excel-math:cast-as-numeric($array5[1]) * 
 
1217
        excel-math:cast-as-numeric($array6[1]) * 
 
1218
        excel-math:cast-as-numeric($array7[1]) * 
 
1219
        excel-math:cast-as-numeric($array8[1]) * 
 
1220
        excel-math:cast-as-numeric($array9[1]) * 
 
1221
        excel-math:cast-as-numeric($array10[1]) * 
 
1222
        excel-math:cast-as-numeric($array11[1]) * 
 
1223
        excel-math:cast-as-numeric($array12[1]) * 
 
1224
        excel-math:cast-as-numeric($array13[1]) * 
 
1225
        excel-math:cast-as-numeric($array14[1]) * 
 
1226
        excel-math:cast-as-numeric($array15[1]) * 
 
1227
        excel-math:cast-as-numeric($array16[1]) * 
 
1228
        excel-math:cast-as-numeric($array17[1]) * 
 
1229
        excel-math:cast-as-numeric($array18[1]) *
 
1230
        excel-math:cast-as-numeric($array19[1]) +
 
1231
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1232
                                             fn:subsequence($array2,2),
 
1233
                                             fn:subsequence($array3,2),
 
1234
                                             fn:subsequence($array4,2),
 
1235
                                             fn:subsequence($array5,2),
 
1236
                                             fn:subsequence($array6,2),
 
1237
                                             fn:subsequence($array7,2),
 
1238
                                             fn:subsequence($array8,2),
 
1239
                                             fn:subsequence($array9,2),
 
1240
                                             fn:subsequence($array10,2),
 
1241
                                             fn:subsequence($array11,2),
 
1242
                                             fn:subsequence($array12,2),
 
1243
                                             fn:subsequence($array13,2),
 
1244
                                             fn:subsequence($array14,2),
 
1245
                                             fn:subsequence($array15,2),
 
1246
                                             fn:subsequence($array16,2),
 
1247
                                             fn:subsequence($array17,2),
 
1248
                                             fn:subsequence($array18,2),
 
1249
                                             fn:subsequence($array19,2))
 
1250
 };
 
1251
  
 
1252
 (:~
 
1253
  : Multiplies the elements on the same position in each sequence
 
1254
  : and sums up the results.
 
1255
  : 
 
1256
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1257
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1258
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1259
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1260
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1261
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1262
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1263
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1264
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1265
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1266
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1267
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1268
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1269
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1270
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1271
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1272
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1273
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1274
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1275
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1276
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1277
  : @return the sum of products
 
1278
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1279
:)
 
1280
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1281
                                    $array2 as xs:anyAtomicType*,
 
1282
                                    $array3 as xs:anyAtomicType*,
 
1283
                                    $array4 as xs:anyAtomicType*,
 
1284
                                    $array5 as xs:anyAtomicType*,
 
1285
                                    $array6 as xs:anyAtomicType*,
 
1286
                                    $array7 as xs:anyAtomicType*,
 
1287
                                    $array8 as xs:anyAtomicType*,
 
1288
                                    $array9 as xs:anyAtomicType*,
 
1289
                                    $array10 as xs:anyAtomicType*,
 
1290
                                    $array11 as xs:anyAtomicType*,
 
1291
                                    $array12 as xs:anyAtomicType*,
 
1292
                                    $array13 as xs:anyAtomicType*,
 
1293
                                    $array14 as xs:anyAtomicType*,
 
1294
                                    $array15 as xs:anyAtomicType*,
 
1295
                                    $array16 as xs:anyAtomicType*,
 
1296
                                    $array17 as xs:anyAtomicType*,
 
1297
                                    $array18 as xs:anyAtomicType*,
 
1298
                                    $array19 as xs:anyAtomicType*,
 
1299
                                    $array20 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1300
 {
 
1301
    if( fn:empty($array1) or 
 
1302
        fn:empty($array2) or
 
1303
        fn:empty($array3) or
 
1304
        fn:empty($array4) or
 
1305
        fn:empty($array5) or
 
1306
        fn:empty($array6) or
 
1307
        fn:empty($array7) or
 
1308
        fn:empty($array8) or
 
1309
        fn:empty($array9) or
 
1310
        fn:empty($array10) or
 
1311
        fn:empty($array11) or
 
1312
        fn:empty($array12) or
 
1313
        fn:empty($array13) or
 
1314
        fn:empty($array14) or
 
1315
        fn:empty($array15) or
 
1316
        fn:empty($array16) or
 
1317
        fn:empty($array17) or
 
1318
        fn:empty($array18) or
 
1319
        fn:empty($array19) or
 
1320
        fn:empty($array20)) 
 
1321
        then
 
1322
      0
 
1323
    else
 
1324
        excel-math:cast-as-numeric($array1[1]) * 
 
1325
        excel-math:cast-as-numeric($array2[1]) * 
 
1326
        excel-math:cast-as-numeric($array3[1]) * 
 
1327
        excel-math:cast-as-numeric($array4[1]) * 
 
1328
        excel-math:cast-as-numeric($array5[1]) * 
 
1329
        excel-math:cast-as-numeric($array6[1]) * 
 
1330
        excel-math:cast-as-numeric($array7[1]) * 
 
1331
        excel-math:cast-as-numeric($array8[1]) * 
 
1332
        excel-math:cast-as-numeric($array9[1]) * 
 
1333
        excel-math:cast-as-numeric($array10[1]) * 
 
1334
        excel-math:cast-as-numeric($array11[1]) * 
 
1335
        excel-math:cast-as-numeric($array12[1]) * 
 
1336
        excel-math:cast-as-numeric($array13[1]) * 
 
1337
        excel-math:cast-as-numeric($array14[1]) * 
 
1338
        excel-math:cast-as-numeric($array15[1]) * 
 
1339
        excel-math:cast-as-numeric($array16[1]) * 
 
1340
        excel-math:cast-as-numeric($array17[1]) * 
 
1341
        excel-math:cast-as-numeric($array18[1]) *
 
1342
        excel-math:cast-as-numeric($array19[1]) *
 
1343
        excel-math:cast-as-numeric($array20[1]) +
 
1344
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1345
                                             fn:subsequence($array2,2),
 
1346
                                             fn:subsequence($array3,2),
 
1347
                                             fn:subsequence($array4,2),
 
1348
                                             fn:subsequence($array5,2),
 
1349
                                             fn:subsequence($array6,2),
 
1350
                                             fn:subsequence($array7,2),
 
1351
                                             fn:subsequence($array8,2),
 
1352
                                             fn:subsequence($array9,2),
 
1353
                                             fn:subsequence($array10,2),
 
1354
                                             fn:subsequence($array11,2),
 
1355
                                             fn:subsequence($array12,2),
 
1356
                                             fn:subsequence($array13,2),
 
1357
                                             fn:subsequence($array14,2),
 
1358
                                             fn:subsequence($array15,2),
 
1359
                                             fn:subsequence($array16,2),
 
1360
                                             fn:subsequence($array17,2),
 
1361
                                             fn:subsequence($array18,2),
 
1362
                                             fn:subsequence($array19,2),
 
1363
                                             fn:subsequence($array20,2))
 
1364
 };
 
1365
 
 
1366
 (:~
 
1367
  : Multiplies the elements on the same position in each sequence
 
1368
  : and sums up the results.
 
1369
  : 
 
1370
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1371
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1372
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1373
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1374
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1375
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1376
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1377
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1378
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1379
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1380
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1381
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1382
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1383
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1384
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1385
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1386
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1387
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1388
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1389
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1390
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1391
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
1392
  : @return the sum of products
 
1393
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1394
:)
 
1395
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1396
                                    $array2 as xs:anyAtomicType*,
 
1397
                                    $array3 as xs:anyAtomicType*,
 
1398
                                    $array4 as xs:anyAtomicType*,
 
1399
                                    $array5 as xs:anyAtomicType*,
 
1400
                                    $array6 as xs:anyAtomicType*,
 
1401
                                    $array7 as xs:anyAtomicType*,
 
1402
                                    $array8 as xs:anyAtomicType*,
 
1403
                                    $array9 as xs:anyAtomicType*,
 
1404
                                    $array10 as xs:anyAtomicType*,
 
1405
                                    $array11 as xs:anyAtomicType*,
 
1406
                                    $array12 as xs:anyAtomicType*,
 
1407
                                    $array13 as xs:anyAtomicType*,
 
1408
                                    $array14 as xs:anyAtomicType*,
 
1409
                                    $array15 as xs:anyAtomicType*,
 
1410
                                    $array16 as xs:anyAtomicType*,
 
1411
                                    $array17 as xs:anyAtomicType*,
 
1412
                                    $array18 as xs:anyAtomicType*,
 
1413
                                    $array19 as xs:anyAtomicType*,
 
1414
                                    $array20 as xs:anyAtomicType*,
 
1415
                                    $array21 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1416
 {
 
1417
    if( fn:empty($array1) or 
 
1418
        fn:empty($array2) or
 
1419
        fn:empty($array3) or
 
1420
        fn:empty($array4) or
 
1421
        fn:empty($array5) or
 
1422
        fn:empty($array6) or
 
1423
        fn:empty($array7) or
 
1424
        fn:empty($array8) or
 
1425
        fn:empty($array9) or
 
1426
        fn:empty($array10) or
 
1427
        fn:empty($array11) or
 
1428
        fn:empty($array12) or
 
1429
        fn:empty($array13) or
 
1430
        fn:empty($array14) or
 
1431
        fn:empty($array15) or
 
1432
        fn:empty($array16) or
 
1433
        fn:empty($array17) or
 
1434
        fn:empty($array18) or
 
1435
        fn:empty($array19) or
 
1436
        fn:empty($array20) or
 
1437
        fn:empty($array21)) 
 
1438
        then
 
1439
      0
 
1440
    else
 
1441
        excel-math:cast-as-numeric($array1[1]) * 
 
1442
        excel-math:cast-as-numeric($array2[1]) * 
 
1443
        excel-math:cast-as-numeric($array3[1]) * 
 
1444
        excel-math:cast-as-numeric($array4[1]) * 
 
1445
        excel-math:cast-as-numeric($array5[1]) * 
 
1446
        excel-math:cast-as-numeric($array6[1]) * 
 
1447
        excel-math:cast-as-numeric($array7[1]) * 
 
1448
        excel-math:cast-as-numeric($array8[1]) * 
 
1449
        excel-math:cast-as-numeric($array9[1]) * 
 
1450
        excel-math:cast-as-numeric($array10[1]) * 
 
1451
        excel-math:cast-as-numeric($array11[1]) * 
 
1452
        excel-math:cast-as-numeric($array12[1]) * 
 
1453
        excel-math:cast-as-numeric($array13[1]) * 
 
1454
        excel-math:cast-as-numeric($array14[1]) * 
 
1455
        excel-math:cast-as-numeric($array15[1]) * 
 
1456
        excel-math:cast-as-numeric($array16[1]) * 
 
1457
        excel-math:cast-as-numeric($array17[1]) * 
 
1458
        excel-math:cast-as-numeric($array18[1]) *
 
1459
        excel-math:cast-as-numeric($array19[1]) *
 
1460
        excel-math:cast-as-numeric($array20[1]) *
 
1461
        excel-math:cast-as-numeric($array21[1]) +
 
1462
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1463
                                             fn:subsequence($array2,2),
 
1464
                                             fn:subsequence($array3,2),
 
1465
                                             fn:subsequence($array4,2),
 
1466
                                             fn:subsequence($array5,2),
 
1467
                                             fn:subsequence($array6,2),
 
1468
                                             fn:subsequence($array7,2),
 
1469
                                             fn:subsequence($array8,2),
 
1470
                                             fn:subsequence($array9,2),
 
1471
                                             fn:subsequence($array10,2),
 
1472
                                             fn:subsequence($array11,2),
 
1473
                                             fn:subsequence($array12,2),
 
1474
                                             fn:subsequence($array13,2),
 
1475
                                             fn:subsequence($array14,2),
 
1476
                                             fn:subsequence($array15,2),
 
1477
                                             fn:subsequence($array16,2),
 
1478
                                             fn:subsequence($array17,2),
 
1479
                                             fn:subsequence($array18,2),
 
1480
                                             fn:subsequence($array19,2),
 
1481
                                             fn:subsequence($array20,2),
 
1482
                                             fn:subsequence($array21,2))
 
1483
 };
 
1484
 
 
1485
 (:~
 
1486
  : Multiplies the elements on the same position in each sequence
 
1487
  : and sums up the results.
 
1488
  : 
 
1489
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1490
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1491
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1492
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1493
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1494
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1495
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1496
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1497
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1498
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1499
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1500
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1501
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1502
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1503
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1504
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1505
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1506
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1507
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1508
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1509
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1510
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
1511
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
1512
  : @return the sum of products
 
1513
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1514
:)
 
1515
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1516
                                    $array2 as xs:anyAtomicType*,
 
1517
                                    $array3 as xs:anyAtomicType*,
 
1518
                                    $array4 as xs:anyAtomicType*,
 
1519
                                    $array5 as xs:anyAtomicType*,
 
1520
                                    $array6 as xs:anyAtomicType*,
 
1521
                                    $array7 as xs:anyAtomicType*,
 
1522
                                    $array8 as xs:anyAtomicType*,
 
1523
                                    $array9 as xs:anyAtomicType*,
 
1524
                                    $array10 as xs:anyAtomicType*,
 
1525
                                    $array11 as xs:anyAtomicType*,
 
1526
                                    $array12 as xs:anyAtomicType*,
 
1527
                                    $array13 as xs:anyAtomicType*,
 
1528
                                    $array14 as xs:anyAtomicType*,
 
1529
                                    $array15 as xs:anyAtomicType*,
 
1530
                                    $array16 as xs:anyAtomicType*,
 
1531
                                    $array17 as xs:anyAtomicType*,
 
1532
                                    $array18 as xs:anyAtomicType*,
 
1533
                                    $array19 as xs:anyAtomicType*,
 
1534
                                    $array20 as xs:anyAtomicType*,
 
1535
                                    $array21 as xs:anyAtomicType*,
 
1536
                                    $array22 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1537
 {
 
1538
    if( fn:empty($array1) or 
 
1539
        fn:empty($array2) or
 
1540
        fn:empty($array3) or
 
1541
        fn:empty($array4) or
 
1542
        fn:empty($array5) or
 
1543
        fn:empty($array6) or
 
1544
        fn:empty($array7) or
 
1545
        fn:empty($array8) or
 
1546
        fn:empty($array9) or
 
1547
        fn:empty($array10) or
 
1548
        fn:empty($array11) or
 
1549
        fn:empty($array12) or
 
1550
        fn:empty($array13) or
 
1551
        fn:empty($array14) or
 
1552
        fn:empty($array15) or
 
1553
        fn:empty($array16) or
 
1554
        fn:empty($array17) or
 
1555
        fn:empty($array18) or
 
1556
        fn:empty($array19) or
 
1557
        fn:empty($array20) or
 
1558
        fn:empty($array21) or
 
1559
        fn:empty($array22)) 
 
1560
        then
 
1561
      0
 
1562
    else
 
1563
        excel-math:cast-as-numeric($array1[1]) * 
 
1564
        excel-math:cast-as-numeric($array2[1]) * 
 
1565
        excel-math:cast-as-numeric($array3[1]) * 
 
1566
        excel-math:cast-as-numeric($array4[1]) * 
 
1567
        excel-math:cast-as-numeric($array5[1]) * 
 
1568
        excel-math:cast-as-numeric($array6[1]) * 
 
1569
        excel-math:cast-as-numeric($array7[1]) * 
 
1570
        excel-math:cast-as-numeric($array8[1]) * 
 
1571
        excel-math:cast-as-numeric($array9[1]) * 
 
1572
        excel-math:cast-as-numeric($array10[1]) * 
 
1573
        excel-math:cast-as-numeric($array11[1]) * 
 
1574
        excel-math:cast-as-numeric($array12[1]) * 
 
1575
        excel-math:cast-as-numeric($array13[1]) * 
 
1576
        excel-math:cast-as-numeric($array14[1]) * 
 
1577
        excel-math:cast-as-numeric($array15[1]) * 
 
1578
        excel-math:cast-as-numeric($array16[1]) * 
 
1579
        excel-math:cast-as-numeric($array17[1]) * 
 
1580
        excel-math:cast-as-numeric($array18[1]) *
 
1581
        excel-math:cast-as-numeric($array19[1]) *
 
1582
        excel-math:cast-as-numeric($array20[1]) *
 
1583
        excel-math:cast-as-numeric($array21[1]) *
 
1584
        excel-math:cast-as-numeric($array22[1]) +
 
1585
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1586
                                             fn:subsequence($array2,2),
 
1587
                                             fn:subsequence($array3,2),
 
1588
                                             fn:subsequence($array4,2),
 
1589
                                             fn:subsequence($array5,2),
 
1590
                                             fn:subsequence($array6,2),
 
1591
                                             fn:subsequence($array7,2),
 
1592
                                             fn:subsequence($array8,2),
 
1593
                                             fn:subsequence($array9,2),
 
1594
                                             fn:subsequence($array10,2),
 
1595
                                             fn:subsequence($array11,2),
 
1596
                                             fn:subsequence($array12,2),
 
1597
                                             fn:subsequence($array13,2),
 
1598
                                             fn:subsequence($array14,2),
 
1599
                                             fn:subsequence($array15,2),
 
1600
                                             fn:subsequence($array16,2),
 
1601
                                             fn:subsequence($array17,2),
 
1602
                                             fn:subsequence($array18,2),
 
1603
                                             fn:subsequence($array19,2),
 
1604
                                             fn:subsequence($array20,2),
 
1605
                                             fn:subsequence($array21,2),
 
1606
                                             fn:subsequence($array22,2))
 
1607
 };
 
1608
 
 
1609
 (:~
 
1610
  : Multiplies the elements on the same position in each sequence
 
1611
  : and sums up the results.
 
1612
  : 
 
1613
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1614
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1615
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1616
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1617
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1618
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1619
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1620
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1621
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1622
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1623
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1624
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1625
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1626
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1627
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1628
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1629
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1630
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1631
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1632
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1633
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1634
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
1635
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
1636
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
1637
  : @return the sum of products
 
1638
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1639
:)
 
1640
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1641
                                    $array2 as xs:anyAtomicType*,
 
1642
                                    $array3 as xs:anyAtomicType*,
 
1643
                                    $array4 as xs:anyAtomicType*,
 
1644
                                    $array5 as xs:anyAtomicType*,
 
1645
                                    $array6 as xs:anyAtomicType*,
 
1646
                                    $array7 as xs:anyAtomicType*,
 
1647
                                    $array8 as xs:anyAtomicType*,
 
1648
                                    $array9 as xs:anyAtomicType*,
 
1649
                                    $array10 as xs:anyAtomicType*,
 
1650
                                    $array11 as xs:anyAtomicType*,
 
1651
                                    $array12 as xs:anyAtomicType*,
 
1652
                                    $array13 as xs:anyAtomicType*,
 
1653
                                    $array14 as xs:anyAtomicType*,
 
1654
                                    $array15 as xs:anyAtomicType*,
 
1655
                                    $array16 as xs:anyAtomicType*,
 
1656
                                    $array17 as xs:anyAtomicType*,
 
1657
                                    $array18 as xs:anyAtomicType*,
 
1658
                                    $array19 as xs:anyAtomicType*,
 
1659
                                    $array20 as xs:anyAtomicType*,
 
1660
                                    $array21 as xs:anyAtomicType*,
 
1661
                                    $array22 as xs:anyAtomicType*,
 
1662
                                    $array23 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1663
 {
 
1664
    if( fn:empty($array1) or 
 
1665
        fn:empty($array2) or
 
1666
        fn:empty($array3) or
 
1667
        fn:empty($array4) or
 
1668
        fn:empty($array5) or
 
1669
        fn:empty($array6) or
 
1670
        fn:empty($array7) or
 
1671
        fn:empty($array8) or
 
1672
        fn:empty($array9) or
 
1673
        fn:empty($array10) or
 
1674
        fn:empty($array11) or
 
1675
        fn:empty($array12) or
 
1676
        fn:empty($array13) or
 
1677
        fn:empty($array14) or
 
1678
        fn:empty($array15) or
 
1679
        fn:empty($array16) or
 
1680
        fn:empty($array17) or
 
1681
        fn:empty($array18) or
 
1682
        fn:empty($array19) or
 
1683
        fn:empty($array20) or
 
1684
        fn:empty($array21) or
 
1685
        fn:empty($array22) or
 
1686
        fn:empty($array23)) 
 
1687
        then
 
1688
      0
 
1689
    else
 
1690
        excel-math:cast-as-numeric($array1[1]) * 
 
1691
        excel-math:cast-as-numeric($array2[1]) * 
 
1692
        excel-math:cast-as-numeric($array3[1]) * 
 
1693
        excel-math:cast-as-numeric($array4[1]) * 
 
1694
        excel-math:cast-as-numeric($array5[1]) * 
 
1695
        excel-math:cast-as-numeric($array6[1]) * 
 
1696
        excel-math:cast-as-numeric($array7[1]) * 
 
1697
        excel-math:cast-as-numeric($array8[1]) * 
 
1698
        excel-math:cast-as-numeric($array9[1]) * 
 
1699
        excel-math:cast-as-numeric($array10[1]) * 
 
1700
        excel-math:cast-as-numeric($array11[1]) * 
 
1701
        excel-math:cast-as-numeric($array12[1]) * 
 
1702
        excel-math:cast-as-numeric($array13[1]) * 
 
1703
        excel-math:cast-as-numeric($array14[1]) * 
 
1704
        excel-math:cast-as-numeric($array15[1]) * 
 
1705
        excel-math:cast-as-numeric($array16[1]) * 
 
1706
        excel-math:cast-as-numeric($array17[1]) * 
 
1707
        excel-math:cast-as-numeric($array18[1]) *
 
1708
        excel-math:cast-as-numeric($array19[1]) *
 
1709
        excel-math:cast-as-numeric($array20[1]) *
 
1710
        excel-math:cast-as-numeric($array21[1]) *
 
1711
        excel-math:cast-as-numeric($array22[1]) *
 
1712
        excel-math:cast-as-numeric($array23[1]) +
 
1713
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1714
                                             fn:subsequence($array2,2),
 
1715
                                             fn:subsequence($array3,2),
 
1716
                                             fn:subsequence($array4,2),
 
1717
                                             fn:subsequence($array5,2),
 
1718
                                             fn:subsequence($array6,2),
 
1719
                                             fn:subsequence($array7,2),
 
1720
                                             fn:subsequence($array8,2),
 
1721
                                             fn:subsequence($array9,2),
 
1722
                                             fn:subsequence($array10,2),
 
1723
                                             fn:subsequence($array11,2),
 
1724
                                             fn:subsequence($array12,2),
 
1725
                                             fn:subsequence($array13,2),
 
1726
                                             fn:subsequence($array14,2),
 
1727
                                             fn:subsequence($array15,2),
 
1728
                                             fn:subsequence($array16,2),
 
1729
                                             fn:subsequence($array17,2),
 
1730
                                             fn:subsequence($array18,2),
 
1731
                                             fn:subsequence($array19,2),
 
1732
                                             fn:subsequence($array20,2),
 
1733
                                             fn:subsequence($array21,2),
 
1734
                                             fn:subsequence($array22,2),
 
1735
                                             fn:subsequence($array23,2))
 
1736
 };
 
1737
 
 
1738
 (:~
 
1739
  : Multiplies the elements on the same position in each sequence
 
1740
  : and sums up the results.
 
1741
  : 
 
1742
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1743
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1744
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1745
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1746
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1747
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1748
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1749
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1750
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1751
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1752
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1753
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1754
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1755
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1756
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1757
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1758
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1759
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1760
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1761
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1762
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1763
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
1764
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
1765
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
1766
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
1767
  : @return the sum of products
 
1768
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1769
:)
 
1770
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1771
                                    $array2 as xs:anyAtomicType*,
 
1772
                                    $array3 as xs:anyAtomicType*,
 
1773
                                    $array4 as xs:anyAtomicType*,
 
1774
                                    $array5 as xs:anyAtomicType*,
 
1775
                                    $array6 as xs:anyAtomicType*,
 
1776
                                    $array7 as xs:anyAtomicType*,
 
1777
                                    $array8 as xs:anyAtomicType*,
 
1778
                                    $array9 as xs:anyAtomicType*,
 
1779
                                    $array10 as xs:anyAtomicType*,
 
1780
                                    $array11 as xs:anyAtomicType*,
 
1781
                                    $array12 as xs:anyAtomicType*,
 
1782
                                    $array13 as xs:anyAtomicType*,
 
1783
                                    $array14 as xs:anyAtomicType*,
 
1784
                                    $array15 as xs:anyAtomicType*,
 
1785
                                    $array16 as xs:anyAtomicType*,
 
1786
                                    $array17 as xs:anyAtomicType*,
 
1787
                                    $array18 as xs:anyAtomicType*,
 
1788
                                    $array19 as xs:anyAtomicType*,
 
1789
                                    $array20 as xs:anyAtomicType*,
 
1790
                                    $array21 as xs:anyAtomicType*,
 
1791
                                    $array22 as xs:anyAtomicType*,
 
1792
                                    $array23 as xs:anyAtomicType*,
 
1793
                                    $array24 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1794
 {
 
1795
    if( fn:empty($array1) or 
 
1796
        fn:empty($array2) or
 
1797
        fn:empty($array3) or
 
1798
        fn:empty($array4) or
 
1799
        fn:empty($array5) or
 
1800
        fn:empty($array6) or
 
1801
        fn:empty($array7) or
 
1802
        fn:empty($array8) or
 
1803
        fn:empty($array9) or
 
1804
        fn:empty($array10) or
 
1805
        fn:empty($array11) or
 
1806
        fn:empty($array12) or
 
1807
        fn:empty($array13) or
 
1808
        fn:empty($array14) or
 
1809
        fn:empty($array15) or
 
1810
        fn:empty($array16) or
 
1811
        fn:empty($array17) or
 
1812
        fn:empty($array18) or
 
1813
        fn:empty($array19) or
 
1814
        fn:empty($array20) or
 
1815
        fn:empty($array21) or
 
1816
        fn:empty($array22) or
 
1817
        fn:empty($array23) or
 
1818
        fn:empty($array24)) 
 
1819
        then
 
1820
      0
 
1821
    else
 
1822
        excel-math:cast-as-numeric($array1[1]) * 
 
1823
        excel-math:cast-as-numeric($array2[1]) * 
 
1824
        excel-math:cast-as-numeric($array3[1]) * 
 
1825
        excel-math:cast-as-numeric($array4[1]) * 
 
1826
        excel-math:cast-as-numeric($array5[1]) * 
 
1827
        excel-math:cast-as-numeric($array6[1]) * 
 
1828
        excel-math:cast-as-numeric($array7[1]) * 
 
1829
        excel-math:cast-as-numeric($array8[1]) * 
 
1830
        excel-math:cast-as-numeric($array9[1]) * 
 
1831
        excel-math:cast-as-numeric($array10[1]) * 
 
1832
        excel-math:cast-as-numeric($array11[1]) * 
 
1833
        excel-math:cast-as-numeric($array12[1]) * 
 
1834
        excel-math:cast-as-numeric($array13[1]) * 
 
1835
        excel-math:cast-as-numeric($array14[1]) * 
 
1836
        excel-math:cast-as-numeric($array15[1]) * 
 
1837
        excel-math:cast-as-numeric($array16[1]) * 
 
1838
        excel-math:cast-as-numeric($array17[1]) * 
 
1839
        excel-math:cast-as-numeric($array18[1]) *
 
1840
        excel-math:cast-as-numeric($array19[1]) *
 
1841
        excel-math:cast-as-numeric($array20[1]) *
 
1842
        excel-math:cast-as-numeric($array21[1]) *
 
1843
        excel-math:cast-as-numeric($array22[1]) *
 
1844
        excel-math:cast-as-numeric($array23[1]) *
 
1845
        excel-math:cast-as-numeric($array24[1]) +
 
1846
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1847
                                             fn:subsequence($array2,2),
 
1848
                                             fn:subsequence($array3,2),
 
1849
                                             fn:subsequence($array4,2),
 
1850
                                             fn:subsequence($array5,2),
 
1851
                                             fn:subsequence($array6,2),
 
1852
                                             fn:subsequence($array7,2),
 
1853
                                             fn:subsequence($array8,2),
 
1854
                                             fn:subsequence($array9,2),
 
1855
                                             fn:subsequence($array10,2),
 
1856
                                             fn:subsequence($array11,2),
 
1857
                                             fn:subsequence($array12,2),
 
1858
                                             fn:subsequence($array13,2),
 
1859
                                             fn:subsequence($array14,2),
 
1860
                                             fn:subsequence($array15,2),
 
1861
                                             fn:subsequence($array16,2),
 
1862
                                             fn:subsequence($array17,2),
 
1863
                                             fn:subsequence($array18,2),
 
1864
                                             fn:subsequence($array19,2),
 
1865
                                             fn:subsequence($array20,2),
 
1866
                                             fn:subsequence($array21,2),
 
1867
                                             fn:subsequence($array22,2),
 
1868
                                             fn:subsequence($array23,2),
 
1869
                                             fn:subsequence($array24,2))
 
1870
 };
 
1871
 
 
1872
 (:~
 
1873
  : Multiplies the elements on the same position in each sequence
 
1874
  : and sums up the results.
 
1875
  : 
 
1876
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
1877
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
1878
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
1879
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
1880
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
1881
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
1882
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
1883
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
1884
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
1885
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
1886
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
1887
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
1888
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
1889
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
1890
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
1891
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
1892
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
1893
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
1894
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
1895
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
1896
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
1897
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
1898
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
1899
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
1900
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
1901
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
1902
  : @return the sum of products
 
1903
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
1904
:)
 
1905
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
1906
                                    $array2 as xs:anyAtomicType*,
 
1907
                                    $array3 as xs:anyAtomicType*,
 
1908
                                    $array4 as xs:anyAtomicType*,
 
1909
                                    $array5 as xs:anyAtomicType*,
 
1910
                                    $array6 as xs:anyAtomicType*,
 
1911
                                    $array7 as xs:anyAtomicType*,
 
1912
                                    $array8 as xs:anyAtomicType*,
 
1913
                                    $array9 as xs:anyAtomicType*,
 
1914
                                    $array10 as xs:anyAtomicType*,
 
1915
                                    $array11 as xs:anyAtomicType*,
 
1916
                                    $array12 as xs:anyAtomicType*,
 
1917
                                    $array13 as xs:anyAtomicType*,
 
1918
                                    $array14 as xs:anyAtomicType*,
 
1919
                                    $array15 as xs:anyAtomicType*,
 
1920
                                    $array16 as xs:anyAtomicType*,
 
1921
                                    $array17 as xs:anyAtomicType*,
 
1922
                                    $array18 as xs:anyAtomicType*,
 
1923
                                    $array19 as xs:anyAtomicType*,
 
1924
                                    $array20 as xs:anyAtomicType*,
 
1925
                                    $array21 as xs:anyAtomicType*,
 
1926
                                    $array22 as xs:anyAtomicType*,
 
1927
                                    $array23 as xs:anyAtomicType*,
 
1928
                                    $array24 as xs:anyAtomicType*,
 
1929
                                    $array25 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
1930
 {
 
1931
    if( fn:empty($array1) or 
 
1932
        fn:empty($array2) or
 
1933
        fn:empty($array3) or
 
1934
        fn:empty($array4) or
 
1935
        fn:empty($array5) or
 
1936
        fn:empty($array6) or
 
1937
        fn:empty($array7) or
 
1938
        fn:empty($array8) or
 
1939
        fn:empty($array9) or
 
1940
        fn:empty($array10) or
 
1941
        fn:empty($array11) or
 
1942
        fn:empty($array12) or
 
1943
        fn:empty($array13) or
 
1944
        fn:empty($array14) or
 
1945
        fn:empty($array15) or
 
1946
        fn:empty($array16) or
 
1947
        fn:empty($array17) or
 
1948
        fn:empty($array18) or
 
1949
        fn:empty($array19) or
 
1950
        fn:empty($array20) or
 
1951
        fn:empty($array21) or
 
1952
        fn:empty($array22) or
 
1953
        fn:empty($array23) or
 
1954
        fn:empty($array24) or
 
1955
        fn:empty($array25)) 
 
1956
        then
 
1957
      0
 
1958
    else
 
1959
        excel-math:cast-as-numeric($array1[1]) * 
 
1960
        excel-math:cast-as-numeric($array2[1]) * 
 
1961
        excel-math:cast-as-numeric($array3[1]) * 
 
1962
        excel-math:cast-as-numeric($array4[1]) * 
 
1963
        excel-math:cast-as-numeric($array5[1]) * 
 
1964
        excel-math:cast-as-numeric($array6[1]) * 
 
1965
        excel-math:cast-as-numeric($array7[1]) * 
 
1966
        excel-math:cast-as-numeric($array8[1]) * 
 
1967
        excel-math:cast-as-numeric($array9[1]) * 
 
1968
        excel-math:cast-as-numeric($array10[1]) * 
 
1969
        excel-math:cast-as-numeric($array11[1]) * 
 
1970
        excel-math:cast-as-numeric($array12[1]) * 
 
1971
        excel-math:cast-as-numeric($array13[1]) * 
 
1972
        excel-math:cast-as-numeric($array14[1]) * 
 
1973
        excel-math:cast-as-numeric($array15[1]) * 
 
1974
        excel-math:cast-as-numeric($array16[1]) * 
 
1975
        excel-math:cast-as-numeric($array17[1]) * 
 
1976
        excel-math:cast-as-numeric($array18[1]) *
 
1977
        excel-math:cast-as-numeric($array19[1]) *
 
1978
        excel-math:cast-as-numeric($array20[1]) *
 
1979
        excel-math:cast-as-numeric($array21[1]) *
 
1980
        excel-math:cast-as-numeric($array22[1]) *
 
1981
        excel-math:cast-as-numeric($array23[1]) *
 
1982
        excel-math:cast-as-numeric($array24[1]) *
 
1983
        excel-math:cast-as-numeric($array25[1]) +
 
1984
                    excel:sumproduct(  fn:subsequence($array1,2),
 
1985
                                             fn:subsequence($array2,2),
 
1986
                                             fn:subsequence($array3,2),
 
1987
                                             fn:subsequence($array4,2),
 
1988
                                             fn:subsequence($array5,2),
 
1989
                                             fn:subsequence($array6,2),
 
1990
                                             fn:subsequence($array7,2),
 
1991
                                             fn:subsequence($array8,2),
 
1992
                                             fn:subsequence($array9,2),
 
1993
                                             fn:subsequence($array10,2),
 
1994
                                             fn:subsequence($array11,2),
 
1995
                                             fn:subsequence($array12,2),
 
1996
                                             fn:subsequence($array13,2),
 
1997
                                             fn:subsequence($array14,2),
 
1998
                                             fn:subsequence($array15,2),
 
1999
                                             fn:subsequence($array16,2),
 
2000
                                             fn:subsequence($array17,2),
 
2001
                                             fn:subsequence($array18,2),
 
2002
                                             fn:subsequence($array19,2),
 
2003
                                             fn:subsequence($array20,2),
 
2004
                                             fn:subsequence($array21,2),
 
2005
                                             fn:subsequence($array22,2),
 
2006
                                             fn:subsequence($array23,2),
 
2007
                                             fn:subsequence($array24,2),
 
2008
                                             fn:subsequence($array25,2))
 
2009
 };
 
2010
 
 
2011
 (:~
 
2012
  : Multiplies the elements on the same position in each sequence
 
2013
  : and sums up the results.
 
2014
  : 
 
2015
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
2016
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
2017
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
2018
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
2019
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
2020
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
2021
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
2022
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
2023
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
2024
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
2025
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
2026
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
2027
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
2028
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
2029
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
2030
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
2031
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
2032
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
2033
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
2034
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
2035
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
2036
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
2037
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
2038
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
2039
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
2040
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
2041
  : @param $array26 the sequences of numbers or arguments castable to numeric
 
2042
  : @return the sum of products
 
2043
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2044
:)
 
2045
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
2046
                                    $array2 as xs:anyAtomicType*,
 
2047
                                    $array3 as xs:anyAtomicType*,
 
2048
                                    $array4 as xs:anyAtomicType*,
 
2049
                                    $array5 as xs:anyAtomicType*,
 
2050
                                    $array6 as xs:anyAtomicType*,
 
2051
                                    $array7 as xs:anyAtomicType*,
 
2052
                                    $array8 as xs:anyAtomicType*,
 
2053
                                    $array9 as xs:anyAtomicType*,
 
2054
                                    $array10 as xs:anyAtomicType*,
 
2055
                                    $array11 as xs:anyAtomicType*,
 
2056
                                    $array12 as xs:anyAtomicType*,
 
2057
                                    $array13 as xs:anyAtomicType*,
 
2058
                                    $array14 as xs:anyAtomicType*,
 
2059
                                    $array15 as xs:anyAtomicType*,
 
2060
                                    $array16 as xs:anyAtomicType*,
 
2061
                                    $array17 as xs:anyAtomicType*,
 
2062
                                    $array18 as xs:anyAtomicType*,
 
2063
                                    $array19 as xs:anyAtomicType*,
 
2064
                                    $array20 as xs:anyAtomicType*,
 
2065
                                    $array21 as xs:anyAtomicType*,
 
2066
                                    $array22 as xs:anyAtomicType*,
 
2067
                                    $array23 as xs:anyAtomicType*,
 
2068
                                    $array24 as xs:anyAtomicType*,
 
2069
                                    $array25 as xs:anyAtomicType*,
 
2070
                                    $array26 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
2071
 {
 
2072
    if( fn:empty($array1) or 
 
2073
        fn:empty($array2) or
 
2074
        fn:empty($array3) or
 
2075
        fn:empty($array4) or
 
2076
        fn:empty($array5) or
 
2077
        fn:empty($array6) or
 
2078
        fn:empty($array7) or
 
2079
        fn:empty($array8) or
 
2080
        fn:empty($array9) or
 
2081
        fn:empty($array10) or
 
2082
        fn:empty($array11) or
 
2083
        fn:empty($array12) or
 
2084
        fn:empty($array13) or
 
2085
        fn:empty($array14) or
 
2086
        fn:empty($array15) or
 
2087
        fn:empty($array16) or
 
2088
        fn:empty($array17) or
 
2089
        fn:empty($array18) or
 
2090
        fn:empty($array19) or
 
2091
        fn:empty($array20) or
 
2092
        fn:empty($array21) or
 
2093
        fn:empty($array22) or
 
2094
        fn:empty($array23) or
 
2095
        fn:empty($array24) or
 
2096
        fn:empty($array25) or
 
2097
        fn:empty($array26)) 
 
2098
        then
 
2099
      0
 
2100
    else
 
2101
        excel-math:cast-as-numeric($array1[1]) * 
 
2102
        excel-math:cast-as-numeric($array2[1]) * 
 
2103
        excel-math:cast-as-numeric($array3[1]) * 
 
2104
        excel-math:cast-as-numeric($array4[1]) * 
 
2105
        excel-math:cast-as-numeric($array5[1]) * 
 
2106
        excel-math:cast-as-numeric($array6[1]) * 
 
2107
        excel-math:cast-as-numeric($array7[1]) * 
 
2108
        excel-math:cast-as-numeric($array8[1]) * 
 
2109
        excel-math:cast-as-numeric($array9[1]) * 
 
2110
        excel-math:cast-as-numeric($array10[1]) * 
 
2111
        excel-math:cast-as-numeric($array11[1]) * 
 
2112
        excel-math:cast-as-numeric($array12[1]) * 
 
2113
        excel-math:cast-as-numeric($array13[1]) * 
 
2114
        excel-math:cast-as-numeric($array14[1]) * 
 
2115
        excel-math:cast-as-numeric($array15[1]) * 
 
2116
        excel-math:cast-as-numeric($array16[1]) * 
 
2117
        excel-math:cast-as-numeric($array17[1]) * 
 
2118
        excel-math:cast-as-numeric($array18[1]) *
 
2119
        excel-math:cast-as-numeric($array19[1]) *
 
2120
        excel-math:cast-as-numeric($array20[1]) *
 
2121
        excel-math:cast-as-numeric($array21[1]) *
 
2122
        excel-math:cast-as-numeric($array22[1]) *
 
2123
        excel-math:cast-as-numeric($array23[1]) *
 
2124
        excel-math:cast-as-numeric($array24[1]) *
 
2125
        excel-math:cast-as-numeric($array25[1]) *
 
2126
        excel-math:cast-as-numeric($array26[1]) +
 
2127
                    excel:sumproduct(  fn:subsequence($array1,2),
 
2128
                                             fn:subsequence($array2,2),
 
2129
                                             fn:subsequence($array3,2),
 
2130
                                             fn:subsequence($array4,2),
 
2131
                                             fn:subsequence($array5,2),
 
2132
                                             fn:subsequence($array6,2),
 
2133
                                             fn:subsequence($array7,2),
 
2134
                                             fn:subsequence($array8,2),
 
2135
                                             fn:subsequence($array9,2),
 
2136
                                             fn:subsequence($array10,2),
 
2137
                                             fn:subsequence($array11,2),
 
2138
                                             fn:subsequence($array12,2),
 
2139
                                             fn:subsequence($array13,2),
 
2140
                                             fn:subsequence($array14,2),
 
2141
                                             fn:subsequence($array15,2),
 
2142
                                             fn:subsequence($array16,2),
 
2143
                                             fn:subsequence($array17,2),
 
2144
                                             fn:subsequence($array18,2),
 
2145
                                             fn:subsequence($array19,2),
 
2146
                                             fn:subsequence($array20,2),
 
2147
                                             fn:subsequence($array21,2),
 
2148
                                             fn:subsequence($array22,2),
 
2149
                                             fn:subsequence($array23,2),
 
2150
                                             fn:subsequence($array24,2),
 
2151
                                             fn:subsequence($array25,2),
 
2152
                                             fn:subsequence($array26,2))
 
2153
 };
 
2154
 
 
2155
 (:~
 
2156
  : Multiplies the elements on the same position in each sequence
 
2157
  : and sums up the results.
 
2158
  : 
 
2159
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
2160
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
2161
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
2162
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
2163
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
2164
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
2165
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
2166
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
2167
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
2168
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
2169
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
2170
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
2171
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
2172
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
2173
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
2174
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
2175
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
2176
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
2177
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
2178
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
2179
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
2180
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
2181
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
2182
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
2183
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
2184
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
2185
  : @param $array26 the sequences of numbers or arguments castable to numeric
 
2186
  : @param $array27 the sequences of numbers or arguments castable to numeric
 
2187
  : @return the sum of products
 
2188
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2189
:)
 
2190
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
2191
                                    $array2 as xs:anyAtomicType*,
 
2192
                                    $array3 as xs:anyAtomicType*,
 
2193
                                    $array4 as xs:anyAtomicType*,
 
2194
                                    $array5 as xs:anyAtomicType*,
 
2195
                                    $array6 as xs:anyAtomicType*,
 
2196
                                    $array7 as xs:anyAtomicType*,
 
2197
                                    $array8 as xs:anyAtomicType*,
 
2198
                                    $array9 as xs:anyAtomicType*,
 
2199
                                    $array10 as xs:anyAtomicType*,
 
2200
                                    $array11 as xs:anyAtomicType*,
 
2201
                                    $array12 as xs:anyAtomicType*,
 
2202
                                    $array13 as xs:anyAtomicType*,
 
2203
                                    $array14 as xs:anyAtomicType*,
 
2204
                                    $array15 as xs:anyAtomicType*,
 
2205
                                    $array16 as xs:anyAtomicType*,
 
2206
                                    $array17 as xs:anyAtomicType*,
 
2207
                                    $array18 as xs:anyAtomicType*,
 
2208
                                    $array19 as xs:anyAtomicType*,
 
2209
                                    $array20 as xs:anyAtomicType*,
 
2210
                                    $array21 as xs:anyAtomicType*,
 
2211
                                    $array22 as xs:anyAtomicType*,
 
2212
                                    $array23 as xs:anyAtomicType*,
 
2213
                                    $array24 as xs:anyAtomicType*,
 
2214
                                    $array25 as xs:anyAtomicType*,
 
2215
                                    $array26 as xs:anyAtomicType*,
 
2216
                                    $array27 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
2217
 {
 
2218
    if( fn:empty($array1) or 
 
2219
        fn:empty($array2) or
 
2220
        fn:empty($array3) or
 
2221
        fn:empty($array4) or
 
2222
        fn:empty($array5) or
 
2223
        fn:empty($array6) or
 
2224
        fn:empty($array7) or
 
2225
        fn:empty($array8) or
 
2226
        fn:empty($array9) or
 
2227
        fn:empty($array10) or
 
2228
        fn:empty($array11) or
 
2229
        fn:empty($array12) or
 
2230
        fn:empty($array13) or
 
2231
        fn:empty($array14) or
 
2232
        fn:empty($array15) or
 
2233
        fn:empty($array16) or
 
2234
        fn:empty($array17) or
 
2235
        fn:empty($array18) or
 
2236
        fn:empty($array19) or
 
2237
        fn:empty($array20) or
 
2238
        fn:empty($array21) or
 
2239
        fn:empty($array22) or
 
2240
        fn:empty($array23) or
 
2241
        fn:empty($array24) or
 
2242
        fn:empty($array25) or
 
2243
        fn:empty($array26) or
 
2244
        fn:empty($array27)) 
 
2245
        then
 
2246
      0
 
2247
    else
 
2248
        excel-math:cast-as-numeric($array1[1]) * 
 
2249
        excel-math:cast-as-numeric($array2[1]) * 
 
2250
        excel-math:cast-as-numeric($array3[1]) * 
 
2251
        excel-math:cast-as-numeric($array4[1]) * 
 
2252
        excel-math:cast-as-numeric($array5[1]) * 
 
2253
        excel-math:cast-as-numeric($array6[1]) * 
 
2254
        excel-math:cast-as-numeric($array7[1]) * 
 
2255
        excel-math:cast-as-numeric($array8[1]) * 
 
2256
        excel-math:cast-as-numeric($array9[1]) * 
 
2257
        excel-math:cast-as-numeric($array10[1]) * 
 
2258
        excel-math:cast-as-numeric($array11[1]) * 
 
2259
        excel-math:cast-as-numeric($array12[1]) * 
 
2260
        excel-math:cast-as-numeric($array13[1]) * 
 
2261
        excel-math:cast-as-numeric($array14[1]) * 
 
2262
        excel-math:cast-as-numeric($array15[1]) * 
 
2263
        excel-math:cast-as-numeric($array16[1]) * 
 
2264
        excel-math:cast-as-numeric($array17[1]) * 
 
2265
        excel-math:cast-as-numeric($array18[1]) *
 
2266
        excel-math:cast-as-numeric($array19[1]) *
 
2267
        excel-math:cast-as-numeric($array20[1]) *
 
2268
        excel-math:cast-as-numeric($array21[1]) *
 
2269
        excel-math:cast-as-numeric($array22[1]) *
 
2270
        excel-math:cast-as-numeric($array23[1]) *
 
2271
        excel-math:cast-as-numeric($array24[1]) *
 
2272
        excel-math:cast-as-numeric($array25[1]) *
 
2273
        excel-math:cast-as-numeric($array26[1]) *
 
2274
        excel-math:cast-as-numeric($array27[1]) +
 
2275
                    excel:sumproduct(  fn:subsequence($array1,2),
 
2276
                                             fn:subsequence($array2,2),
 
2277
                                             fn:subsequence($array3,2),
 
2278
                                             fn:subsequence($array4,2),
 
2279
                                             fn:subsequence($array5,2),
 
2280
                                             fn:subsequence($array6,2),
 
2281
                                             fn:subsequence($array7,2),
 
2282
                                             fn:subsequence($array8,2),
 
2283
                                             fn:subsequence($array9,2),
 
2284
                                             fn:subsequence($array10,2),
 
2285
                                             fn:subsequence($array11,2),
 
2286
                                             fn:subsequence($array12,2),
 
2287
                                             fn:subsequence($array13,2),
 
2288
                                             fn:subsequence($array14,2),
 
2289
                                             fn:subsequence($array15,2),
 
2290
                                             fn:subsequence($array16,2),
 
2291
                                             fn:subsequence($array17,2),
 
2292
                                             fn:subsequence($array18,2),
 
2293
                                             fn:subsequence($array19,2),
 
2294
                                             fn:subsequence($array20,2),
 
2295
                                             fn:subsequence($array21,2),
 
2296
                                             fn:subsequence($array22,2),
 
2297
                                             fn:subsequence($array23,2),
 
2298
                                             fn:subsequence($array24,2),
 
2299
                                             fn:subsequence($array25,2),
 
2300
                                             fn:subsequence($array26,2),
 
2301
                                             fn:subsequence($array27,2))
 
2302
 };
 
2303
 
 
2304
 (:~
 
2305
  : Multiplies the elements on the same position in each sequence
 
2306
  : and sums up the results.
 
2307
  : 
 
2308
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
2309
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
2310
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
2311
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
2312
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
2313
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
2314
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
2315
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
2316
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
2317
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
2318
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
2319
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
2320
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
2321
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
2322
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
2323
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
2324
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
2325
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
2326
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
2327
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
2328
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
2329
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
2330
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
2331
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
2332
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
2333
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
2334
  : @param $array26 the sequences of numbers or arguments castable to numeric
 
2335
  : @param $array27 the sequences of numbers or arguments castable to numeric
 
2336
  : @param $array28 the sequences of numbers or arguments castable to numeric
 
2337
  : @return the sum of products
 
2338
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2339
:)
 
2340
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
2341
                                    $array2 as xs:anyAtomicType*,
 
2342
                                    $array3 as xs:anyAtomicType*,
 
2343
                                    $array4 as xs:anyAtomicType*,
 
2344
                                    $array5 as xs:anyAtomicType*,
 
2345
                                    $array6 as xs:anyAtomicType*,
 
2346
                                    $array7 as xs:anyAtomicType*,
 
2347
                                    $array8 as xs:anyAtomicType*,
 
2348
                                    $array9 as xs:anyAtomicType*,
 
2349
                                    $array10 as xs:anyAtomicType*,
 
2350
                                    $array11 as xs:anyAtomicType*,
 
2351
                                    $array12 as xs:anyAtomicType*,
 
2352
                                    $array13 as xs:anyAtomicType*,
 
2353
                                    $array14 as xs:anyAtomicType*,
 
2354
                                    $array15 as xs:anyAtomicType*,
 
2355
                                    $array16 as xs:anyAtomicType*,
 
2356
                                    $array17 as xs:anyAtomicType*,
 
2357
                                    $array18 as xs:anyAtomicType*,
 
2358
                                    $array19 as xs:anyAtomicType*,
 
2359
                                    $array20 as xs:anyAtomicType*,
 
2360
                                    $array21 as xs:anyAtomicType*,
 
2361
                                    $array22 as xs:anyAtomicType*,
 
2362
                                    $array23 as xs:anyAtomicType*,
 
2363
                                    $array24 as xs:anyAtomicType*,
 
2364
                                    $array25 as xs:anyAtomicType*,
 
2365
                                    $array26 as xs:anyAtomicType*,
 
2366
                                    $array27 as xs:anyAtomicType*,
 
2367
                                    $array28 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
2368
 {
 
2369
    if( fn:empty($array1) or 
 
2370
        fn:empty($array2) or
 
2371
        fn:empty($array3) or
 
2372
        fn:empty($array4) or
 
2373
        fn:empty($array5) or
 
2374
        fn:empty($array6) or
 
2375
        fn:empty($array7) or
 
2376
        fn:empty($array8) or
 
2377
        fn:empty($array9) or
 
2378
        fn:empty($array10) or
 
2379
        fn:empty($array11) or
 
2380
        fn:empty($array12) or
 
2381
        fn:empty($array13) or
 
2382
        fn:empty($array14) or
 
2383
        fn:empty($array15) or
 
2384
        fn:empty($array16) or
 
2385
        fn:empty($array17) or
 
2386
        fn:empty($array18) or
 
2387
        fn:empty($array19) or
 
2388
        fn:empty($array20) or
 
2389
        fn:empty($array21) or
 
2390
        fn:empty($array22) or
 
2391
        fn:empty($array23) or
 
2392
        fn:empty($array24) or
 
2393
        fn:empty($array25) or
 
2394
        fn:empty($array26) or
 
2395
        fn:empty($array27) or
 
2396
        fn:empty($array28)) 
 
2397
        then
 
2398
      0
 
2399
    else
 
2400
        excel-math:cast-as-numeric($array1[1]) * 
 
2401
        excel-math:cast-as-numeric($array2[1]) * 
 
2402
        excel-math:cast-as-numeric($array3[1]) * 
 
2403
        excel-math:cast-as-numeric($array4[1]) * 
 
2404
        excel-math:cast-as-numeric($array5[1]) * 
 
2405
        excel-math:cast-as-numeric($array6[1]) * 
 
2406
        excel-math:cast-as-numeric($array7[1]) * 
 
2407
        excel-math:cast-as-numeric($array8[1]) * 
 
2408
        excel-math:cast-as-numeric($array9[1]) * 
 
2409
        excel-math:cast-as-numeric($array10[1]) * 
 
2410
        excel-math:cast-as-numeric($array11[1]) * 
 
2411
        excel-math:cast-as-numeric($array12[1]) * 
 
2412
        excel-math:cast-as-numeric($array13[1]) * 
 
2413
        excel-math:cast-as-numeric($array14[1]) * 
 
2414
        excel-math:cast-as-numeric($array15[1]) * 
 
2415
        excel-math:cast-as-numeric($array16[1]) * 
 
2416
        excel-math:cast-as-numeric($array17[1]) * 
 
2417
        excel-math:cast-as-numeric($array18[1]) *
 
2418
        excel-math:cast-as-numeric($array19[1]) *
 
2419
        excel-math:cast-as-numeric($array20[1]) *
 
2420
        excel-math:cast-as-numeric($array21[1]) *
 
2421
        excel-math:cast-as-numeric($array22[1]) *
 
2422
        excel-math:cast-as-numeric($array23[1]) *
 
2423
        excel-math:cast-as-numeric($array24[1]) *
 
2424
        excel-math:cast-as-numeric($array25[1]) *
 
2425
        excel-math:cast-as-numeric($array26[1]) *
 
2426
        excel-math:cast-as-numeric($array27[1]) *
 
2427
        excel-math:cast-as-numeric($array28[1]) +
 
2428
                    excel:sumproduct(  fn:subsequence($array1,2),
 
2429
                                             fn:subsequence($array2,2),
 
2430
                                             fn:subsequence($array3,2),
 
2431
                                             fn:subsequence($array4,2),
 
2432
                                             fn:subsequence($array5,2),
 
2433
                                             fn:subsequence($array6,2),
 
2434
                                             fn:subsequence($array7,2),
 
2435
                                             fn:subsequence($array8,2),
 
2436
                                             fn:subsequence($array9,2),
 
2437
                                             fn:subsequence($array10,2),
 
2438
                                             fn:subsequence($array11,2),
 
2439
                                             fn:subsequence($array12,2),
 
2440
                                             fn:subsequence($array13,2),
 
2441
                                             fn:subsequence($array14,2),
 
2442
                                             fn:subsequence($array15,2),
 
2443
                                             fn:subsequence($array16,2),
 
2444
                                             fn:subsequence($array17,2),
 
2445
                                             fn:subsequence($array18,2),
 
2446
                                             fn:subsequence($array19,2),
 
2447
                                             fn:subsequence($array20,2),
 
2448
                                             fn:subsequence($array21,2),
 
2449
                                             fn:subsequence($array22,2),
 
2450
                                             fn:subsequence($array23,2),
 
2451
                                             fn:subsequence($array24,2),
 
2452
                                             fn:subsequence($array25,2),
 
2453
                                             fn:subsequence($array26,2),
 
2454
                                             fn:subsequence($array27,2),
 
2455
                                             fn:subsequence($array28,2))
 
2456
 };
 
2457
 
 
2458
 (:~
 
2459
  : Multiplies the elements on the same position in each sequence
 
2460
  : and sums up the results.
 
2461
  : 
 
2462
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
2463
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
2464
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
2465
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
2466
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
2467
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
2468
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
2469
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
2470
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
2471
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
2472
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
2473
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
2474
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
2475
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
2476
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
2477
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
2478
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
2479
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
2480
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
2481
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
2482
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
2483
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
2484
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
2485
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
2486
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
2487
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
2488
  : @param $array26 the sequences of numbers or arguments castable to numeric
 
2489
  : @param $array27 the sequences of numbers or arguments castable to numeric
 
2490
  : @param $array28 the sequences of numbers or arguments castable to numeric
 
2491
  : @param $array29 the sequences of numbers or arguments castable to numeric
 
2492
  : @return the sum of products
 
2493
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2494
:)
 
2495
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
2496
                                    $array2 as xs:anyAtomicType*,
 
2497
                                    $array3 as xs:anyAtomicType*,
 
2498
                                    $array4 as xs:anyAtomicType*,
 
2499
                                    $array5 as xs:anyAtomicType*,
 
2500
                                    $array6 as xs:anyAtomicType*,
 
2501
                                    $array7 as xs:anyAtomicType*,
 
2502
                                    $array8 as xs:anyAtomicType*,
 
2503
                                    $array9 as xs:anyAtomicType*,
 
2504
                                    $array10 as xs:anyAtomicType*,
 
2505
                                    $array11 as xs:anyAtomicType*,
 
2506
                                    $array12 as xs:anyAtomicType*,
 
2507
                                    $array13 as xs:anyAtomicType*,
 
2508
                                    $array14 as xs:anyAtomicType*,
 
2509
                                    $array15 as xs:anyAtomicType*,
 
2510
                                    $array16 as xs:anyAtomicType*,
 
2511
                                    $array17 as xs:anyAtomicType*,
 
2512
                                    $array18 as xs:anyAtomicType*,
 
2513
                                    $array19 as xs:anyAtomicType*,
 
2514
                                    $array20 as xs:anyAtomicType*,
 
2515
                                    $array21 as xs:anyAtomicType*,
 
2516
                                    $array22 as xs:anyAtomicType*,
 
2517
                                    $array23 as xs:anyAtomicType*,
 
2518
                                    $array24 as xs:anyAtomicType*,
 
2519
                                    $array25 as xs:anyAtomicType*,
 
2520
                                    $array26 as xs:anyAtomicType*,
 
2521
                                    $array27 as xs:anyAtomicType*,
 
2522
                                    $array28 as xs:anyAtomicType*,
 
2523
                                    $array29 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
2524
 {
 
2525
    if( fn:empty($array1) or 
 
2526
        fn:empty($array2) or
 
2527
        fn:empty($array3) or
 
2528
        fn:empty($array4) or
 
2529
        fn:empty($array5) or
 
2530
        fn:empty($array6) or
 
2531
        fn:empty($array7) or
 
2532
        fn:empty($array8) or
 
2533
        fn:empty($array9) or
 
2534
        fn:empty($array10) or
 
2535
        fn:empty($array11) or
 
2536
        fn:empty($array12) or
 
2537
        fn:empty($array13) or
 
2538
        fn:empty($array14) or
 
2539
        fn:empty($array15) or
 
2540
        fn:empty($array16) or
 
2541
        fn:empty($array17) or
 
2542
        fn:empty($array18) or
 
2543
        fn:empty($array19) or
 
2544
        fn:empty($array20) or
 
2545
        fn:empty($array21) or
 
2546
        fn:empty($array22) or
 
2547
        fn:empty($array23) or
 
2548
        fn:empty($array24) or
 
2549
        fn:empty($array25) or
 
2550
        fn:empty($array26) or
 
2551
        fn:empty($array27) or
 
2552
        fn:empty($array28) or
 
2553
        fn:empty($array29)) 
 
2554
        then
 
2555
      0
 
2556
    else
 
2557
        excel-math:cast-as-numeric($array1[1]) * 
 
2558
        excel-math:cast-as-numeric($array2[1]) * 
 
2559
        excel-math:cast-as-numeric($array3[1]) * 
 
2560
        excel-math:cast-as-numeric($array4[1]) * 
 
2561
        excel-math:cast-as-numeric($array5[1]) * 
 
2562
        excel-math:cast-as-numeric($array6[1]) * 
 
2563
        excel-math:cast-as-numeric($array7[1]) * 
 
2564
        excel-math:cast-as-numeric($array8[1]) * 
 
2565
        excel-math:cast-as-numeric($array9[1]) * 
 
2566
        excel-math:cast-as-numeric($array10[1]) * 
 
2567
        excel-math:cast-as-numeric($array11[1]) * 
 
2568
        excel-math:cast-as-numeric($array12[1]) * 
 
2569
        excel-math:cast-as-numeric($array13[1]) * 
 
2570
        excel-math:cast-as-numeric($array14[1]) * 
 
2571
        excel-math:cast-as-numeric($array15[1]) * 
 
2572
        excel-math:cast-as-numeric($array16[1]) * 
 
2573
        excel-math:cast-as-numeric($array17[1]) * 
 
2574
        excel-math:cast-as-numeric($array18[1]) *
 
2575
        excel-math:cast-as-numeric($array19[1]) *
 
2576
        excel-math:cast-as-numeric($array20[1]) *
 
2577
        excel-math:cast-as-numeric($array21[1]) *
 
2578
        excel-math:cast-as-numeric($array22[1]) *
 
2579
        excel-math:cast-as-numeric($array23[1]) *
 
2580
        excel-math:cast-as-numeric($array24[1]) *
 
2581
        excel-math:cast-as-numeric($array25[1]) *
 
2582
        excel-math:cast-as-numeric($array26[1]) *
 
2583
        excel-math:cast-as-numeric($array27[1]) *
 
2584
        excel-math:cast-as-numeric($array28[1]) *
 
2585
        excel-math:cast-as-numeric($array29[1]) +
 
2586
                    excel:sumproduct(  fn:subsequence($array1,2),
 
2587
                                             fn:subsequence($array2,2),
 
2588
                                             fn:subsequence($array3,2),
 
2589
                                             fn:subsequence($array4,2),
 
2590
                                             fn:subsequence($array5,2),
 
2591
                                             fn:subsequence($array6,2),
 
2592
                                             fn:subsequence($array7,2),
 
2593
                                             fn:subsequence($array8,2),
 
2594
                                             fn:subsequence($array9,2),
 
2595
                                             fn:subsequence($array10,2),
 
2596
                                             fn:subsequence($array11,2),
 
2597
                                             fn:subsequence($array12,2),
 
2598
                                             fn:subsequence($array13,2),
 
2599
                                             fn:subsequence($array14,2),
 
2600
                                             fn:subsequence($array15,2),
 
2601
                                             fn:subsequence($array16,2),
 
2602
                                             fn:subsequence($array17,2),
 
2603
                                             fn:subsequence($array18,2),
 
2604
                                             fn:subsequence($array19,2),
 
2605
                                             fn:subsequence($array20,2),
 
2606
                                             fn:subsequence($array21,2),
 
2607
                                             fn:subsequence($array22,2),
 
2608
                                             fn:subsequence($array23,2),
 
2609
                                             fn:subsequence($array24,2),
 
2610
                                             fn:subsequence($array25,2),
 
2611
                                             fn:subsequence($array26,2),
 
2612
                                             fn:subsequence($array27,2),
 
2613
                                             fn:subsequence($array28,2),
 
2614
                                             fn:subsequence($array29,2))
 
2615
 };
 
2616
 
 
2617
 (:~
 
2618
  : Multiplies the elements on the same position in each sequence
 
2619
  : and sums up the results.
 
2620
  : 
 
2621
  : @see http://office.microsoft.com/en-us/excel/HP052092931033.aspx
 
2622
  : @param $array1 the sequences of numbers or arguments castable to numeric
 
2623
  : @param $array2 the sequences of numbers or arguments castable to numeric
 
2624
  : @param $array3 the sequences of numbers or arguments castable to numeric
 
2625
  : @param $array4 the sequences of numbers or arguments castable to numeric
 
2626
  : @param $array5 the sequences of numbers or arguments castable to numeric
 
2627
  : @param $array6 the sequences of numbers or arguments castable to numeric
 
2628
  : @param $array7 the sequences of numbers or arguments castable to numeric
 
2629
  : @param $array8 the sequences of numbers or arguments castable to numeric
 
2630
  : @param $array9 the sequences of numbers or arguments castable to numeric
 
2631
  : @param $array10 the sequences of numbers or arguments castable to numeric
 
2632
  : @param $array11 the sequences of numbers or arguments castable to numeric
 
2633
  : @param $array12 the sequences of numbers or arguments castable to numeric
 
2634
  : @param $array13 the sequences of numbers or arguments castable to numeric
 
2635
  : @param $array14 the sequences of numbers or arguments castable to numeric
 
2636
  : @param $array15 the sequences of numbers or arguments castable to numeric
 
2637
  : @param $array16 the sequences of numbers or arguments castable to numeric
 
2638
  : @param $array17 the sequences of numbers or arguments castable to numeric
 
2639
  : @param $array18 the sequences of numbers or arguments castable to numeric
 
2640
  : @param $array19 the sequences of numbers or arguments castable to numeric
 
2641
  : @param $array20 the sequences of numbers or arguments castable to numeric
 
2642
  : @param $array21 the sequences of numbers or arguments castable to numeric
 
2643
  : @param $array22 the sequences of numbers or arguments castable to numeric
 
2644
  : @param $array23 the sequences of numbers or arguments castable to numeric
 
2645
  : @param $array24 the sequences of numbers or arguments castable to numeric
 
2646
  : @param $array25 the sequences of numbers or arguments castable to numeric
 
2647
  : @param $array26 the sequences of numbers or arguments castable to numeric
 
2648
  : @param $array27 the sequences of numbers or arguments castable to numeric
 
2649
  : @param $array28 the sequences of numbers or arguments castable to numeric
 
2650
  : @param $array29 the sequences of numbers or arguments castable to numeric
 
2651
  : @param $array30 the sequences of numbers or arguments castable to numeric
 
2652
  : @return the sum of products
 
2653
  : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2654
:)
 
2655
 declare function excel:sumproduct( $array1 as xs:anyAtomicType*,
 
2656
                                    $array2 as xs:anyAtomicType*,
 
2657
                                    $array3 as xs:anyAtomicType*,
 
2658
                                    $array4 as xs:anyAtomicType*,
 
2659
                                    $array5 as xs:anyAtomicType*,
 
2660
                                    $array6 as xs:anyAtomicType*,
 
2661
                                    $array7 as xs:anyAtomicType*,
 
2662
                                    $array8 as xs:anyAtomicType*,
 
2663
                                    $array9 as xs:anyAtomicType*,
 
2664
                                    $array10 as xs:anyAtomicType*,
 
2665
                                    $array11 as xs:anyAtomicType*,
 
2666
                                    $array12 as xs:anyAtomicType*,
 
2667
                                    $array13 as xs:anyAtomicType*,
 
2668
                                    $array14 as xs:anyAtomicType*,
 
2669
                                    $array15 as xs:anyAtomicType*,
 
2670
                                    $array16 as xs:anyAtomicType*,
 
2671
                                    $array17 as xs:anyAtomicType*,
 
2672
                                    $array18 as xs:anyAtomicType*,
 
2673
                                    $array19 as xs:anyAtomicType*,
 
2674
                                    $array20 as xs:anyAtomicType*,
 
2675
                                    $array21 as xs:anyAtomicType*,
 
2676
                                    $array22 as xs:anyAtomicType*,
 
2677
                                    $array23 as xs:anyAtomicType*,
 
2678
                                    $array24 as xs:anyAtomicType*,
 
2679
                                    $array25 as xs:anyAtomicType*,
 
2680
                                    $array26 as xs:anyAtomicType*,
 
2681
                                    $array27 as xs:anyAtomicType*,
 
2682
                                    $array28 as xs:anyAtomicType*,
 
2683
                                    $array29 as xs:anyAtomicType*,
 
2684
                                    $array30 as xs:anyAtomicType*  ) as xs:anyAtomicType
 
2685
 {
 
2686
    if( fn:empty($array1) or 
 
2687
        fn:empty($array2) or
 
2688
        fn:empty($array3) or
 
2689
        fn:empty($array4) or
 
2690
        fn:empty($array5) or
 
2691
        fn:empty($array6) or
 
2692
        fn:empty($array7) or
 
2693
        fn:empty($array8) or
 
2694
        fn:empty($array9) or
 
2695
        fn:empty($array10) or
 
2696
        fn:empty($array11) or
 
2697
        fn:empty($array12) or
 
2698
        fn:empty($array13) or
 
2699
        fn:empty($array14) or
 
2700
        fn:empty($array15) or
 
2701
        fn:empty($array16) or
 
2702
        fn:empty($array17) or
 
2703
        fn:empty($array18) or
 
2704
        fn:empty($array19) or
 
2705
        fn:empty($array20) or
 
2706
        fn:empty($array21) or
 
2707
        fn:empty($array22) or
 
2708
        fn:empty($array23) or
 
2709
        fn:empty($array24) or
 
2710
        fn:empty($array25) or
 
2711
        fn:empty($array26) or
 
2712
        fn:empty($array27) or
 
2713
        fn:empty($array28) or
 
2714
        fn:empty($array29) or
 
2715
        fn:empty($array30)) 
 
2716
        then
 
2717
      0
 
2718
    else
 
2719
        excel-math:cast-as-numeric($array1[1]) * 
 
2720
        excel-math:cast-as-numeric($array2[1]) * 
 
2721
        excel-math:cast-as-numeric($array3[1]) * 
 
2722
        excel-math:cast-as-numeric($array4[1]) * 
 
2723
        excel-math:cast-as-numeric($array5[1]) * 
 
2724
        excel-math:cast-as-numeric($array6[1]) * 
 
2725
        excel-math:cast-as-numeric($array7[1]) * 
 
2726
        excel-math:cast-as-numeric($array8[1]) * 
 
2727
        excel-math:cast-as-numeric($array9[1]) * 
 
2728
        excel-math:cast-as-numeric($array10[1]) * 
 
2729
        excel-math:cast-as-numeric($array11[1]) * 
 
2730
        excel-math:cast-as-numeric($array12[1]) * 
 
2731
        excel-math:cast-as-numeric($array13[1]) * 
 
2732
        excel-math:cast-as-numeric($array14[1]) * 
 
2733
        excel-math:cast-as-numeric($array15[1]) * 
 
2734
        excel-math:cast-as-numeric($array16[1]) * 
 
2735
        excel-math:cast-as-numeric($array17[1]) * 
 
2736
        excel-math:cast-as-numeric($array18[1]) *
 
2737
        excel-math:cast-as-numeric($array19[1]) *
 
2738
        excel-math:cast-as-numeric($array20[1]) *
 
2739
        excel-math:cast-as-numeric($array21[1]) *
 
2740
        excel-math:cast-as-numeric($array22[1]) *
 
2741
        excel-math:cast-as-numeric($array23[1]) *
 
2742
        excel-math:cast-as-numeric($array24[1]) *
 
2743
        excel-math:cast-as-numeric($array25[1]) *
 
2744
        excel-math:cast-as-numeric($array26[1]) *
 
2745
        excel-math:cast-as-numeric($array27[1]) *
 
2746
        excel-math:cast-as-numeric($array28[1]) *
 
2747
        excel-math:cast-as-numeric($array29[1]) *
 
2748
        excel-math:cast-as-numeric($array30[1]) +
 
2749
                    excel:sumproduct(  fn:subsequence($array1,2),
 
2750
                                             fn:subsequence($array2,2),
 
2751
                                             fn:subsequence($array3,2),
 
2752
                                             fn:subsequence($array4,2),
 
2753
                                             fn:subsequence($array5,2),
 
2754
                                             fn:subsequence($array6,2),
 
2755
                                             fn:subsequence($array7,2),
 
2756
                                             fn:subsequence($array8,2),
 
2757
                                             fn:subsequence($array9,2),
 
2758
                                             fn:subsequence($array10,2),
 
2759
                                             fn:subsequence($array11,2),
 
2760
                                             fn:subsequence($array12,2),
 
2761
                                             fn:subsequence($array13,2),
 
2762
                                             fn:subsequence($array14,2),
 
2763
                                             fn:subsequence($array15,2),
 
2764
                                             fn:subsequence($array16,2),
 
2765
                                             fn:subsequence($array17,2),
 
2766
                                             fn:subsequence($array18,2),
 
2767
                                             fn:subsequence($array19,2),
 
2768
                                             fn:subsequence($array20,2),
 
2769
                                             fn:subsequence($array21,2),
 
2770
                                             fn:subsequence($array22,2),
 
2771
                                             fn:subsequence($array23,2),
 
2772
                                             fn:subsequence($array24,2),
 
2773
                                             fn:subsequence($array25,2),
 
2774
                                             fn:subsequence($array26,2),
 
2775
                                             fn:subsequence($array27,2),
 
2776
                                             fn:subsequence($array28,2),
 
2777
                                             fn:subsequence($array29,2),
 
2778
                                             fn:subsequence($array30,2))
 
2779
 };
 
2780
 
 
2781
(:~
 
2782
 : Returns the sum of the squares of the arguments.
 
2783
 : It used the sumproduct function.
 
2784
 : 
 
2785
 : @see http://office.microsoft.com/en-us/excel/HP052092951033.aspx
 
2786
 : @param $numbers the sequence of one or more numbers or arguments castable to numeric
 
2787
 : @return the sum of squared values, as numeric type
 
2788
 : @error XQP0021(errValue) if the parameters cannot be casted to numeric type
 
2789
 : @example rbkt/Queries/zorba/excel/math/sumsq1.xq
 
2790
:)
 
2791
 declare function excel:sumsq( $numbers as xs:anyAtomicType+) as xs:anyAtomicType
 
2792
 {
 
2793
   excel:sumproduct($numbers, $numbers)
 
2794
 };
 
2795