xpath - fn:sum error "cannot cast to xs:double" -


i'm trying add multiple nodes (names & amount of nodes uncertain).

performing query

for $x in //onboard/* return $x 

returns (and more)

<total>     <one/> </total> <total>   <one>124</one>   <two>1</two>   <three>0</three> </total> <total>   <one>46</one> </total> <total>   <one>129</one>   <two>1</two>   <three>0</three> </total> <seafarers>   <one>149</one>   <two>3</two>   <three>3</three>   <six>155</six> </seafarers> <soldiers>   <one>135</one>   <six>118</six> </soldiers> 

per child of name 'total' or 'seafarers' or similar not fixed return sum of values of nodes node 'one' node 'six' again, unsure how many nodes there , if of them exist (for each node @ least 1 number node exists, not have 'one').

so far have tried results in typecast errors or incorrect answers.

for sample code provided, desired answer be:

125 46 130 310 253 

you can try way :

for $x in //onboard/*[*] return sum($x/*) 

that reads : $x each child of <onboard> having @ least 1 child element, return sum of children element of $x.

update :

turned out problem due empty element(s) passed sum() function. possible way avoid error :

for $x in //onboard/*[normalize-space()] return sum($x/*[normalize-space()]) 

above xquery consider children of <onboard> non-empty element. in sum() operation, again non empty child of $x considered.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -