Almost certainly this is due to "xdmp:mapping" being on https://docs.marklogic.com/guide/xquery/enhanced#id_55459 https://docs.marklogic.com/guide/xquery/langoverview#id_45023
For some this is an incredible feature. For others its surprising and difficult to debug . Its ON by default. In short, what it does is call functions that have an argument that can take exactly 1 of something N times depending on the argument you pass so you don’t have to write for loops. A side effect is that if N is 0 then the function is never called. I recommend that until you understand and decide for yourself if this is incredibly useful or too confusing to disable it. Add this line right under the version line in your XQuery files declare option xdmp:update "false"; However, you do have another issue ... you have declared your function to take exactly 1 argument ... So when you turn this off, instead of not calling your function you will get an error. You need to either change your function signature to allow the parameter to be empty, or pass in a zero length string. It looks like your function is expecting "" instead of () -- which means that your XPath is finding no text nodes let $sessionId := $node//sessionId/text() This use of text() is generally discouraged. Unless you absolutely positively know you need to use text(), don’t. Just don’t do it. Instead use string() let $sessionId := fn:string($node//sessionId) ( you can scan the archives of the various XQuery forums for a decade long debate on this if your curious) Now this will give you an error if there is > 1 node with a seesionID element ... but your code is not setup to handle N nodes so that’s probably for the best. From: [email protected] [mailto:[email protected]] On Behalf Of Kapoor, Pragya Sent: Friday, September 26, 2014 7:01 AM To: [email protected] Subject: [MarkLogic Dev General] Passing empty value to function not working Hi, I need to pass an empty value to util function, which is not working. declare function xutils:validateSession($sessionId as xs:string) { if($sessionId ne "" ) then let $document := fn:doc($config:USER_SESSIONS) <errorCode> <code>500</code> <description>server error</description> </errorCode> else <errorCode> <code>517</code> <description>Session Id can't be empty</description> </errorCode> }; I am calling this function from some other file and it is returing an empty sequence.But if I make this function local:validateSession($sessionId as xs:string) then its working. Calling file: import module namespace config = "config" at "/rest-apis/utils/config.xqy"; let $node := '<inputString> <sessionId></sessionId> </inputString>' let $node := xdmp:unquote($node) let $sessionId := $node//sessionId/text() return let $validateFlag := xutils:validateSession($sessionId) return $validateFlag Please advice. Thanks Pragya "This e-mail and any attachments transmitted with it are for the sole use of the intended recipient(s) and may contain confidential , proprietary or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this e-mail or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful."
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
