Re: [MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread David Lee
Yes you right, I copied off the wrong text block ... sorry

declare option xdmp:mapping "false";

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Ron Hitchens
Sent: Friday, September 26, 2014 12:13 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Passing empty value to function not working


Dave,

   I think that should be:

declare option xdmp:mapping "false";

   Rather than "update" to turn off function mapping.

   BTW: I'm one of those who think function mapping is awesome.  But yeah, if 
you're not careful it will trip you up big time.  Generally you're better off 
using the XQuery 3.0 mapping syntax these days if you're doing it intentionally.

---
Ron Hitchens {r...@overstory.co.uk<mailto:r...@overstory.co.uk>}  +44 7879 
358212

On Sep 26, 2014, at 1:08 PM, David Lee 
mailto:david@marklogic.com>> wrote:


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: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 
[mailto:general-boun...@developer.marklogic.com<mailto:boun...@developer.marklogic.com>]
 On Behalf Of Kapoor, Pragya
Sent: Friday, September 26, 2014 7:01 AM
To: general@developer.marklogic.com<mailto:general@developer.marklogic.com>
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)
 
  500
  server error
  
else

  517
  Session Id can't be empty
  

   };

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 := '


   '



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
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
http://developer.marklogic.com/mailman/listinfo/general

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread Ron Hitchens

Dave,

   I think that should be:

declare option xdmp:mapping "false";

   Rather than "update" to turn off function mapping.

   BTW: I'm one of those who think function mapping is awesome.  But yeah, if 
you're not careful it will trip you up big time.  Generally you're better off 
using the XQuery 3.0 mapping syntax these days if you're doing it intentionally.

---
Ron Hitchens {r...@overstory.co.uk}  +44 7879 358212

On Sep 26, 2014, at 1:08 PM, David Lee  wrote:

> 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: general-boun...@developer.marklogic.com 
> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Kapoor, Pragya
> Sent: Friday, September 26, 2014 7:01 AM
> To: general@developer.marklogic.com
> 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)
>  
>   500
>   server error
>   
> else
> 
>   517
>   Session Id can't be empty
>   
>  
>};
>  
> 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 := '
>
>   
>'
>  
>  
>  
> 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
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread Gary Vidal
You can always try using cardinality ?.  This will allow you to pass (0,1) 
arguments to function.  Of course you have check the value with 
fn:exists($sessionId) and handle case accordingly

xutils:validateSession($sessionId as xs:string?) {..}
-Original Message-
From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of 
general-requ...@developer.marklogic.com
Sent: Friday, September 26, 2014 8:08 AM
To: general@developer.marklogic.com
Subject: General Digest, Vol 123, Issue 50

Send General mailing list submissions to
general@developer.marklogic.com

To subscribe or unsubscribe via the World Wide Web, visit
http://developer.marklogic.com/mailman/listinfo/general
or, via email, send a message with subject or body 'help' to
general-requ...@developer.marklogic.com

You can reach the person managing the list at
general-ow...@developer.marklogic.com

When replying, please edit your Subject line so it is more specific than "Re: 
Contents of General digest..."


Today's Topics:

   1. Re: Passing empty value to function not   working (David Ennis)
   2. Re: Passing empty value to function not   working (David Lee)


--

Message: 1
Date: Fri, 26 Sep 2014 13:14:50 +0200
From: David Ennis 
Subject: Re: [MarkLogic Dev General] Passing empty value to function
not working
To: MarkLogic Developer Discussion 
Message-ID:

Content-Type: text/plain; charset="utf-8"

?Hi

MarkLogic allows for function overloading.  Perhaps that could be your 
solution..

Kind Regards,
David Ennis?



Kind Regards,
David Ennis


David Ennis
*Content Engineer*

[image: HintTech]  <http://www.hinttech.com/> Mastering the value of content 
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[image: http://www.hinttech.com] <http://www.hinttech.com> 
<https://twitter.com/HintTech>  <http://www.facebook.com/HintTech>
<http://www.linkedin.com/company/HintTech>

On 26 September 2014 13:00, Kapoor, Pragya  wrote:

>  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)
>  
>   500
>   server error
>   
>  else
> 
>   517
>   Session Id can't be empty
>   
>
> };
>
>  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 := '
>
> 
>'
>
>
>
>  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
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
---------- next part --
An HTML attachment was scrubbed...
URL: 
http://developer.marklogic.com/pipermail/general/attachments/20140926/2461825e/attachment-0001.html
 

--

Message: 2
Date: Fri, 26 Sep 2014 12:08:06 +
From: David Lee 
Subject: Re: [MarkLogic Dev General] Passing empty value to function
not working
To: MarkLogic Developer Discussion 
Message-ID:
<6ad72d76c2d6f04d8be471b70d4b991e04c9b...@exchg10-be02.marklogic.com>
Content-Type: text/plain; charset="utf-8"

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

Re: [MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread David Lee
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: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Kapoor, Pragya
Sent: Friday, September 26, 2014 7:01 AM
To: general@developer.marklogic.com
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)
 
  500
  server error
  
else

  517
  Session Id can't be empty
  

   };

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 := '


   '



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
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread David Ennis
​Hi

MarkLogic allows for function overloading.  Perhaps that could be your
solution..

Kind Regards,
David Ennis​



Kind Regards,
David Ennis


David Ennis
*Content Engineer*

[image: HintTech]  
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[image: http://www.hinttech.com] 
  


On 26 September 2014 13:00, Kapoor, Pragya  wrote:

>  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)
>  
>   500
>   server error
>   
>  else
> 
>   517
>   Session Id can't be empty
>   
>
> };
>
>  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 := '
>
> 
>'
>
>
>
>  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
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] Passing empty value to function not working

2014-09-26 Thread Kapoor, Pragya
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)
 
  500
  server error
  
else

  517
  Session Id can't be empty
  

   };

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 := '


   '



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
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general