Problem comparing Strings with nodes.

Hi

I hava a simple XQuery that doesnt works , and I don’t understand.

This Xquery Works:

for $b in input()/Book
where $b/Authors/Author
return $b/Authors/Author

this returns:
Anonymous
Arthur Conan Doyle

But now, I want get only the Anonymouse Books.

for $b in input()/Book
where $b/Authors/Author = ‘Anonymous’
return $b/Authors/Author

This xquery returns nothing.

for $b in input()/Book
where $b/Authors/Author/text() = ‘Anonymous’
return $b/Authors/Author

This query returns nothing too.

Why not works?

Thanks, and forgive my very bad english.

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
<xq:result>
<author>anonymous</author>
<author>doyle</author>
<author>deranged</author>
<author>doyle</author>
</xq:result>

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:

<?xml version="1.0" encoding="utf-8"?> A20 A21 A52

But with where sentence, it returns nothing. Why?

This is the XSD stored in Tamino for TipoProtocolo

<xs:element name = “TipoProtocolo”>
xs:complexType
xs:sequence
<xs:element name = “idTipoProtocolo” type = “idSimpleType”></xs:element>
<xs:element ref = “nombre”></xs:element>
<xs:element ref = “descripcion”></xs:element>
<xs:element name = “actividades”>
xs:complexType
xs:sequence
<xs:element ref = “idTipoActividad” minOccurs = “0” maxOccurs = “unbounded”></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = “condiciones”>
xs:complexType
xs:sequence
<xs:element ref = “Condicion” minOccurs = “0” maxOccurs = “unbounded”></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = “tipo”>
xs:complexType
xs:choice
<xs:element name = “Horizontal” type = “xs:string”></xs:element>
<xs:element name = “AsociadoProblema”>
xs:complexType
xs:all
<xs:element name = “CIAPs”>
xs:complexType
xs:sequence
<xs:element name = “CIAP” type = “xs:string” maxOccurs = “unbounded”></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name = “Plantilla”>
xs:complexType
xs:all
<xs:element name = “CIAPs”>
xs:complexType
xs:sequence
<xs:element name = “CIAP” type = “xs:string” maxOccurs = “unbounded”></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = “CDUInforme” type = “xs:string”></xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

It’s like I can’t compare String with CIAP, despite of CIAP is a string.

A lot of thanks for the Help.

try this:


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 :wink:

Perhaps you should use the tf:containsText function instead ?

Finn

Thanks, The problem was non-printable character.