Reputation: 25
I am using XQuery to count occurrences of related comments, on a thread on Social Media. However, I only want to count these occurrences, if the comments are made by females. (This is for a gender related research project at Uni.
So far I have got XQuery to count all the occurrences of the comments made by females by using this:
for $t in doc ("women.xml")
let $a:=$t//comment/@gender="female"
return count ($a)
However I need some help working out how I would adapt this to account the occurrences of appearance specific comments said by females.
Thank you for your help
Upvotes: 1
Views: 586
Reputation: 163262
First, note that
let $a:=$t//comment/@gender="female" return count ($a)
always returns 1. That's because the result of "=" is a boolean, and a boolean value is a sequence of length 1. What you intended is
let $a:=$t//comment[@gender="female"] return count ($a)
or more simply
count($t//comment[@gender="female"])
Now, if you only want to define "appearance-specific" comments, you can do
count($t//comment[@gender="female"][local:is-appearance-specific(.)])
and then you need to define a function
declare function local:is-appearance-specific(
$c as element(comment)) as xs:boolean {
....
};
which returns true if the comment is considered "appearance-specific".
Upvotes: 2