Calculating the balance of xpub
Regular nodes, by default, only maintain a balance tally for addresses in its own wallet. Your options are to either add every address to the wallet as a watch-only address, or to build your own index on top of the node by scanning each block and extracting the data from it.

There are patched versions of nodes available, such as the ones backing insight explorers, that also maintain an address index to speed explorer operations up. However, these versions are rarely up to date.