Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xPath - sum(//*) explained

Tags:

xml

xpath

Lets say we have the following XML structure:

<a><b>2<d>4</d></b><c>3</c></a> 

Why does sum(//*) return 274?

like image 769
Onion Avatar asked Oct 02 '22 06:10

Onion


1 Answers

Because it's 243 + 24 + 3 + 4 = 274

//* means all elements, which are a, b, c, and d. Then, we summarize their text values, which include everything except tags.

I think, what you're looking for is sum(//*/text()), which is 9 in this case

like image 193
yegor256 Avatar answered Oct 13 '22 12:10

yegor256