1

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

1
  • Post sample XML containing comments you do and do not want selected, and specify clearly a criteria that distinguishes ones you want from ones you do not want. Without such details, your question is unanswerable beyond saying that count(//comment[@gender="female"]) will return the number of comment elements with @gender attribute values equal to "female". Commented Apr 15, 2018 at 22:05

1 Answer 1

2

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.