The query calls two distinct functions. The code of this functions is very similar but not the same.
Here is the code:
declare function local:obtenerVivienda($id as xs:string) as element*
{
let $viviendas := for $doc in doc("../../documentos.xml")/documentos/documento,
$persona in doc($doc)//comparece[idPersonaFisica = $id]
//descripcion[atributo ="vive en"]
return $persona/valor
for $vivienda in distinct-values($viviendas)
return
<viveEn>
<atributo>vive en</atributo>
<valor>{$vivienda/text()}</valor>
</viveEn>
};
declare function local:obtenerVecinoDe($id as xs:string) as element*
{
let $vecindad := for $doc in doc("../../documentos.xml")/documentos/documento,
$persona in doc($doc)//comparece[idPersonaFisica = $id]
//descripcion[atributo ="vecino de"]
return $persona/valor
for $vecino in distinct-values($vecindad)
return
<vecinoDe>
<atributo>vecino de</atributo>
<valor>{$vecino}</valor>
</vecinoDe>
};
As you can see, both functions share almost the same code, but when I run the query, the first function doesn't crash but, after, an error message appears:
"Function obtenerVecinoDe doesn't match the function signature"
Do you know what is the possible cause of this error?
Subject:Re: Problem with a function Author:(Deleted User) Date:08 Jul 2004 07:02 AM
Hi Jose,
the error is in both the function signatures: they have been declared as
returning "element*", but the correct spelling is "element()*".
Without the "()", they specify that the return type is 0 or more instances
of a type named "element", instead of specifying that you expects 0 or more
element nodes.
Also, in the body of the first function you wrote
for $vivienda in distinct-values($viviendas)
return
<viveEn>
<atributo>vive en</atributo>
<valor>{$vivienda/text()}</valor>
</viveEn>
but distinct-values returns simple values, not nodes; so $vivienda/text()
will report an error. The correct expression is using just {$vivienda},
like you do in the body of the second function.