Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

2017-02-15 Thread Geert Josten
Yes, nice detailed answer Florent. Consider posting this question and answer on 
SO to get extra credit.. ;-)

From: 
<general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>>
 on behalf of Erik Zander 
<erik.zan...@studentlitteratur.se<mailto:erik.zan...@studentlitteratur.se>>
Reply-To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Date: Wednesday, February 15, 2017 at 1:57 PM
To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

Hi Florent,

Thank you!

Using map:entry solved it and goes with my intentions.
Also thanks for the great explanation it’s obvious why map:map doesn’t work 
when its explained well.

Regards
Erik

Från: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [mailto:general-boun...@developer.marklogic.com] För Florent Georges
Skickat: den 15 februari 2017 12:18
Till: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Ämne: Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

Hi,
Short answer: what you want is to use map:entry() instead of
map:map().  The following returns true (that is, it stores a document
node as the value of the key "key" in the map):

let $doc := document {  }
let $map := map:entry('key', $doc)
return
   map:get($map, 'key') instance of document-node()

So what is the difference with the following, which stores an element
node instead?

let $doc := document {  }
let $map := map:map(
  
 
key
{ $doc }
 
  )
return
   map:get($map, 'key') instance of element()

The difference is that the above first copy the document node to an
XML tree.  A document node added to an element is just "ignored", its
children get copied directly, as per the XDM recommendation.  This XML
tree is used as an XML representation of a map, and "deserialized".
What is in the element map:value *IS* an element node at this point,
so ends up as such in the map.

This might be more clear if we get rid of all the map machinery:

let $doc  := document {  }
let $elem := { $doc }
return
   $elem/node() instance of element()

The value of $elem in this last code is the following (which makes
sense, right?, what else could it be?):


   


Regards,

--
Florent Georges
H2O Consulting
http://h2o.consulting/

On 15 February 2017 at 11:37, Erik Zander wrote:
Hi All,

I did iron out why I got errors, now I could use some help finding the best 
solution to it.

The error is that I have code like

……

let $evalParams := map:map(


document
{$doc}

)
let $resultDocument := xdmp:eval($transformCode, $evalParams)

where in the $transform code it checks for a document-node
declare variable $document as document-node() external;

To my understanding this has to do with the map:map structure.

But is there a good way of going around it. I could use xdmp:unqote but it 
feels a bit messy. I could also put into the database but doing document 
inserts and deletions just for that feels like a bit much overhead.

Any thoughts on this is greatly appreciated.

Regards
Erik

___
General mailing list
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general

___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

2017-02-15 Thread Erik Zander
Hi Florent,

Thank you!

Using map:entry solved it and goes with my intentions.
Also thanks for the great explanation it’s obvious why map:map doesn’t work 
when its explained well.

Regards
Erik

Från: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] För Florent Georges
Skickat: den 15 februari 2017 12:18
Till: MarkLogic Developer Discussion <general@developer.marklogic.com>
Ämne: Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

Hi,
Short answer: what you want is to use map:entry() instead of
map:map().  The following returns true (that is, it stores a document
node as the value of the key "key" in the map):

let $doc := document {  }
let $map := map:entry('key', $doc)
return
   map:get($map, 'key') instance of document-node()

So what is the difference with the following, which stores an element
node instead?

let $doc := document {  }
let $map := map:map(
  
 
key
{ $doc }
 
  )
return
   map:get($map, 'key') instance of element()

The difference is that the above first copy the document node to an
XML tree.  A document node added to an element is just "ignored", its
children get copied directly, as per the XDM recommendation.  This XML
tree is used as an XML representation of a map, and "deserialized".
What is in the element map:value *IS* an element node at this point,
so ends up as such in the map.

This might be more clear if we get rid of all the map machinery:

let $doc  := document {  }
let $elem := { $doc }
return
   $elem/node() instance of element()

The value of $elem in this last code is the following (which makes
sense, right?, what else could it be?):


   


Regards,

--
Florent Georges
H2O Consulting
http://h2o.consulting/

On 15 February 2017 at 11:37, Erik Zander wrote:
Hi All,

I did iron out why I got errors, now I could use some help finding the best 
solution to it.

The error is that I have code like

……

let $evalParams := map:map(


document
{$doc}

)
let $resultDocument := xdmp:eval($transformCode, $evalParams)

where in the $transform code it checks for a document-node
declare variable $document as document-node() external;

To my understanding this has to do with the map:map structure.

But is there a good way of going around it. I could use xdmp:unqote but it 
feels a bit messy. I could also put into the database but doing document 
inserts and deletions just for that feels like a bit much overhead.

Any thoughts on this is greatly appreciated.

Regards
Erik

___
General mailing list
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general

___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] passing a document-node into an eval/invoke

2017-02-15 Thread Florent Georges
Hi,

Short answer: what you want is to use map:entry() instead of
map:map().  The following returns true (that is, it stores a document
node as the value of the key "key" in the map):

let $doc := document {  }
let $map := map:entry('key', $doc)
return
   map:get($map, 'key') instance of document-node()

So what is the difference with the following, which stores an element
node instead?

let $doc := document {  }
let $map := map:map(
  
 
key
{ $doc }
 
  )
return
   map:get($map, 'key') instance of element()

The difference is that the above first copy the document node to an
XML tree.  A document node added to an element is just "ignored", its
children get copied directly, as per the XDM recommendation.  This XML
tree is used as an XML representation of a map, and "deserialized".
What is in the element map:value *IS* an element node at this point,
so ends up as such in the map.

This might be more clear if we get rid of all the map machinery:

let $doc  := document {  }
let $elem := { $doc }
return
   $elem/node() instance of element()

The value of $elem in this last code is the following (which makes
sense, right?, what else could it be?):


   


Regards,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/


On 15 February 2017 at 11:37, Erik Zander wrote:

> Hi All,
>
>
>
> I did iron out why I got errors, now I could use some help finding the
> best solution to it.
>
>
>
> The error is that I have code like
>
>
>
> ……
>
>
>
> let $evalParams := map:map(
>
> 
> xmlns:map='http://marklogic.com/xdmp/map'>
>
> 
>
> document
>
> {$doc}
>
> 
>
> )
>
> let $resultDocument := xdmp:eval($transformCode, $evalParams)
>
>
>
> where in the $transform code it checks for a document-node
>
> declare variable $document as document-node() external;
>
>
>
> To my understanding this has to do with the map:map structure.
>
>
>
> But is there a good way of going around it. I could use xdmp:unqote but it
> feels a bit messy. I could also put into the database but doing document
> inserts and deletions just for that feels like a bit much overhead.
>
>
>
> Any thoughts on this is greatly appreciated.
>
>
>
> Regards
>
> Erik
>
> ___
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general