XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Jose Alberto CoronadoSubject: Problem with a function
Author: Jose Alberto Coronado
Date: 08 Jul 2004 03:45 AM
Hello, I need help. I have a problem with a Xquery:

<residenciaDomicilio>
{local:obtenerVivienda($idPersonaFisica)}
{local:obtenerVecinoDe($idPersonaFisica)}
</residenciaDomicilio>


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?

Thanks.

Postnext
Alberto MassariSubject: Re: Problem with a function
Author: Alberto Massari
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.

Alberto


Posttop
Jose Alberto CoronadoSubject: Re: Problem with a function
Author: Jose Alberto Coronado
Date: 08 Jul 2004 07:38 AM
Thank you Alberto, I have tried it and the functions already work.
You have help me very much.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.