I have this XPath expression, which sum all nodes in the deepest XML hierarchy, without using nodes names:
select @data.value('sum(//*[not(*)])', 'float')
How do I make an exception of one node, by its name?
Say this is the xml:
<c>
<b1>
<a>1</a>
<d>4</d>
<g>5</g>
</b1>
<b1>
<a>7</a>
<d>1</d>
<g>2</g>
</b1>
</c>
I would like the sum to contain "d" and "g", without "a", but "a" will be pass as parameter and so need to be represented as parameter inside the expression. I've tried the following:
declare @except varchar(max) = 'a'
select @data.value('sum(//*[not(*)])', 'float') - @data.value('sum(//*:local-name()=sql:variable("@except"))', 'float')
but no success.