Hi, Sini:

If multiple nodes are correct, you can add an asterisk to the return type
in the function signature:

declare function local:insert-element($data) as node()* { ... };


Erik Hennum

________________________________________
From: [email protected] 
[[email protected]] On Behalf Of sini narayanan 
[[email protected]]
Sent: Thursday, November 22, 2012 1:30 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Invalid coercion

Hi David,

Thanks for pointing that. So how do I return multiple nodes?

Thanks


On Thu, Nov 22, 2012 at 8:47 PM, David Lee 
<[email protected]<mailto:[email protected]>> wrote:
Your function is returning multiple nodes and it is declared as only returning 
one.


-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Phone: +1 812-482-5223<tel:%2B1%20812-482-5223>
Cell:  +1 812-630-7622<tel:%2B1%20812-630-7622>
www.marklogic.com<http://www.marklogic.com/>


From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of sini narayanan
Sent: Thursday, November 22, 2012 12:42 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Invalid coercion

Hi,

I'm getting the following error:
[1.0-ml] XDMP-AS: (err:XPTY0004) local:insert-element($data) -- Invalid 
coercion: (<equipment equipmentLabel="Garden" equipmentID="PARC"/>, <equipment 
equipmentLabel="AirConditioned Room" equipmentID="CLIM_CHB"/>, <equipment 
equipmentLabel="Conference Room" equipmentID="SALLE_REUN_CONFR"/>, ...) as 
node()
I have created a function which return a node as below

declare function local:insert-element($data) as node() {

    let $EquipmentMap   := fn:doc("/GA/equipmentMap.xml")
    for $content in $EquipmentMap//map:entry
    let $keys := $content/@key
    let $label := $content/map:value/text()
    where $data/etData/etField//fieldValue[@fieldCode eq $keys]
     return
        <equipment equipmentLabel="{$label}" equipmentID="{$keys}"/>
};

The method is called inside the doc insert command:

let $create-od := xdmp:document-insert($doc-name-od,
        <datasheet datasheetType="objectiveData">
        <equipments>{local:insert-element($data)}</equipments>
        </datasheet>,
        xdmp:default-permissions(),
        xdmp:default-collections(), 10)

And by $data is fn:doc("/xmlName.xml")/test


Is there something wrong 'm doing. Please help.

Thanks

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general


_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to