Hi Sini,
If the node isn't in the database, you can't use the xdmp:node-* functions, you
have to instead re-build the node in memory; this is fairly easy to do if you
know the structure of the node, less so if you are trying to be more generic:
e.g. assuming your $node and $constraint, and you know what the structure looks
like:
let $new-node := element search:query {
element search:and-query {
element search:collection-constraint-query {
$node/search:and-query/search:collection-constraint-query/*,
$constraint
}
}
}
i.e. re-build the node structure, copying anything relevant, and inserting the
new content. You can write this more generically, using fn:node-name() to copy
unknown parent nodes, but you'd still need to know the structure. It is,
however, fast.
A more generic, expressive way of doing this is to use the in-mem-update
library that ships with ML:
import module namespace mem = "http://xqdev.com/in-mem-update" at
"/MarkLogic/appservices/utils/in-mem-update.xqy";
...
let $new-node := mem:node-insert-child($node//collection-constraint-query,
$constraint)
This then looks very much like the xdmp:node-insert-child() version, except
that the function returns the new node.
Beware that this can hide quite a lot of complexity under the surface (have a
look at the code!), and if your parent node doesn't exist, the return value
will be the empty-sequence, so check for this in situations where you can't be
sure!
Ellis.
On 21 Jun 2013, at 09:25, sini narayanan <[email protected]> wrote:
> Hi All,
>
> How do I perform a node-child-insert to a node? The node value is below.
> I need to do this without inserting this node into the database.
>
> let $node := <query xmlns="http://marklogic.com/appservices/search">
> <and-query>
> <collection-constraint-query>
> <constraint-name>type</constraint-name>
> <uri>xml</uri>
> </collection-constraint-query>
> </and-query>
> </query>
>
> let $constraint := <range-constraint-query>
> <constraint-name>country</constraint-name>
> <value>FRA</value>
> </range-constraint-query>
> return
> xdmp:node-insert-child($node//collection-constraint-query, $constraint)
>
> Thanks,
> Sini
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general