Question

I am trying to return either "Empty" if it is a empty sequence or "NotEmpty" if it is not. Let's say,

for $family in doc("gedcom.xml") /*/FamilyRec
where $family/Child/Link[@Ref = "IN006"]
return if(empty(data($family))) then "Empty" else "NotEmpty"

i am getting result in oxygen: NotEmpty which is Ok.

but let's say, there is no value for IN005

for $family in doc("gedcom.xml") /*/FamilyRec
where $family/Child/Link[@Ref = "IN005"]
return if(empty(data($family))) then "Empty" else "NotEmpty"

then it should print: Empty

but instead of printing "Empty" I am getting

Engine name: Saxon-EE XQuery 9.3.0.5 Severity: warning Description: Your query returned an empty sequence.

Can anyone please help me. Thanks in Advance.

Était-ce utile?

La solution

If I understand the issue correctly, I think the problem is that your where clause will filter out the value that you're looking for: if "IN005" doesn't exist then it will never get to the return clause.

instead you should not have a where clause and do the check in the return:

for $family in doc("gedcom.xml") /*/FamilyRec
return if($family/Child/Link[@Ref = "IN005"]) then "NotEmpty" else "Empty"

Autres conseils

I am trying to return either "Empty" if it is a empty sequence or "NotEmpty" if it is not.

What is "it"?

I'm having trouble working out exactly what your requirements are, but it sounds to me something like:

let $result :=
   for ...
   where ...
   return ...
return (if empty($result) then "Empty" else "Not Empty")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top