Do you have a sample of a document or two that you are querying against? When I try your example with a literal document, it appears to work correctly:
let $bk :=<doc> <book><title>junk</title><authors><author>anonymous</author><author>doyle</author></authors></book>
<book><title>trash</title><authors><author>milton</author><author>doyle</author></authors></book></doc>
for $b in $bk/book
where $b/authors/author = "doyle"
return $b/authors/author
So I assume my example does not represent your problem correctly!
Something to check: sometimes multiplicity confuses the issue. See if this approach helps:
let $bk :=<doc> <book><title>junk</title><authors><author>anonymous</author><author>doyle</author></authors></book>
<book><title>trash</title><authors><author>deranged</author><author>doyle</author></authors></book></doc>
for $b in $bk/book/authors
where $b/author = "doyle"
return $b/../title
The real Xquery is this. The previous was very simplified version:
for $a in input()/Protocolo[Paciente/ID_Paciente/NASI=‘123456’]
for $b in input()/TipoProtocolo[idTipoProtocolo/id = $a/refTipoProtocolo/id ]
for $CIAP in $b/tipo/AsociadoProblema/CIAPs/CIAP
where $CIAP = “A20”
return {$CIAP}
Without the line "where $CIAP = “A20"”, it returns:
for $a in input()/Protocolo[Paciente/ID_Paciente/NASI='123456']
for $b in input()/TipoProtocolo[idTipoProtocolo/id = $a/refTipoProtocolo/id ]
for $CIAP in $b/tipo/AsociadoProblema/CIAPs/CIAP
where starts-with($CIAP, "A20")
return <result>{$CIAP}</result>
if that works, you probably have some non-printable characters in the CIAP string (such as line feed or carriage return)
Hi “Flush”
I noticed that in your initial question you had this example:
Anonymous
Arthur Conan Doyle
And I can easily explain why a search for “Anonymous” doesn’t give any hit…
A search for " Anonymous" with an initial space would probably yield a better result
Perhaps you should use the tf:containsText function instead ?