Please consider the following XML--
<div id="test">
<p> Text sihdfaif</p>
<p />
<p> Text sihdfaif</p>
<p />
<p> Text sihdfaif</p>
<p> Text sihdfaif</p>
<p> Text sihdfaif</p>
</div>
Now, I want to obtain the number of p elements that have some text within them.. in this case, that value=5 (there are 2 'p' elements which are empty)
This is the XQuery that I came up with--
let $claims_main := $doc//div[@id="test"]
let $claims := $doc//div[@id="test"]/p
let $n := count($claims)
where $claims_main/p != ''
return $n
However the result that I get from the above is7, i.e. including the empty 'p' elements.
An alternative that I thought of, is using a for loop over all of the 'p' elements, but in that case how do I retrieve the total number of elements of the loop? If I use count in that case, then I simply get [1,1,1,1,1]- ie. count of each p element (since in the for loop the count would be for each of the 'p' elements, and not the div itself)...