Project

Profile

Help

-TP option use works with XQuery and Saxon 10.1 HE but gi... ยป matrix-addition-1.xq

Martin Honnen, 2020-07-13 14:45

 
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method 'xml';
declare option output:indent 'yes';

declare variable $number-of-rows as xs:integer external := 10;
declare variable $number-of-cols as xs:integer external := 20;

declare variable $col-value as xs:decimal external := 1;

declare function local:make-rows() {
(1 to $number-of-rows)
!
<row>
{
(1 to $number-of-cols)
!
<col>{$col-value}</col>
}
</row>
};

declare variable $m1 as element(Matrix) external :=
<Matrix
id="m1">
{local:make-rows()}
</Matrix>
;

declare variable $m2 as element(Matrix) external :=
<Matrix
id="m2">
{local:make-rows()}
</Matrix>
;

declare function local:matrix-addition($M as element(Matrix), $N as element(Matrix)) as element(Matrix) {
<Matrix>
{
for-each-pair(
$M/row,
$N/row,
function ($row1, $row2) {
<row>
{
for-each-pair(
$row1/col,
$row2/col,
function ($col1, $col2) {
<col>{$col1 + $col2}</col>
}
)
}
</row>
}
)
}
</Matrix>

};


local:matrix-addition($m1, $m2)
    (1-1/1)